function ShouldCallParentMethodsRule::processNode
File
-
vendor/
phpstan/ phpstan-phpunit/ src/ Rules/ PHPUnit/ ShouldCallParentMethodsRule.php, line 26
Class
- ShouldCallParentMethodsRule
- @implements Rule<InClassMethodNode>
Namespace
PHPStan\Rules\PHPUnitCode
public function processNode(Node $node, Scope $scope) : array {
$methodName = $node->getOriginalNode()->name->name;
if (!in_array(strtolower($methodName), [
'setup',
'teardown',
], true)) {
return [];
}
if ($scope->getClassReflection() === null) {
return [];
}
if (!$scope->getClassReflection()
->isSubclassOf(TestCase::class)) {
return [];
}
$parentClass = $scope->getClassReflection()
->getParentClass();
if ($parentClass === null) {
return [];
}
if (!$parentClass->hasNativeMethod($methodName)) {
return [];
}
$parentMethod = $parentClass->getNativeMethod($methodName);
if ($parentMethod->getDeclaringClass()
->getName() === TestCase::class) {
return [];
}
$hasParentCall = $this->hasParentClassCall($node->getOriginalNode()
->getStmts(), strtolower($methodName));
if (!$hasParentCall) {
return [
RuleErrorBuilder::message(sprintf('Missing call to parent::%s() method.', $methodName))->identifier('phpunit.callParent')
->build(),
];
}
return [];
}