Repository navigation
Conversation
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']) |
There was a problem hiding this comment.
this should be differentiate between file extension scanned by rector and phpstan I guess, since scanned by rector means it will fixable via rector.
There was a problem hiding this comment.
A file that Rector processes has to be scanned by PHPStan as well: otherwise, since 2.8, any rule that needs the reflection of a class in it throws "should be known at this point", which is what happened to the 116 .inc files of the project in the issue. So this passes only the extensions Rector processes. PHPStan can still scan more than Rector changes: a fileExtensions list from a config given to withPHPStanConfigs() is merged with it (I checked with module added on top of this e2e project). On main, such a config is also the workaround for the issue, as the e2e project passes with fileExtensions: [php, inc] in it. Would you rather keep that workaround and document it, or have a separate option for the PHPStan list?
Fixes rectorphp/rector#9958
With
withFileExtensions(['php', 'inc'])the*.incfiles in a directory path are processed, but PHPStan indexes that directory for static reflection with its ownfileExtensions, which is onlyphp. The classes in those files are not known by name, so since 2.8.0fetchClassLikeReflection()throwsClass "App\ChildService" should be known at this point. TheClassLikepassed to it is the node being traversed (ChildServicehere,BaseProviderin 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*.incfile was not found either, soAddParamBasedOnParentClassMethodRectorchanged 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.incfiles that hit it.