Skip to content

Commit 870aa06

Browse files
committed
[BE] OverridingMethodRule - include template types in prototype declaring class description
1 parent 7a701ea commit 870aa06

File tree

10 files changed

+27
-36
lines changed

10 files changed

+27
-36
lines changed

changelog-2.0.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ Bleeding edge (TODO move to other sections)
5151
* Specify `Imagick` parameter types ([#2334](https://github.com/phpstan/phpstan-src/pull/2334)), thanks @zonuexe!
5252
* Fix position variance of static method parameters ([#2313](https://github.com/phpstan/phpstan-src/pull/2313)), thanks @jiripudil!
5353
* Check variance of template types in properties ([#2314](https://github.com/phpstan/phpstan-src/pull/2314)), thanks @jiripudil!
54-
* OverridingMethodRule - include template types in prototype declaring class description (https://github.com/phpstan/phpstan-src/commit/ca2c66cc4dff59ba44d52b82cb9e0aa3256240f3)
5554
* Report narrowing `PHPStan\Type\Type` interface via `@var` (https://github.com/phpstan/phpstan-src/commit/713b98fb107213c28e3d8c8b4b43c5f5fc47c144), https://github.com/nunomaduro/larastan/issues/1567#issuecomment-1460445389
5655
* Check invalid PHPDocs in previously unchecked statement types (https://github.com/phpstan/phpstan-src/commit/9780d352f3264aac09ac7954f691de1877db8e01)
5756
* InvalidPHPStanDocTagRule in StubValidator (https://github.com/phpstan/phpstan-src/commit/9c2552b7e744926d1a74c1ba8fd32c64079eed61)
@@ -139,6 +138,7 @@ Improvements 🔧
139138
* Report "missing return" error closer to where the return is missing (https://github.com/phpstan/phpstan-src/commit/04f8636e6577cbcaefc944725eed74c0d7865ead)
140139
* Report dead types even in multi-exception catch ([#2399](https://github.com/phpstan/phpstan-src/pull/2399)), thanks @JanTvrdik!
141140
* MethodSignatureRule - look at abstract trait method (https://github.com/phpstan/phpstan-src/commit/5fd8cee591ce1b07daa5f98a1ddcdfc723f1b5eb)
141+
* OverridingMethodRule - include template types in prototype declaring class description (https://github.com/phpstan/phpstan-src/commit/ca2c66cc4dff59ba44d52b82cb9e0aa3256240f3)
142142

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

conf/bleedingEdge.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ parameters:
3232
paramOutVariance: true
3333
strictStaticMethodTemplateTypeVariance: true
3434
propertyVariance: true
35-
genericPrototypeMessage: true
3635
stricterFunctionMap: true
3736
zeroFiles: true
3837
projectServicesNotInAnalysedPaths: 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-
genericPrototypeMessage: %featureToggles.genericPrototypeMessage%
182181
finalByPhpDoc: %featureToggles.finalByPhpDoc%
183182
checkMissingOverrideMethodAttribute: %checkMissingOverrideMethodAttribute%
184183
tags:

conf/config.neon

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ parameters:
6868

6969
strictStaticMethodTemplateTypeVariance: false
7070
propertyVariance: false
71-
genericPrototypeMessage: false
7271
stricterFunctionMap: false
7372
zeroFiles: false
7473
projectServicesNotInAnalysedPaths: false
@@ -1048,8 +1047,6 @@ services:
10481047

10491048
-
10501049
class: PHPStan\Rules\Methods\MethodParameterComparisonHelper
1051-
arguments:
1052-
genericPrototypeMessage: %featureToggles.genericPrototypeMessage%
10531050

10541051
-
10551052
class: PHPStan\Rules\MissingTypehintCheck

conf/parametersSchema.neon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ parametersSchema:
6262
paramOutVariance: bool()
6363
strictStaticMethodTemplateTypeVariance: bool()
6464
propertyVariance: bool()
65-
genericPrototypeMessage: bool()
6665
stricterFunctionMap: bool()
6766
zeroFiles: bool()
6867
projectServicesNotInAnalysedPaths: 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, $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), $phpClassReflectionExtension, $container->getParameter('featureToggles')['finalByPhpDoc'], $container->getParameter('checkMissingOverrideMethodAttribute')),
200200
new DuplicateDeclarationRule(),
201201
new LocalTypeAliasesRule($localTypeAliasesCheck),
202202
new LocalTypeTraitAliasesRule($localTypeAliasesCheck, $reflectionProvider),

src/Rules/Methods/MethodParameterComparisonHelper.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
final class MethodParameterComparisonHelper
2525
{
2626

27-
public function __construct(private PhpVersion $phpVersion, private bool $genericPrototypeMessage)
27+
public function __construct(private PhpVersion $phpVersion)
2828
{
2929
}
3030

@@ -47,7 +47,7 @@ public function compare(ExtendedMethodReflection $prototype, ClassReflection $pr
4747
'Method %s::%s() overrides method %s::%s() but misses parameter #%d $%s.',
4848
$method->getDeclaringClass()->getDisplayName(),
4949
$method->getName(),
50-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
50+
$prototypeDeclaringClass->getDisplayName(true),
5151
$prototype->getName(),
5252
$i + 1,
5353
$prototypeParameter->getName(),
@@ -73,7 +73,7 @@ public function compare(ExtendedMethodReflection $prototype, ClassReflection $pr
7373
$method->getName(),
7474
$i + 1,
7575
$prototypeParameter->getName(),
76-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
76+
$prototypeDeclaringClass->getDisplayName(true),
7777
$prototype->getName(),
7878
))->identifier('parameter.byRef');
7979

@@ -92,7 +92,7 @@ public function compare(ExtendedMethodReflection $prototype, ClassReflection $pr
9292
$method->getName(),
9393
$i + 1,
9494
$prototypeParameter->getName(),
95-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
95+
$prototypeDeclaringClass->getDisplayName(true),
9696
$prototype->getName(),
9797
))->identifier('parameter.notByRef');
9898

@@ -133,7 +133,7 @@ public function compare(ExtendedMethodReflection $prototype, ClassReflection $pr
133133
$method->getName(),
134134
$i + 1,
135135
$prototypeParameter->getName(),
136-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
136+
$prototypeDeclaringClass->getDisplayName(true),
137137
$prototype->getName(),
138138
))->identifier('parameter.notVariadic');
139139

@@ -178,7 +178,7 @@ public function compare(ExtendedMethodReflection $prototype, ClassReflection $pr
178178
$i + $j + 1,
179179
$remainingPrototypeParameter->getName(),
180180
$remainingPrototypeParameter->getNativeType()->describe(VerbosityLevel::typeOnly()),
181-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
181+
$prototypeDeclaringClass->getDisplayName(true),
182182
$prototype->getName(),
183183
))->identifier('method.childParameterType');
184184

@@ -198,7 +198,7 @@ public function compare(ExtendedMethodReflection $prototype, ClassReflection $pr
198198
$method->getName(),
199199
$i + 1,
200200
$prototypeParameter->getName(),
201-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
201+
$prototypeDeclaringClass->getDisplayName(true),
202202
$prototype->getName(),
203203
))->identifier('parameter.variadic');
204204

@@ -220,7 +220,7 @@ public function compare(ExtendedMethodReflection $prototype, ClassReflection $pr
220220
$method->getName(),
221221
$i + 1,
222222
$prototypeParameter->getName(),
223-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
223+
$prototypeDeclaringClass->getDisplayName(true),
224224
$prototype->getName(),
225225
))->identifier('parameter.notOptional');
226226

@@ -246,7 +246,7 @@ public function compare(ExtendedMethodReflection $prototype, ClassReflection $pr
246246
$i + 1,
247247
$prototypeParameter->getName(),
248248
$prototypeParameterType->describe(VerbosityLevel::typeOnly()),
249-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
249+
$prototypeDeclaringClass->getDisplayName(true),
250250
$prototype->getName(),
251251
))->identifier('method.childParameterType');
252252

@@ -274,7 +274,7 @@ public function compare(ExtendedMethodReflection $prototype, ClassReflection $pr
274274
$i + 1,
275275
$prototypeParameter->getName(),
276276
$prototypeParameterType->describe(VerbosityLevel::typeOnly()),
277-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
277+
$prototypeDeclaringClass->getDisplayName(true),
278278
$prototype->getName(),
279279
))->identifier('method.childParameterType');
280280

@@ -294,7 +294,7 @@ public function compare(ExtendedMethodReflection $prototype, ClassReflection $pr
294294
$i + 1,
295295
$prototypeParameter->getName(),
296296
$prototypeParameterType->describe(VerbosityLevel::typeOnly()),
297-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
297+
$prototypeDeclaringClass->getDisplayName(true),
298298
$prototype->getName(),
299299
))->identifier('method.childParameterType');
300300

src/Rules/Methods/OverridingMethodRule.php

Lines changed: 12 additions & 13 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 $genericPrototypeMessage,
4241
private bool $finalByPhpDoc,
4342
private bool $checkMissingOverrideMethodAttribute,
4443
)
@@ -65,7 +64,7 @@ public function processNode(Node $node, Scope $scope): array
6564
'Method %s::%s() overrides final method %s::%s().',
6665
$method->getDeclaringClass()->getDisplayName(),
6766
$method->getName(),
68-
$parent->getDisplayName($this->genericPrototypeMessage),
67+
$parent->getDisplayName(true),
6968
$parentConstructor->getName(),
7069
))
7170
->nonIgnorable()
@@ -79,7 +78,7 @@ public function processNode(Node $node, Scope $scope): array
7978
'Method %s::%s() overrides @final method %s::%s().',
8079
$method->getDeclaringClass()->getDisplayName(),
8180
$method->getName(),
82-
$parent->getDisplayName($this->genericPrototypeMessage),
81+
$parent->getDisplayName(true),
8382
$parentConstructor->getName(),
8483
))->identifier('method.parentMethodFinalByPhpDoc')
8584
->build(),
@@ -116,7 +115,7 @@ public function processNode(Node $node, Scope $scope): array
116115
'Method %s::%s() overrides method %s::%s() but is missing the #[\Override] attribute.',
117116
$method->getDeclaringClass()->getDisplayName(),
118117
$method->getName(),
119-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
118+
$prototypeDeclaringClass->getDisplayName(true),
120119
$prototype->getName(),
121120
))->identifier('method.missingOverride')->build();
122121
}
@@ -125,7 +124,7 @@ public function processNode(Node $node, Scope $scope): array
125124
'Method %s::%s() overrides final method %s::%s().',
126125
$method->getDeclaringClass()->getDisplayName(),
127126
$method->getName(),
128-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
127+
$prototypeDeclaringClass->getDisplayName(true),
129128
$prototype->getName(),
130129
))
131130
->nonIgnorable()
@@ -136,7 +135,7 @@ public function processNode(Node $node, Scope $scope): array
136135
'Method %s::%s() overrides @final method %s::%s().',
137136
$method->getDeclaringClass()->getDisplayName(),
138137
$method->getName(),
139-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
138+
$prototypeDeclaringClass->getDisplayName(true),
140139
$prototype->getName(),
141140
))->identifier('method.parentMethodFinalByPhpDoc')
142141
->build();
@@ -148,7 +147,7 @@ public function processNode(Node $node, Scope $scope): array
148147
'Non-static method %s::%s() overrides static method %s::%s().',
149148
$method->getDeclaringClass()->getDisplayName(),
150149
$method->getName(),
151-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
150+
$prototypeDeclaringClass->getDisplayName(true),
152151
$prototype->getName(),
153152
))
154153
->nonIgnorable()
@@ -160,7 +159,7 @@ public function processNode(Node $node, Scope $scope): array
160159
'Static method %s::%s() overrides non-static method %s::%s().',
161160
$method->getDeclaringClass()->getDisplayName(),
162161
$method->getName(),
163-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
162+
$prototypeDeclaringClass->getDisplayName(true),
164163
$prototype->getName(),
165164
))
166165
->nonIgnorable()
@@ -176,7 +175,7 @@ public function processNode(Node $node, Scope $scope): array
176175
$method->isPrivate() ? 'Private' : 'Protected',
177176
$method->getDeclaringClass()->getDisplayName(),
178177
$method->getName(),
179-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
178+
$prototypeDeclaringClass->getDisplayName(true),
180179
$prototype->getName(),
181180
))
182181
->nonIgnorable()
@@ -188,7 +187,7 @@ public function processNode(Node $node, Scope $scope): array
188187
'Private method %s::%s() overriding protected method %s::%s() should be protected or public.',
189188
$method->getDeclaringClass()->getDisplayName(),
190189
$method->getName(),
191-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
190+
$prototypeDeclaringClass->getDisplayName(true),
192191
$prototype->getName(),
193192
))
194193
->nonIgnorable()
@@ -223,7 +222,7 @@ public function processNode(Node $node, Scope $scope): array
223222
$method->getDeclaringClass()->getDisplayName(),
224223
$method->getName(),
225224
$realPrototype->getTentativeReturnType()->describe(VerbosityLevel::typeOnly()),
226-
$realPrototype->getDeclaringClass()->getDisplayName($this->genericPrototypeMessage),
225+
$realPrototype->getDeclaringClass()->getDisplayName(true),
227226
$realPrototype->getName(),
228227
))
229228
->tip('Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.')
@@ -273,7 +272,7 @@ public function processNode(Node $node, Scope $scope): array
273272
$method->getDeclaringClass()->getDisplayName(),
274273
$method->getName(),
275274
$prototypeReturnType->describe(VerbosityLevel::typeOnly()),
276-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
275+
$prototypeDeclaringClass->getDisplayName(true),
277276
$prototype->getName(),
278277
))
279278
->nonIgnorable()
@@ -286,7 +285,7 @@ public function processNode(Node $node, Scope $scope): array
286285
$method->getDeclaringClass()->getDisplayName(),
287286
$method->getName(),
288287
$prototypeReturnType->describe(VerbosityLevel::typeOnly()),
289-
$prototypeDeclaringClass->getDisplayName($this->genericPrototypeMessage),
288+
$prototypeDeclaringClass->getDisplayName(true),
290289
$prototype->getName(),
291290
))
292291
->nonIgnorable()

tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,9 @@ protected function getRule(): Rule
2828
$phpVersion,
2929
new MethodSignatureRule($phpClassReflectionExtension, $this->reportMaybes, $this->reportStatic),
3030
true,
31-
new MethodParameterComparisonHelper($phpVersion, true),
31+
new MethodParameterComparisonHelper($phpVersion),
3232
$phpClassReflectionExtension,
3333
true,
34-
true,
3534
false,
3635
);
3736
}

tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@ protected function getRule(): Rule
3030
$phpVersion,
3131
new MethodSignatureRule($phpClassReflectionExtension, true, true),
3232
false,
33-
new MethodParameterComparisonHelper($phpVersion, true),
33+
new MethodParameterComparisonHelper($phpVersion),
3434
$phpClassReflectionExtension,
3535
true,
36-
true,
3736
$this->checkMissingOverrideMethodAttribute,
3837
);
3938
}

0 commit comments

Comments
 (0)