Skip to content

Commit 84ab800

Browse files
committed
[BE] Detect overriding @final method in OverridingMethodRule
1 parent 870aa06 commit 84ab800

File tree

9 files changed

+4
-11
lines changed

9 files changed

+4
-11
lines changed

changelog-2.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ Bleeding edge (TODO move to other sections)
6262
* More precise `stream_socket_client()` signature ([#2519](https://github.com/phpstan/phpstan-src/pull/2519)), thanks @staabm!
6363
* More precise `scandir()` signature ([#2518](https://github.com/phpstan/phpstan-src/pull/2518)), thanks @staabm!
6464
* More precise `extract()` signature ([#2517](https://github.com/phpstan/phpstan-src/pull/2517)), thanks @staabm!
65-
* Detect overriding `@final` method in OverridingMethodRule, #9135
6665
* MagicConstantContextRule ([#2741](https://github.com/phpstan/phpstan-src/pull/2741)), #10099, thanks @staabm!
6766
* More precise `RecursiveIteratorIterator::__construct()` parameter types ([#2835](https://github.com/phpstan/phpstan-src/pull/2835)), thanks @staabm!
6867
* TooWideMethodReturnTypehintRule - always report for final methods (https://github.com/phpstan/phpstan-src/commit/c30e9a484c8245b8126cd63444607ca74d2af761)
@@ -139,6 +138,7 @@ Improvements 🔧
139138
* Report dead types even in multi-exception catch ([#2399](https://github.com/phpstan/phpstan-src/pull/2399)), thanks @JanTvrdik!
140139
* MethodSignatureRule - look at abstract trait method (https://github.com/phpstan/phpstan-src/commit/5fd8cee591ce1b07daa5f98a1ddcdfc723f1b5eb)
141140
* OverridingMethodRule - include template types in prototype declaring class description (https://github.com/phpstan/phpstan-src/commit/ca2c66cc4dff59ba44d52b82cb9e0aa3256240f3)
141+
* Detect overriding `@final` method in OverridingMethodRule, #9135
142142

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

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ parameters:
3636
zeroFiles: true
3737
projectServicesNotInAnalysedPaths: true
3838
callUserFunc: true
39-
finalByPhpDoc: true
4039
magicConstantOutOfContext: true
4140
pure: true
4241
checkParameterCastableToStringFunctions: true

conf/config.level0.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ services:
178178
class: PHPStan\Rules\Methods\OverridingMethodRule
179179
arguments:
180180
checkPhpDocMethodSignatures: %checkPhpDocMethodSignatures%
181-
finalByPhpDoc: %featureToggles.finalByPhpDoc%
182181
checkMissingOverrideMethodAttribute: %checkMissingOverrideMethodAttribute%
183182
tags:
184183
- phpstan.rules.rule

conf/config.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ parameters:
7272
zeroFiles: false
7373
projectServicesNotInAnalysedPaths: false
7474
callUserFunc: false
75-
finalByPhpDoc: false
7675
magicConstantOutOfContext: false
7776
pure: false
7877
checkParameterCastableToStringFunctions: false

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ parametersSchema:
6666
zeroFiles: bool()
6767
projectServicesNotInAnalysedPaths: bool()
6868
callUserFunc: bool()
69-
finalByPhpDoc: bool()
7069
magicConstantOutOfContext: bool()
7170
pure: bool()
7271
checkParameterCastableToStringFunctions: 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), true, new MethodParameterComparisonHelper($phpVersion), $phpClassReflectionExtension, $container->getParameter('featureToggles')['finalByPhpDoc'], $container->getParameter('checkMissingOverrideMethodAttribute')),
199+
new OverridingMethodRule($phpVersion, new MethodSignatureRule($phpClassReflectionExtension, true, true), true, new MethodParameterComparisonHelper($phpVersion), $phpClassReflectionExtension, $container->getParameter('checkMissingOverrideMethodAttribute')),
200200
new DuplicateDeclarationRule(),
201201
new LocalTypeAliasesRule($localTypeAliasesCheck),
202202
new LocalTypeTraitAliasesRule($localTypeAliasesCheck, $reflectionProvider),

src/Rules/Methods/OverridingMethodRule.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ public function __construct(
3838
private bool $checkPhpDocMethodSignatures,
3939
private MethodParameterComparisonHelper $methodParameterComparisonHelper,
4040
private PhpClassReflectionExtension $phpClassReflectionExtension,
41-
private bool $finalByPhpDoc,
4241
private bool $checkMissingOverrideMethodAttribute,
4342
)
4443
{
@@ -72,7 +71,7 @@ public function processNode(Node $node, Scope $scope): array
7271
->build(),
7372
], $node, $scope);
7473
}
75-
if ($parentConstructor->isFinal()->yes() && $this->finalByPhpDoc) {
74+
if ($parentConstructor->isFinal()->yes()) {
7675
return $this->addErrors([
7776
RuleErrorBuilder::message(sprintf(
7877
'Method %s::%s() overrides @final method %s::%s().',
@@ -130,7 +129,7 @@ public function processNode(Node $node, Scope $scope): array
130129
->nonIgnorable()
131130
->identifier('method.parentMethodFinal')
132131
->build();
133-
} elseif ($prototype->isFinal()->yes() && $this->finalByPhpDoc) {
132+
} elseif ($prototype->isFinal()->yes()) {
134133
$messages[] = RuleErrorBuilder::message(sprintf(
135134
'Method %s::%s() overrides @final method %s::%s().',
136135
$method->getDeclaringClass()->getDisplayName(),

tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ protected function getRule(): Rule
3030
true,
3131
new MethodParameterComparisonHelper($phpVersion),
3232
$phpClassReflectionExtension,
33-
true,
3433
false,
3534
);
3635
}

tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ protected function getRule(): Rule
3232
false,
3333
new MethodParameterComparisonHelper($phpVersion),
3434
$phpClassReflectionExtension,
35-
true,
3635
$this->checkMissingOverrideMethodAttribute,
3736
);
3837
}

0 commit comments

Comments
 (0)