-
-
Notifications
You must be signed in to change notification settings - Fork 17
feat: add support for phpstan>=2.1.12 #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.x
Are you sure you want to change the base?
Conversation
But it needs another argument after the other arguments ( I think it'll be much better if the $nodeScopeResolver = new NodeScopeResolver( // @phpstan-ignore-line
reflectionProvider: $reflectionProvider,
initializerExprTypeResolver: $container->getByType(InitializerExprTypeResolver::class),
reflector: $container->getService('betterReflectionReflector'), // @phpstan-ignore-line
classReflectionExtensionRegistryProvider: $container->getByType(ClassReflectionExtensionRegistryProvider::class),
parameterOutTypeExtensionProvider: $container->getByType(ParameterOutTypeExtensionProvider::class),
parser: $container->getService('defaultAnalysisParser'), // @phpstan-ignore-line
fileTypeMapper: $container->getByType(FileTypeMapper::class),
stubPhpDocProvider: $container->getByType(StubPhpDocProvider::class),
phpVersion: $container->getByType(PhpVersion::class),
signatureMapProvider: $container->getByType(SignatureMapProvider::class),
deprecationProvider: $container->getByType(DeprecationProvider::class),
attributeReflectionFactory: $container->getByType(AttributeReflectionFactory::class),
phpDocInheritanceResolver: $container->getByType(PhpDocInheritanceResolver::class),
fileHelper: $container->getByType(FileHelper::class),
typeSpecifier: $typeSpecifier, // @phpstan-ignore-line
dynamicThrowTypeExtensionProvider: $container->getByType(DynamicThrowTypeExtensionProvider::class),
readWritePropertiesExtensionProvider: $container->getByType(ReadWritePropertiesExtensionProvider::class),
parameterClosureTypeExtensionProvider: $container->getByType(ParameterClosureTypeExtensionProvider::class),
scopeFactory: $scopeFactory,
polluteScopeWithLoopInitialAssignments: false,
polluteScopeWithAlwaysIterableForeach: true,
polluteScopeWithBlock: true, // @phpstan-ignore-line
earlyTerminatingMethodCalls: [],
earlyTerminatingFunctionCalls: [],
universalObjectCratesClasses: [], // @phpstan-ignore-line
implicitThrows: true,
treatPhpDocTypesAsCertain: true,
narrowMethodScopeFromConstructor: true,
); |
I’ve switched the NodeScopeResolver instantiation to named arguments and added the extra narrowMethodScopeFromConstructor parameter as requested. |
NodeScopeResolver constructor isn't covered by BC promise (https://phpstan.org/developing-extensions/backward-compatibility-promise) because it often changes. The proper solution is to fetch NodeScopeResolver via |
Do you mean that all this code including all the version checks could be replaced with: |
I’ve applied the improvements focusing on readability and maintainability. Here’s how the code looks now — I’m retrieving the required services (NodeScopeResolver and FileAnalyser) using $container->getByType(), as suggested. I also moved the rule and collector registry creation into clearly named variables for better clarity. Thanks a lot for the great tips — they helped clean this up nicely! |
Nice cleanup! |
Since PHPStan 2.1.12 introduces an additional constructor parameter in NodeScopeResolver, this PR adjusts the constructor invocation for PHPStan ≥ 2.1.12.