Skip to content

Commit

Permalink
Fix @phpstan-self-out error message
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Aug 23, 2024
1 parent 6838669 commit 04e5009
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Rules/FunctionDefinitionCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ public function checkClassMethod(
string $templateTypeMissingInParameterMessage,
string $unresolvableParameterTypeMessage,
string $unresolvableReturnTypeMessage,
string $selfOutMessage,
): array
{
/** @var ParametersAcceptorWithPhpDocs $parametersAcceptor */
Expand All @@ -263,7 +264,7 @@ public function checkClassMethod(

foreach ($selfOutTypeReferencedClasses as $class) {
if (!$this->reflectionProvider->hasClass($class)) {
$errors[] = RuleErrorBuilder::message(sprintf($returnMessage, $class))
$errors[] = RuleErrorBuilder::message(sprintf($selfOutMessage, $class))
->line($methodNode->getStartLine())
->identifier('class.notFound')
->build();
Expand All @@ -273,7 +274,7 @@ public function checkClassMethod(
continue;
}

$errors[] = RuleErrorBuilder::message(sprintf($returnMessage, $class))
$errors[] = RuleErrorBuilder::message(sprintf($selfOutMessage, $class))
->line($methodNode->getStartLine())
->identifier('selfOut.trait')
->build();
Expand Down
5 changes: 5 additions & 0 deletions src/Rules/Methods/ExistingClassesInTypehintsRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ public function processNode(Node $node, Scope $scope): array
$className,
$methodName,
),
sprintf(
'Method %s::%s() has invalid @phpstan-self-out type %%s.',
$className,
$methodName,
),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,11 +512,11 @@ public function testSelfOut(): void
{
$this->analyse([__DIR__ . '/data/self-out.php'], [
[
'Method SelfOutClasses\Foo::doFoo() has invalid return type SelfOutClasses\Nonexistent.',
'Method SelfOutClasses\Foo::doFoo() has invalid @phpstan-self-out type SelfOutClasses\Nonexistent.',
16,
],
[
'Method SelfOutClasses\Foo::doBar() has invalid return type SelfOutClasses\FooTrait.',
'Method SelfOutClasses\Foo::doBar() has invalid @phpstan-self-out type SelfOutClasses\FooTrait.',
24,
],
[
Expand Down

0 comments on commit 04e5009

Please sign in to comment.