Skip to content

Bump to PHPStan ^2.2.6 and Fix its Container compatibility in RichParser - #8208

Merged
TomasVotruba merged 5 commits into
mainfrom
bump-phpstan-226
Jul 27, 2026
Merged

Bump to PHPStan ^2.2.6 and Fix its Container compatibility in RichParser#8208
TomasVotruba merged 5 commits into
mainfrom
bump-phpstan-226

Conversation

@samsonasik

@samsonasik samsonasik commented Jul 26, 2026

Copy link
Copy Markdown
Member

Fixes rectorphp/rector#9824

Currently update to use phpstan 2.2.6 cause crash:

PHP Fatal error:  Uncaught Rector\Exception\Reflection\MissingPrivatePropertyException:
Property "$container" was not found in "PHPStan\Parser\RichParser" class
  in vendor/rector/rector/src/Util/Reflection/PrivatesAccessor.php:82

This PR try bump to PHPStan ^2.2.6 and Fix its Container compatibility in RichParser.

See crash

https://github.com/rectorphp/rector-src/actions/runs/30224923562/job/89853439240#step:6:9

@samsonasik
samsonasik requested a review from TomasVotruba July 26, 2026 23:35
@samsonasik

samsonasik commented Jul 26, 2026

Copy link
Copy Markdown
Member Author

Fixed 🎉 /cc @magicsunday

@TomasVotruba this needs merge and release to fix test compat and test packages on rector-drupal and and rector-laravel in CI above.

I don't have merge access when CI is required.

Screenshot 2026-07-27 at 06 40 46

@michaelmeneses

Copy link
Copy Markdown

Independent reproduction, plus a diagnosis of why the 5 red checks are not the patch's fault.

Reproduction

Downstream project (middag-io/middag-php-dev-tools, ~2400 tests), same bisect as #9824:

phpstan/phpstan composer test
2.2.5 Tests: 2395, Assertions: 9248, Skipped: 1 — green
2.2.6 Tests: 2395, Assertions: 9234, Errors: 11, Skipped: 1

All 11 failures are Rector rule tests (AbstractRectorTestCase), identical trace:

Rector\Exception\Reflection\MissingPrivatePropertyException:
Property "$container" was not found in "PHPStan\Parser\RichParser" class
  src/Util/Reflection/PrivatesAccessor.php:82
  src/DependencyInjection/PHPStan/PHPStanContainerMemento.php:24
  src/PhpParser/Parser/RectorParser.php:32

We are currently capped at phpstan/phpstan: ">=2.0 <2.2.6" waiting for this.

Why the 5 failing checks cannot pass yet

None of them exercise this PR's src/. They all install the published rector/rector, which does not have the fix:

  • Rector dev + PHPUnit 10/11/12 — run in compat-tests/, whose composer.json requires "rector/rector": "dev-main as 2.4.4" together with "phpstan/phpstan": "^2.2" (resolves to 2.2.6). The trace in those logs points at compat-tests/vendor/rector/rector/..., not at the working tree.
  • rector_laravel_rector_dev and rector_drupal_rector_dev — both do composer require rector/rector:dev-main against a freshly cloned downstream repo.

So the failure is the very bug this PR fixes, arriving through the published artifact. It is circular: those jobs can only go green once a release carrying the fix exists, which cannot happen until this merges.

Two ways to break the cycle

  1. Immediate: pin "phpstan/phpstan": "<2.2.6" in compat-tests/composer.json (and constrain it in the two downstream workflows) so they keep testing what they are meant to test — PHPUnit/PHPStan preload compatibility — and revert the pin after the release.
  2. Structural: make the compat and downstream jobs consume the build produced from the current tree (path repository or the build_scoped_rector artifact) instead of dev-main from Packagist. That way a PR fixing an artifact-level bug is actually testable, instead of being blocked by the artifact it fixes.

Happy to open a PR for either if it helps.

@samsonasik

Copy link
Copy Markdown
Member Author

@michaelmeneses this just need merge and new release :)

@TomasVotruba
TomasVotruba merged commit 009a5e4 into main Jul 27, 2026
67 of 73 checks passed
@TomasVotruba
TomasVotruba deleted the bump-phpstan-226 branch July 27, 2026 05:44
@TomasVotruba

Copy link
Copy Markdown
Member

Thank you 👌

@samsonasik

Copy link
Copy Markdown
Member Author

Released 2.5.8 for it 👍 https://github.com/rectorphp/rector/releases/tag/2.5.8

konradmichalik added a commit to konradmichalik/php-doc-block-header-fixer that referenced this pull request Jul 27, 2026
phpstan/phpstan 2.2.6 removed the private $container property on
RichParser that Rector's PHPStanContainerMemento accessed via
reflection, crashing every rector run. Fixed upstream in
rectorphp/rector-src#8208 and released as rector/rector 2.5.8.
konradmichalik added a commit to konradmichalik/php-doc-block-header-fixer that referenced this pull request Jul 27, 2026
phpstan/phpstan 2.2.6 removed the private $container property on
RichParser that Rector's PHPStanContainerMemento accessed via
reflection, crashing every rector run. Fixed upstream in
rectorphp/rector-src#8208 and released as rector/rector 2.5.8.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Fatal error with PHPStan 2.2.6: RichParser::$container no longer exists

4 participants