Repository navigation
Inline code quality pack, replace Psalm with PHPStan, add tests - #3
Conversation
Replace the setono/code-quality-pack meta-package with its constituent packages directly in require-dev (matching the newest v3 pack, kept on PHP >=8.1 via phpunit ^10.5), and switch static analysis from Psalm to PHPStan at level max. - Drop psalm.xml, composer-require-checker.json and rector.php; add phpstan.dist.neon and composer-dependency-analyser.php (the latter replacing composer-require-checker + composer-unused). - Update composer scripts, ecs.php, phpunit.xml.dist (PHPUnit 10 schema), .gitattributes and the build workflow (PHP 8.1-8.4 matrix). - Refactor Metadata to track expiry in a dedicated array<string, int> property so the types are precise under PHPStan level max; behaviour is preserved (the __expires key now serialises last, which is not part of the reconstruction contract). - Make implicit-nullable params explicit for PHP 8.4. - Load the StaticClock time() shadow via the files autoloader so it is defined before any src/ time() call site binds, and add tests covering reconstruction, lazy expiry, pruning and malformed expiry data.
| - name: "Check style" | ||
| run: "composer check-style" | ||
|
|
||
| - name: "Check code style according to PHP version" |
There was a problem hiding this comment.
Good catch — restored in 8aae842.
My reasoning for originally removing it: the old rector.php used Rector\Set\ValueObject\LevelSetList (UP_TO_PHP_81), which Rector 2.0 removed. Since this PR inlines rector/rector: ^2.4, the old config would have failed to load, so the dry-run step would have errored. The newest sibling repo (meta-conversions-api-php-sdk) also keeps rector/rector in require-dev but has no rector config/script/CI step, so I followed that and dropped it.
That was an overreach — it removed a working check that wasn't in scope. I've now ported the config to the Rector 2.x fluent API instead:
return RectorConfig::configure()
->withCache('./.build/rector', FileCacheStorage::class)
->withPaths([__DIR__ . '/src', __DIR__ . '/tests'])
->withPhpSets(php81: true);->withPhpSets(php81: true) is the exact equivalent of the old UP_TO_PHP_81. The composer rector script and the "Check code style according to PHP version" CI step are back, and vendor/bin/rector --dry-run passes clean on the current tree.
The previous rector.php used Rector\Set\ValueObject\LevelSetList which was removed in Rector 2.0, so it would have broken under the inlined rector/rector ^2.4. Rather than drop the check, port the config to the fluent RectorConfig::configure() API (->withPhpSets(php81: true) keeps the old UP_TO_PHP_81 target) and re-add the composer script and CI step.
Summary
Three related maintenance changes:
setono/code-quality-packis replaced by its constituent packages directly inrequire-dev, matching the v3 pack's set as adapted to keep PHP ≥ 8.1 (phpunit ^10.5rather than the pack's^11.5).shipmonk/composer-dependency-analyserreplacescomposer-require-checker+composer-unused.level: max.composer analysenow runs PHPStan;psalm.xml,composer-require-checker.jsonandrector.phpare removed andphpstan.dist.neon+composer-dependency-analyser.phpadded. The CI matrix is expanded to PHP 8.1–8.4.has()/get(),has()/toArray()pruning, the expiry boundary, the__expirescontainer cleanup, and malformed-expiry handling.Notable details
Metadatarefactor: the Psalm-stylearray{__expires?: ..., ...<string, mixed>}shape is self-contradictory under PHPStan, so expiry tracking moved into its ownarray<string, int> $expiresproperty. Behaviour is preserved — the only observable change is that__expiresnow serialises last instead of at insertion position, which is not part of the BC contract (reconstruction is key-based).tests/StaticClock.phpis now loaded via thefilesautoloader instead ofsetUp(). PHP caches each unqualifiedtime()call site's binding on first execution, so the shadow must exist before anysrc/time()runs.Verification
All green locally:
composer validate --strict,composer normalize, ECS, PHPStan (level max),composer-dependency-analyser, PHPUnit (35 tests / 75 assertions), and Infection (95% MSI / 95% covered MSI). The only escaped mutants are the pre-existing, untestableClientUUID-fallback arms (symfony/uid is always installed in dev).