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

Breadcrumb

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

function ClassMethodCoversExistsRule::processNode

File

vendor/phpstan/phpstan-phpunit/src/Rules/PHPUnit/ClassMethodCoversExistsRule.php, line 53

Class

ClassMethodCoversExistsRule
@implements Rule<Node\Stmt\ClassMethod>

Namespace

PHPStan\Rules\PHPUnit

Code

public function processNode(Node $node, Scope $scope) : array {
    $classReflection = $scope->getClassReflection();
    if ($classReflection === null) {
        return [];
    }
    if (!$classReflection->isSubclassOf(TestCase::class)) {
        return [];
    }
    $classPhpDoc = $classReflection->getResolvedPhpDoc();
    [
        $classCovers,
        $classCoversDefaultClasses,
    ] = $this->coversHelper
        ->getCoverAnnotations($classPhpDoc);
    $classCoversStrings = array_map(static function (PhpDocTagNode $covers) : string {
        return (string) $covers->value;
    }, $classCovers);
    $docComment = $node->getDocComment();
    if ($docComment === null) {
        return [];
    }
    $coversDefaultClass = count($classCoversDefaultClasses) === 1 ? array_shift($classCoversDefaultClasses) : null;
    $methodPhpDoc = $this->fileTypeMapper
        ->getResolvedPhpDoc($scope->getFile(), $classReflection->getName(), $scope->isInTrait() ? $scope->getTraitReflection()
        ->getName() : null, $node->name
        ->toString(), $docComment->getText());
    [
        $methodCovers,
        $methodCoversDefaultClasses,
    ] = $this->coversHelper
        ->getCoverAnnotations($methodPhpDoc);
    $errors = [];
    if (count($methodCoversDefaultClasses) > 0) {
        $errors[] = RuleErrorBuilder::message(sprintf('@coversDefaultClass defined on class method %s.', $node->name))
            ->identifier('phpunit.covers')
            ->build();
    }
    foreach ($methodCovers as $covers) {
        if (in_array((string) $covers->value, $classCoversStrings, true)) {
            $errors[] = RuleErrorBuilder::message(sprintf('Class already @covers %s so the method @covers is redundant.', $covers->value))
                ->identifier('phpunit.coversDuplicate')
                ->build();
        }
        $errors = array_merge($errors, $this->coversHelper
            ->processCovers($node, $covers, $coversDefaultClass));
    }
    return $errors;
}

API Navigation

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