Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ShouldCallParentMethodsRule.php

function ShouldCallParentMethodsRule::processNode

File

vendor/phpstan/phpstan-phpunit/src/Rules/PHPUnit/ShouldCallParentMethodsRule.php, line 26

Class

ShouldCallParentMethodsRule
@implements Rule<InClassMethodNode>

Namespace

PHPStan\Rules\PHPUnit

Code

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 [];
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal