Skip to content

Commit

Permalink
OverridingMethodRule - RuleErrorBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jun 4, 2020
1 parent 406b5e4 commit 093ae3f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/Rules/Methods/OverridingMethodRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PHPStan\Reflection\MethodPrototypeReflection;
use PHPStan\Reflection\Php\PhpMethodFromParserNodeReflection;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;

/**
* @implements Rule<InClassMethodNode>
Expand Down Expand Up @@ -37,35 +38,35 @@ public function processNode(Node $node, Scope $scope): array

$messages = [];
if ($prototype->isFinal()) {
$messages[] = sprintf(
$messages[] = RuleErrorBuilder::message(sprintf(
'Method %s::%s() overrides final method %s::%s().',
$method->getDeclaringClass()->getName(),
$method->getName(),
$prototype->getDeclaringClass()->getName(),
$prototype->getName()
);
))->nonIgnorable()->build();
}

if ($prototype->isPublic()) {
if (!$method->isPublic()) {
$messages[] = sprintf(
$messages[] = RuleErrorBuilder::message(sprintf(
'%s method %s::%s() overriding public method %s::%s() should also be public.',
$method->isPrivate() ? 'Private' : 'Protected',
$method->getDeclaringClass()->getName(),
$method->getName(),
$prototype->getDeclaringClass()->getName(),
$prototype->getName()
);
))->nonIgnorable()->build();
}
} else {
if ($method->isPrivate()) {
$messages[] = sprintf(
$messages[] = RuleErrorBuilder::message(sprintf(
'Private method %s::%s() overriding protected method %s::%s() should be protected or public.',
$method->getDeclaringClass()->getName(),
$method->getName(),
$prototype->getDeclaringClass()->getName(),
$prototype->getName()
);
))->nonIgnorable()->build();
}
}

Expand Down

0 comments on commit 093ae3f

Please sign in to comment.