Skip to content

Commit 5ff0a2e

Browse files
committed
Better backward-compatible messages
1 parent 0e58e14 commit 5ff0a2e

File tree

4 files changed

+29
-29
lines changed

4 files changed

+29
-29
lines changed

Diff for: src/Rules/Methods/MethodParameterComparisonHelper.php

+10-10
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
4747
'Method %s::%s() overrides method %s::%s() but misses parameter #%d $%s.',
4848
$method->getDeclaringClass()->getDisplayName(),
4949
$method->getName(),
50-
$prototype->getDeclaringClass()->getDisplayName(),
50+
$prototype->getDeclaringClass()->getDisplayName(false),
5151
$prototype->getName(),
5252
$i + 1,
5353
$prototypeParameter->getName(),
@@ -73,7 +73,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
7373
$method->getName(),
7474
$i + 1,
7575
$prototypeParameter->getName(),
76-
$prototype->getDeclaringClass()->getDisplayName(),
76+
$prototype->getDeclaringClass()->getDisplayName(false),
7777
$prototype->getName(),
7878
));
7979

@@ -92,7 +92,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
9292
$method->getName(),
9393
$i + 1,
9494
$prototypeParameter->getName(),
95-
$prototype->getDeclaringClass()->getDisplayName(),
95+
$prototype->getDeclaringClass()->getDisplayName(false),
9696
$prototype->getName(),
9797
));
9898

@@ -133,7 +133,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
133133
$method->getName(),
134134
$i + 1,
135135
$prototypeParameter->getName(),
136-
$prototype->getDeclaringClass()->getDisplayName(),
136+
$prototype->getDeclaringClass()->getDisplayName(false),
137137
$prototype->getName(),
138138
));
139139

@@ -181,7 +181,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
181181
$i + $j + 1,
182182
$remainingPrototypeParameter->getName(),
183183
$remainingPrototypeParameter->getNativeType()->describe(VerbosityLevel::typeOnly()),
184-
$prototype->getDeclaringClass()->getDisplayName(),
184+
$prototype->getDeclaringClass()->getDisplayName(false),
185185
$prototype->getName(),
186186
));
187187

@@ -201,7 +201,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
201201
$method->getName(),
202202
$i + 1,
203203
$prototypeParameter->getName(),
204-
$prototype->getDeclaringClass()->getDisplayName(),
204+
$prototype->getDeclaringClass()->getDisplayName(false),
205205
$prototype->getName(),
206206
));
207207

@@ -223,7 +223,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
223223
$method->getName(),
224224
$i + 1,
225225
$prototypeParameter->getName(),
226-
$prototype->getDeclaringClass()->getDisplayName(),
226+
$prototype->getDeclaringClass()->getDisplayName(false),
227227
$prototype->getName(),
228228
));
229229

@@ -253,7 +253,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
253253
$i + 1,
254254
$prototypeParameter->getName(),
255255
$prototypeParameterType->describe(VerbosityLevel::typeOnly()),
256-
$prototype->getDeclaringClass()->getDisplayName(),
256+
$prototype->getDeclaringClass()->getDisplayName(false),
257257
$prototype->getName(),
258258
));
259259

@@ -281,7 +281,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
281281
$i + 1,
282282
$prototypeParameter->getName(),
283283
$prototypeParameterType->describe(VerbosityLevel::typeOnly()),
284-
$prototype->getDeclaringClass()->getDisplayName(),
284+
$prototype->getDeclaringClass()->getDisplayName(false),
285285
$prototype->getName(),
286286
));
287287

@@ -301,7 +301,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
301301
$i + 1,
302302
$prototypeParameter->getName(),
303303
$prototypeParameterType->describe(VerbosityLevel::typeOnly()),
304-
$prototype->getDeclaringClass()->getDisplayName(),
304+
$prototype->getDeclaringClass()->getDisplayName(false),
305305
$prototype->getName(),
306306
));
307307

Diff for: src/Rules/Methods/OverridingMethodRule.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public function processNode(Node $node, Scope $scope): array
5353
'Method %s::%s() overrides final method %s::%s().',
5454
$method->getDeclaringClass()->getDisplayName(),
5555
$method->getName(),
56-
$parent->getDisplayName(),
56+
$parent->getDisplayName(false),
5757
$parentConstructor->getName(),
5858
))->nonIgnorable()->build(),
5959
], $node, $scope);
@@ -74,7 +74,7 @@ public function processNode(Node $node, Scope $scope): array
7474
'Method %s::%s() overrides final method %s::%s().',
7575
$method->getDeclaringClass()->getDisplayName(),
7676
$method->getName(),
77-
$prototype->getDeclaringClass()->getDisplayName(),
77+
$prototype->getDeclaringClass()->getDisplayName(false),
7878
$prototype->getName(),
7979
))->nonIgnorable()->build();
8080
}
@@ -85,7 +85,7 @@ public function processNode(Node $node, Scope $scope): array
8585
'Non-static method %s::%s() overrides static method %s::%s().',
8686
$method->getDeclaringClass()->getDisplayName(),
8787
$method->getName(),
88-
$prototype->getDeclaringClass()->getDisplayName(),
88+
$prototype->getDeclaringClass()->getDisplayName(false),
8989
$prototype->getName(),
9090
))->nonIgnorable()->build();
9191
}
@@ -94,7 +94,7 @@ public function processNode(Node $node, Scope $scope): array
9494
'Static method %s::%s() overrides non-static method %s::%s().',
9595
$method->getDeclaringClass()->getDisplayName(),
9696
$method->getName(),
97-
$prototype->getDeclaringClass()->getDisplayName(),
97+
$prototype->getDeclaringClass()->getDisplayName(false),
9898
$prototype->getName(),
9999
))->nonIgnorable()->build();
100100
}
@@ -106,7 +106,7 @@ public function processNode(Node $node, Scope $scope): array
106106
$method->isPrivate() ? 'Private' : 'Protected',
107107
$method->getDeclaringClass()->getDisplayName(),
108108
$method->getName(),
109-
$prototype->getDeclaringClass()->getDisplayName(),
109+
$prototype->getDeclaringClass()->getDisplayName(false),
110110
$prototype->getName(),
111111
))->nonIgnorable()->build();
112112
}
@@ -115,7 +115,7 @@ public function processNode(Node $node, Scope $scope): array
115115
'Private method %s::%s() overriding protected method %s::%s() should be protected or public.',
116116
$method->getDeclaringClass()->getDisplayName(),
117117
$method->getName(),
118-
$prototype->getDeclaringClass()->getDisplayName(),
118+
$prototype->getDeclaringClass()->getDisplayName(false),
119119
$prototype->getName(),
120120
))->nonIgnorable()->build();
121121
}
@@ -143,7 +143,7 @@ public function processNode(Node $node, Scope $scope): array
143143
$method->getDeclaringClass()->getDisplayName(),
144144
$method->getName(),
145145
$prototype->getTentativeReturnType()->describe(VerbosityLevel::typeOnly()),
146-
$prototype->getDeclaringClass()->getDisplayName(),
146+
$prototype->getDeclaringClass()->getDisplayName(false),
147147
$prototype->getName(),
148148
))->tip('Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.')->nonIgnorable()->build();
149149
}
@@ -165,7 +165,7 @@ public function processNode(Node $node, Scope $scope): array
165165
$method->getDeclaringClass()->getDisplayName(),
166166
$method->getName(),
167167
$prototypeReturnType->describe(VerbosityLevel::typeOnly()),
168-
$prototype->getDeclaringClass()->getDisplayName(),
168+
$prototype->getDeclaringClass()->getDisplayName(false),
169169
$prototype->getName(),
170170
))->nonIgnorable()->build();
171171
} else {
@@ -175,7 +175,7 @@ public function processNode(Node $node, Scope $scope): array
175175
$method->getDeclaringClass()->getDisplayName(),
176176
$method->getName(),
177177
$prototypeReturnType->describe(VerbosityLevel::typeOnly()),
178-
$prototype->getDeclaringClass()->getDisplayName(),
178+
$prototype->getDeclaringClass()->getDisplayName(false),
179179
$prototype->getName(),
180180
))->nonIgnorable()->build();
181181
}

Diff for: tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ public function testBug7652(): void
384384
$this->reportStatic = true;
385385
$this->analyse([__DIR__ . '/data/bug-7652.php'], [
386386
[
387-
'Return type mixed of method Bug7652\Options::offsetGet() is not covariant with tentative return type mixed of method ArrayAccess<key-of<TArray of array>,value-of<TArray of array>>::offsetGet().',
387+
'Return type mixed of method Bug7652\Options::offsetGet() is not covariant with tentative return type mixed of method ArrayAccess::offsetGet().',
388388
23,
389389
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
390390
],

Diff for: tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testOverridingFinalMethod(int $phpVersion, string $contravariant
8484
115,
8585
],
8686
[
87-
'Parameter #1 $size (int) of method OverridingFinalMethod\FixedArray::setSize() is not ' . $contravariantMessage . ' with parameter #1 $size (mixed) of method SplFixedArray<mixed>::setSize().',
87+
'Parameter #1 $size (int) of method OverridingFinalMethod\FixedArray::setSize() is not ' . $contravariantMessage . ' with parameter #1 $size (mixed) of method SplFixedArray::setSize().',
8888
125,
8989
],
9090
[
@@ -120,7 +120,7 @@ public function testOverridingFinalMethod(int $phpVersion, string $contravariant
120120
280,
121121
],
122122
[
123-
'Parameter #1 $index (int) of method OverridingFinalMethod\FixedArrayOffsetExists::offsetExists() is not ' . $contravariantMessage . ' with parameter #1 $offset (mixed) of method ArrayAccess<int,mixed>::offsetExists().',
123+
'Parameter #1 $index (int) of method OverridingFinalMethod\FixedArrayOffsetExists::offsetExists() is not ' . $contravariantMessage . ' with parameter #1 $offset (mixed) of method ArrayAccess::offsetExists().',
124124
313,
125125
],
126126
];
@@ -472,37 +472,37 @@ public function dataTentativeReturnTypes(): array
472472
80100,
473473
[
474474
[
475-
'Return type mixed of method TentativeReturnTypes\Foo::getIterator() is not covariant with tentative return type Traversable of method IteratorAggregate<mixed,mixed>::getIterator().',
475+
'Return type mixed of method TentativeReturnTypes\Foo::getIterator() is not covariant with tentative return type Traversable of method IteratorAggregate::getIterator().',
476476
8,
477477
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
478478
],
479479
[
480-
'Return type string of method TentativeReturnTypes\Lorem::getIterator() is not covariant with tentative return type Traversable of method IteratorAggregate<mixed,mixed>::getIterator().',
480+
'Return type string of method TentativeReturnTypes\Lorem::getIterator() is not covariant with tentative return type Traversable of method IteratorAggregate::getIterator().',
481481
40,
482482
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
483483
],
484484
[
485-
'Return type mixed of method TentativeReturnTypes\UntypedIterator::current() is not covariant with tentative return type mixed of method Iterator<mixed,mixed>::current().',
485+
'Return type mixed of method TentativeReturnTypes\UntypedIterator::current() is not covariant with tentative return type mixed of method Iterator::current().',
486486
75,
487487
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
488488
],
489489
[
490-
'Return type mixed of method TentativeReturnTypes\UntypedIterator::next() is not covariant with tentative return type void of method Iterator<mixed,mixed>::next().',
490+
'Return type mixed of method TentativeReturnTypes\UntypedIterator::next() is not covariant with tentative return type void of method Iterator::next().',
491491
79,
492492
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
493493
],
494494
[
495-
'Return type mixed of method TentativeReturnTypes\UntypedIterator::key() is not covariant with tentative return type mixed of method Iterator<mixed,mixed>::key().',
495+
'Return type mixed of method TentativeReturnTypes\UntypedIterator::key() is not covariant with tentative return type mixed of method Iterator::key().',
496496
83,
497497
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
498498
],
499499
[
500-
'Return type mixed of method TentativeReturnTypes\UntypedIterator::valid() is not covariant with tentative return type bool of method Iterator<mixed,mixed>::valid().',
500+
'Return type mixed of method TentativeReturnTypes\UntypedIterator::valid() is not covariant with tentative return type bool of method Iterator::valid().',
501501
87,
502502
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
503503
],
504504
[
505-
'Return type mixed of method TentativeReturnTypes\UntypedIterator::rewind() is not covariant with tentative return type void of method Iterator<mixed,mixed>::rewind().',
505+
'Return type mixed of method TentativeReturnTypes\UntypedIterator::rewind() is not covariant with tentative return type void of method Iterator::rewind().',
506506
91,
507507
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
508508
],

0 commit comments

Comments
 (0)