Skip to content

Inline code quality pack, replace Psalm with PHPStan, add tests - #3

Merged
loevgaard merged 2 commits into
masterfrom
replace-psalm-with-phpstan-and-inline-code-quality-pack
Jun 15, 2026
Merged

loevgaard merged 2 commits into
masterfrom
replace-psalm-with-phpstan-and-inline-code-quality-pack

Conversation

@loevgaard

Copy link
Copy Markdown
Member

Summary

Three related maintenance changes:

  1. Inline the newest code quality pack — setono/code-quality-pack is replaced by its constituent packages directly in require-dev, matching the v3 pack's set as adapted to keep PHP ≥ 8.1 (phpunit ^10.5 rather than the pack's ^11.5). shipmonk/composer-dependency-analyser replaces composer-require-checker + composer-unused.
  2. Replace Psalm with PHPStan — analysis runs at level: max. composer analyse now runs PHPStan; psalm.xml, composer-require-checker.json and rector.php are removed and phpstan.dist.neon + composer-dependency-analyser.php added. The CI matrix is expanded to PHP 8.1–8.4.
  3. Add missing tests — reconstruction round-trip (incl. restored expiry), lazy expiry via has()/get(), has()/toArray() pruning, the expiry boundary, the __expires container cleanup, and malformed-expiry handling.

Notable details

  • Metadata refactor: the Psalm-style array{__expires?: ..., ...<string, mixed>} shape is self-contradictory under PHPStan, so expiry tracking moved into its own array<string, int> $expires property. Behaviour is preserved — the only observable change is that __expires now serialises last instead of at insertion position, which is not part of the BC contract (reconstruction is key-based).
  • Test clock loading: tests/StaticClock.php is now loaded via the files autoloader instead of setUp(). PHP caches each unqualified time() call site's binding on first execution, so the shadow must exist before any src/ time() runs.
  • Implicit-nullable params made explicit for PHP 8.4.

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, untestable Client UUID-fallback arms (symfony/uid is always installed in dev).

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"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@loevgaard
loevgaard merged commit 654bc30 into master Jun 15, 2026
27 checks passed
@loevgaard
loevgaard deleted the replace-psalm-with-phpstan-and-inline-code-quality-pack branch June 15, 2026 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant