Skip to content

[Core] Pass withFileExtensions() to the PHPStan directory scan - #8926

Open
APX403 wants to merge 1 commit into
rectorphp:mainfrom
APX403:phpstan-scan-file-extensions
Open

APX403 wants to merge 1 commit into
rectorphp:mainfrom
APX403:phpstan-scan-file-extensions

Conversation

@APX403

@APX403 APX403 commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Fixes rectorphp/rector#9958

With withFileExtensions(['php', 'inc']) the *.inc files in a directory path are processed, but PHPStan indexes that directory for static reflection with its own fileExtensions, which is only php. The classes in those files are not known by name, so since 2.8.0 fetchClassLikeReflection() throws Class "App\ChildService" should be known at this point. The ClassLike passed to it is the node being traversed (ChildService here, BaseProvider in the trace from the issue), so the class is unknown only because PHPStan never scanned the file that declares it. 2.7 did not crash, but a parent declared in another *.inc file was not found either, so AddParamBasedOnParentClassMethodRector changed nothing there.

The PHPStan container now gets the extensions from withFileExtensions(). The new e2e test fails on main with the error above, and on the LAM repository from the issue the error is gone for all 116 .inc files that hit it.

PHPStan indexes the directories in paths for static reflection, but only
looks at *.php files by default. A class in a processed *.inc file was not
known by name, and since 2.8.0 fetchClassLikeReflection() throws "Class
... should be known at this point" for it.

return RectorConfig::configure()
->withPaths([__DIR__ . '/src'])
->withFileExtensions(['php', 'inc'])

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this should be differentiate between file extension scanned by rector and phpstan I guess, since scanned by rector means it will fixable via rector.

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.

System error: Class ... should be known at this point

2 participants