Skip to content

Commit

Permalink
Better backward-compatible messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Apr 4, 2023
1 parent 0e58e14 commit 5ff0a2e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
20 changes: 10 additions & 10 deletions src/Rules/Methods/MethodParameterComparisonHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
'Method %s::%s() overrides method %s::%s() but misses parameter #%d $%s.',
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
$i + 1,
$prototypeParameter->getName(),
Expand All @@ -73,7 +73,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
$method->getName(),
$i + 1,
$prototypeParameter->getName(),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
));

Expand All @@ -92,7 +92,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
$method->getName(),
$i + 1,
$prototypeParameter->getName(),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
));

Expand Down Expand Up @@ -133,7 +133,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
$method->getName(),
$i + 1,
$prototypeParameter->getName(),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
));

Expand Down Expand Up @@ -181,7 +181,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
$i + $j + 1,
$remainingPrototypeParameter->getName(),
$remainingPrototypeParameter->getNativeType()->describe(VerbosityLevel::typeOnly()),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
));

Expand All @@ -201,7 +201,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
$method->getName(),
$i + 1,
$prototypeParameter->getName(),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
));

Expand All @@ -223,7 +223,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
$method->getName(),
$i + 1,
$prototypeParameter->getName(),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
));

Expand Down Expand Up @@ -253,7 +253,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
$i + 1,
$prototypeParameter->getName(),
$prototypeParameterType->describe(VerbosityLevel::typeOnly()),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
));

Expand Down Expand Up @@ -281,7 +281,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
$i + 1,
$prototypeParameter->getName(),
$prototypeParameterType->describe(VerbosityLevel::typeOnly()),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
));

Expand All @@ -301,7 +301,7 @@ public function compare(MethodPrototypeReflection $prototype, PhpMethodFromParse
$i + 1,
$prototypeParameter->getName(),
$prototypeParameterType->describe(VerbosityLevel::typeOnly()),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
));

Expand Down
18 changes: 9 additions & 9 deletions src/Rules/Methods/OverridingMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function processNode(Node $node, Scope $scope): array
'Method %s::%s() overrides final method %s::%s().',
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
$parent->getDisplayName(),
$parent->getDisplayName(false),
$parentConstructor->getName(),
))->nonIgnorable()->build(),
], $node, $scope);
Expand All @@ -74,7 +74,7 @@ public function processNode(Node $node, Scope $scope): array
'Method %s::%s() overrides final method %s::%s().',
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
))->nonIgnorable()->build();
}
Expand All @@ -85,7 +85,7 @@ public function processNode(Node $node, Scope $scope): array
'Non-static method %s::%s() overrides static method %s::%s().',
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
))->nonIgnorable()->build();
}
Expand All @@ -94,7 +94,7 @@ public function processNode(Node $node, Scope $scope): array
'Static method %s::%s() overrides non-static method %s::%s().',
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
))->nonIgnorable()->build();
}
Expand All @@ -106,7 +106,7 @@ public function processNode(Node $node, Scope $scope): array
$method->isPrivate() ? 'Private' : 'Protected',
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
))->nonIgnorable()->build();
}
Expand All @@ -115,7 +115,7 @@ public function processNode(Node $node, Scope $scope): array
'Private method %s::%s() overriding protected method %s::%s() should be protected or public.',
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
))->nonIgnorable()->build();
}
Expand Down Expand Up @@ -143,7 +143,7 @@ public function processNode(Node $node, Scope $scope): array
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
$prototype->getTentativeReturnType()->describe(VerbosityLevel::typeOnly()),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
))->tip('Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.')->nonIgnorable()->build();
}
Expand All @@ -165,7 +165,7 @@ public function processNode(Node $node, Scope $scope): array
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
$prototypeReturnType->describe(VerbosityLevel::typeOnly()),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
))->nonIgnorable()->build();
} else {
Expand All @@ -175,7 +175,7 @@ public function processNode(Node $node, Scope $scope): array
$method->getDeclaringClass()->getDisplayName(),
$method->getName(),
$prototypeReturnType->describe(VerbosityLevel::typeOnly()),
$prototype->getDeclaringClass()->getDisplayName(),
$prototype->getDeclaringClass()->getDisplayName(false),
$prototype->getName(),
))->nonIgnorable()->build();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/PHPStan/Rules/Methods/MethodSignatureRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public function testBug7652(): void
$this->reportStatic = true;
$this->analyse([__DIR__ . '/data/bug-7652.php'], [
[
'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().',
'Return type mixed of method Bug7652\Options::offsetGet() is not covariant with tentative return type mixed of method ArrayAccess::offsetGet().',
23,
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
],
Expand Down
18 changes: 9 additions & 9 deletions tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function testOverridingFinalMethod(int $phpVersion, string $contravariant
115,
],
[
'Parameter #1 $size (int) of method OverridingFinalMethod\FixedArray::setSize() is not ' . $contravariantMessage . ' with parameter #1 $size (mixed) of method SplFixedArray<mixed>::setSize().',
'Parameter #1 $size (int) of method OverridingFinalMethod\FixedArray::setSize() is not ' . $contravariantMessage . ' with parameter #1 $size (mixed) of method SplFixedArray::setSize().',
125,
],
[
Expand Down Expand Up @@ -120,7 +120,7 @@ public function testOverridingFinalMethod(int $phpVersion, string $contravariant
280,
],
[
'Parameter #1 $index (int) of method OverridingFinalMethod\FixedArrayOffsetExists::offsetExists() is not ' . $contravariantMessage . ' with parameter #1 $offset (mixed) of method ArrayAccess<int,mixed>::offsetExists().',
'Parameter #1 $index (int) of method OverridingFinalMethod\FixedArrayOffsetExists::offsetExists() is not ' . $contravariantMessage . ' with parameter #1 $offset (mixed) of method ArrayAccess::offsetExists().',
313,
],
];
Expand Down Expand Up @@ -472,37 +472,37 @@ public function dataTentativeReturnTypes(): array
80100,
[
[
'Return type mixed of method TentativeReturnTypes\Foo::getIterator() is not covariant with tentative return type Traversable of method IteratorAggregate<mixed,mixed>::getIterator().',
'Return type mixed of method TentativeReturnTypes\Foo::getIterator() is not covariant with tentative return type Traversable of method IteratorAggregate::getIterator().',
8,
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
],
[
'Return type string of method TentativeReturnTypes\Lorem::getIterator() is not covariant with tentative return type Traversable of method IteratorAggregate<mixed,mixed>::getIterator().',
'Return type string of method TentativeReturnTypes\Lorem::getIterator() is not covariant with tentative return type Traversable of method IteratorAggregate::getIterator().',
40,
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
],
[
'Return type mixed of method TentativeReturnTypes\UntypedIterator::current() is not covariant with tentative return type mixed of method Iterator<mixed,mixed>::current().',
'Return type mixed of method TentativeReturnTypes\UntypedIterator::current() is not covariant with tentative return type mixed of method Iterator::current().',
75,
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
],
[
'Return type mixed of method TentativeReturnTypes\UntypedIterator::next() is not covariant with tentative return type void of method Iterator<mixed,mixed>::next().',
'Return type mixed of method TentativeReturnTypes\UntypedIterator::next() is not covariant with tentative return type void of method Iterator::next().',
79,
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
],
[
'Return type mixed of method TentativeReturnTypes\UntypedIterator::key() is not covariant with tentative return type mixed of method Iterator<mixed,mixed>::key().',
'Return type mixed of method TentativeReturnTypes\UntypedIterator::key() is not covariant with tentative return type mixed of method Iterator::key().',
83,
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
],
[
'Return type mixed of method TentativeReturnTypes\UntypedIterator::valid() is not covariant with tentative return type bool of method Iterator<mixed,mixed>::valid().',
'Return type mixed of method TentativeReturnTypes\UntypedIterator::valid() is not covariant with tentative return type bool of method Iterator::valid().',
87,
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
],
[
'Return type mixed of method TentativeReturnTypes\UntypedIterator::rewind() is not covariant with tentative return type void of method Iterator<mixed,mixed>::rewind().',
'Return type mixed of method TentativeReturnTypes\UntypedIterator::rewind() is not covariant with tentative return type void of method Iterator::rewind().',
91,
'Make it covariant, or use the #[\ReturnTypeWillChange] attribute to temporarily suppress the error.',
],
Expand Down

0 comments on commit 5ff0a2e

Please sign in to comment.