|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +**phpstan/extension-installer** is a Composer plugin that automatically registers PHPStan extensions. Without it, users must manually add `includes` entries in their `phpstan.neon` for every installed PHPStan extension. This plugin detects installed extensions and generates a configuration file so PHPStan picks them up automatically. |
| 6 | + |
| 7 | +The package is published as `phpstan/extension-installer` on Packagist with the Composer type `composer-plugin`. |
| 8 | + |
| 9 | +## How It Works |
| 10 | + |
| 11 | +1. The plugin (`src/Plugin.php`) subscribes to Composer's `post-install-cmd` and `post-update-cmd` script events. |
| 12 | +2. On each event, it scans all installed packages for PHPStan extensions (packages with type `phpstan-extension` or an `extra.phpstan` key in their `composer.json`). |
| 13 | +3. It generates `src/GeneratedConfig.php` containing a constant with all discovered extensions, their install paths, and included neon files. |
| 14 | +4. PHPStan reads `GeneratedConfig.php` at runtime to load the extensions automatically. |
| 15 | +5. A stub `GeneratedConfig.php` is committed to the repo as a fallback for when Composer runs with `--no-scripts`. |
| 16 | + |
| 17 | +Users can ignore specific extensions via `extra.phpstan/extension-installer.ignore` in their project's `composer.json`. |
| 18 | + |
| 19 | +## Repository Structure |
| 20 | + |
| 21 | +``` |
| 22 | +src/ |
| 23 | + Plugin.php - The Composer plugin (event subscriber, extension discovery, config generation) |
| 24 | + GeneratedConfig.php - Stub file (overwritten at install time with discovered extensions) |
| 25 | +e2e/ |
| 26 | + integration/ - E2E test: installs phpstan-phpunit extension, runs PHPStan analysis |
| 27 | + ignore/ - E2E test: verifies the ignore functionality works correctly |
| 28 | + test-extension/ - Minimal test extension used by the ignore e2e test |
| 29 | +.github/workflows/ |
| 30 | + build.yml - Lint, coding standard, and PHPStan static analysis |
| 31 | + integration-tests.yml - E2E integration and ignore tests across PHP/Composer versions |
| 32 | +``` |
| 33 | + |
| 34 | +## PHP Version Support |
| 35 | + |
| 36 | +This repository supports **PHP 7.4+** (see `composer.json`: `"php": "^7.4 || ^8.0"`). Do not use language features unavailable in PHP 7.4. |
| 37 | + |
| 38 | +## Dependencies |
| 39 | + |
| 40 | +- `composer-plugin-api: ^2.0` - Composer 2.x plugin API |
| 41 | +- `phpstan/phpstan: ^2.0` - PHPStan (dev dependency for self-analysis; the plugin itself works with extensions requiring PHPStan ^1 or ^2) |
| 42 | + |
| 43 | +Dev dependencies: |
| 44 | +- `composer/composer: ^2.0` - For type information |
| 45 | +- `php-parallel-lint/php-parallel-lint: ^1.2.0` - Syntax linting |
| 46 | +- `phpstan/phpstan-strict-rules: ^2.0` - Strict PHPStan rules for self-analysis |
| 47 | + |
| 48 | +## Development Commands |
| 49 | + |
| 50 | +All commands are defined in the `Makefile`: |
| 51 | + |
| 52 | +```bash |
| 53 | +make check # Run all checks (lint + cs + phpstan) |
| 54 | +make lint # Run php-parallel-lint on src/ |
| 55 | +make cs # Run PHP_CodeSniffer (requires build-cs to be set up) |
| 56 | +make cs-install # Clone and install phpstan/build-cs coding standard |
| 57 | +make cs-fix # Auto-fix coding standard violations |
| 58 | +make phpstan # Run PHPStan static analysis (level 8) |
| 59 | +``` |
| 60 | + |
| 61 | +### Coding Standard |
| 62 | + |
| 63 | +This project uses [phpstan/build-cs](https://github.com/phpstan/build-cs) (branch `2.x`) for coding standards via PHP_CodeSniffer. The `phpcs.xml` configures `php_version` as `70400` (PHP 7.4). To set it up locally: |
| 64 | + |
| 65 | +```bash |
| 66 | +make cs-install |
| 67 | +make cs |
| 68 | +``` |
| 69 | + |
| 70 | +### Static Analysis |
| 71 | + |
| 72 | +PHPStan runs at **level 8** on the `src/` directory with `phpstan-strict-rules` included. Configuration is in `phpstan.neon`. |
| 73 | + |
| 74 | +## CI Pipeline |
| 75 | + |
| 76 | +### Build (`build.yml`) |
| 77 | + |
| 78 | +- **Lint**: Runs `php-parallel-lint` across PHP 7.4, 8.0, 8.1, 8.2, 8.3, 8.4 |
| 79 | +- **Coding Standard**: Runs PHP_CodeSniffer on PHP 8.2 |
| 80 | +- **PHPStan**: Runs static analysis across PHP 7.4-8.4 with both lowest and highest dependency versions |
| 81 | + |
| 82 | +### Integration Tests (`integration-tests.yml`) |
| 83 | + |
| 84 | +- **Integration test**: Installs `phpstan-phpunit` via the extension installer, runs PHPStan analysis on a test file, then verifies it works after renaming the directory (testing relative path handling) |
| 85 | +- **Ignore test**: Verifies the ignore configuration correctly excludes specified extensions |
| 86 | +- Both tests run across PHP 7.4-8.5 and multiple Composer versions (v2, preview, snapshot, 2.1.0) |
| 87 | +- Uses `COMPOSER_ROOT_VERSION: "1.4.x-dev"` environment variable |
| 88 | + |
| 89 | +## Branch |
| 90 | + |
| 91 | +The main development branch is `1.4.x`. |
| 92 | + |
| 93 | +## Making Changes |
| 94 | + |
| 95 | +- Keep `src/GeneratedConfig.php` as a stub - it gets overwritten at install time by `Plugin.php`. |
| 96 | +- Any changes to the plugin logic are in `src/Plugin.php`. |
| 97 | +- E2E tests in `e2e/` validate the plugin works end-to-end with real Composer installs. |
| 98 | +- Run `make check` before submitting changes to verify lint, coding standard, and static analysis all pass. |
0 commit comments