Skip to content

Commit 7a701ea

Browse files
committed
[BE] MethodSignatureRule - look at abstract trait method
1 parent 8430805 commit 7a701ea

File tree

8 files changed

+24
-31
lines changed

8 files changed

+24
-31
lines changed

changelog-2.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ Bleeding edge (TODO move to other sections)
6464
* More precise `scandir()` signature ([#2518](https://github.com/phpstan/phpstan-src/pull/2518)), thanks @staabm!
6565
* More precise `extract()` signature ([#2517](https://github.com/phpstan/phpstan-src/pull/2517)), thanks @staabm!
6666
* Detect overriding `@final` method in OverridingMethodRule, #9135
67-
* MethodSignatureRule - look at abstract trait method (https://github.com/phpstan/phpstan-src/commit/5fd8cee591ce1b07daa5f98a1ddcdfc723f1b5eb)
6867
* MagicConstantContextRule ([#2741](https://github.com/phpstan/phpstan-src/pull/2741)), #10099, thanks @staabm!
6968
* More precise `RecursiveIteratorIterator::__construct()` parameter types ([#2835](https://github.com/phpstan/phpstan-src/pull/2835)), thanks @staabm!
7069
* TooWideMethodReturnTypehintRule - always report for final methods (https://github.com/phpstan/phpstan-src/commit/c30e9a484c8245b8126cd63444607ca74d2af761)
@@ -139,6 +138,7 @@ Improvements 🔧
139138
* Run missing type check on `@param-out` (https://github.com/phpstan/phpstan-src/commit/56b20024386d983927c64dfa895ff026bed2798c)
140139
* Report "missing return" error closer to where the return is missing (https://github.com/phpstan/phpstan-src/commit/04f8636e6577cbcaefc944725eed74c0d7865ead)
141140
* Report dead types even in multi-exception catch ([#2399](https://github.com/phpstan/phpstan-src/pull/2399)), thanks @JanTvrdik!
141+
* MethodSignatureRule - look at abstract trait method (https://github.com/phpstan/phpstan-src/commit/5fd8cee591ce1b07daa5f98a1ddcdfc723f1b5eb)
142142

143143
Bugfixes 🐛
144144
=====================

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ parameters:
1717
runtimeReflectionRules: true
1818
notAnalysedTrait: true
1919
curlSetOptTypes: true
20-
abstractTraitMethod: true
2120
missingMagicSerializationRule: true
2221
nullContextForVoidReturningFunctions: true
2322
unescapeStrings: true

conf/config.neon

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ parameters:
5252
runtimeReflectionRules: false
5353
notAnalysedTrait: false
5454
curlSetOptTypes: false
55-
abstractTraitMethod: false
5655
missingMagicSerializationRule: false
5756
nullContextForVoidReturningFunctions: false
5857
unescapeStrings: false
@@ -1046,7 +1045,6 @@ services:
10461045
arguments:
10471046
reportMaybes: %reportMaybesInMethodSignatures%
10481047
reportStatic: %reportStaticMethodSignatures%
1049-
abstractTraitMethod: %featureToggles.abstractTraitMethod%
10501048

10511049
-
10521050
class: PHPStan\Rules\Methods\MethodParameterComparisonHelper

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ parametersSchema:
4747
runtimeReflectionRules: bool()
4848
notAnalysedTrait: bool()
4949
curlSetOptTypes: bool()
50-
abstractTraitMethod: bool()
5150
missingMagicSerializationRule: bool()
5251
nullContextForVoidReturningFunctions: bool()
5352
unescapeStrings: bool()

src/PhpDoc/StubValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ private function getRuleRegistry(Container $container): RuleRegistry
196196
new ExistingClassesInTypehintsRule($functionDefinitionCheck),
197197
new \PHPStan\Rules\Functions\ExistingClassesInTypehintsRule($functionDefinitionCheck),
198198
new ExistingClassesInPropertiesRule($reflectionProvider, $classNameCheck, $unresolvableTypeHelper, $phpVersion, true, false),
199-
new OverridingMethodRule($phpVersion, new MethodSignatureRule($phpClassReflectionExtension, true, true, $container->getParameter('featureToggles')['abstractTraitMethod']), true, new MethodParameterComparisonHelper($phpVersion, $container->getParameter('featureToggles')['genericPrototypeMessage']), $phpClassReflectionExtension, $container->getParameter('featureToggles')['genericPrototypeMessage'], $container->getParameter('featureToggles')['finalByPhpDoc'], $container->getParameter('checkMissingOverrideMethodAttribute')),
199+
new OverridingMethodRule($phpVersion, new MethodSignatureRule($phpClassReflectionExtension, true, true), true, new MethodParameterComparisonHelper($phpVersion, $container->getParameter('featureToggles')['genericPrototypeMessage']), $phpClassReflectionExtension, $container->getParameter('featureToggles')['genericPrototypeMessage'], $container->getParameter('featureToggles')['finalByPhpDoc'], $container->getParameter('checkMissingOverrideMethodAttribute')),
200200
new DuplicateDeclarationRule(),
201201
new LocalTypeAliasesRule($localTypeAliasesCheck),
202202
new LocalTypeTraitAliasesRule($localTypeAliasesCheck, $reflectionProvider),

src/Rules/Methods/MethodSignatureRule.php

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public function __construct(
4444
private PhpClassReflectionExtension $phpClassReflectionExtension,
4545
private bool $reportMaybes,
4646
private bool $reportStatic,
47-
private bool $abstractTraitMethod,
4847
)
4948
{
5049
}
@@ -169,30 +168,28 @@ private function collectParentMethods(string $methodName, ClassReflection $class
169168
$parentMethods[] = [$method, $method->getDeclaringClass()];
170169
}
171170

172-
if ($this->abstractTraitMethod) {
173-
foreach ($class->getTraits(true) as $trait) {
174-
$nativeTraitReflection = $trait->getNativeReflection();
175-
if (!$nativeTraitReflection->hasMethod($methodName)) {
176-
continue;
177-
}
178-
179-
$methodReflection = $nativeTraitReflection->getMethod($methodName);
180-
$isAbstract = $methodReflection->isAbstract();
181-
if (!$isAbstract) {
182-
continue;
183-
}
171+
foreach ($class->getTraits(true) as $trait) {
172+
$nativeTraitReflection = $trait->getNativeReflection();
173+
if (!$nativeTraitReflection->hasMethod($methodName)) {
174+
continue;
175+
}
184176

185-
$declaringTrait = $trait->getNativeMethod($methodName)->getDeclaringClass();
186-
$parentMethods[] = [
187-
$this->phpClassReflectionExtension->createUserlandMethodReflection(
188-
$trait,
189-
$class,
190-
new NativeBuiltinMethodReflection($methodReflection),
191-
$declaringTrait->getName(),
192-
),
193-
$declaringTrait,
194-
];
177+
$methodReflection = $nativeTraitReflection->getMethod($methodName);
178+
$isAbstract = $methodReflection->isAbstract();
179+
if (!$isAbstract) {
180+
continue;
195181
}
182+
183+
$declaringTrait = $trait->getNativeMethod($methodName)->getDeclaringClass();
184+
$parentMethods[] = [
185+
$this->phpClassReflectionExtension->createUserlandMethodReflection(
186+
$trait,
187+
$class,
188+
new NativeBuiltinMethodReflection($methodReflection),
189+
$declaringTrait->getName(),
190+
),
191+
$declaringTrait,
192+
];
196193
}
197194

198195
return $parentMethods;

tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ protected function getRule(): Rule
2626

2727
return new OverridingMethodRule(
2828
$phpVersion,
29-
new MethodSignatureRule($phpClassReflectionExtension, $this->reportMaybes, $this->reportStatic, true),
29+
new MethodSignatureRule($phpClassReflectionExtension, $this->reportMaybes, $this->reportStatic),
3030
true,
3131
new MethodParameterComparisonHelper($phpVersion, true),
3232
$phpClassReflectionExtension,

tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function getRule(): Rule
2828

2929
return new OverridingMethodRule(
3030
$phpVersion,
31-
new MethodSignatureRule($phpClassReflectionExtension, true, true, true),
31+
new MethodSignatureRule($phpClassReflectionExtension, true, true),
3232
false,
3333
new MethodParameterComparisonHelper($phpVersion, true),
3434
$phpClassReflectionExtension,

0 commit comments

Comments
 (0)