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

Breadcrumb

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

class AnnotationHelper

Same name in this branch
  1. 11.1.x vendor/slevomat/coding-standard/SlevomatCodingStandard/Helpers/AnnotationHelper.php \SlevomatCodingStandard\Helpers\AnnotationHelper

Hierarchy

  • class \PHPStan\Rules\PHPUnit\AnnotationHelper

Expanded class hierarchy of AnnotationHelper

File

vendor/phpstan/phpstan-phpunit/src/Rules/PHPUnit/AnnotationHelper.php, line 13

Namespace

PHPStan\Rules\PHPUnit
View source
class AnnotationHelper {
    private const ANNOTATIONS_WITH_PARAMS = [
        'backupGlobals',
        'backupStaticAttributes',
        'covers',
        'coversDefaultClass',
        'dataProvider',
        'depends',
        'group',
        'preserveGlobalState',
        'requires',
        'testDox',
        'testWith',
        'ticket',
        'uses',
    ];
    
    /**
     * @return list<IdentifierRuleError> errors
     */
    public function processDocComment(Doc $docComment) : array {
        $errors = [];
        $docCommentLines = preg_split("/((\r?\n)|(\r\n?))/", $docComment->getText());
        if ($docCommentLines === false) {
            return [];
        }
        foreach ($docCommentLines as $docCommentLine) {
            // These annotations can't be retrieved using the getResolvedPhpDoc method on the FileTypeMapper as they are not present when they are invalid
            $annotation = preg_match('/(?<annotation>@(?<property>[a-zA-Z]+)(?<whitespace>\\s*)(?<value>.*))/', $docCommentLine, $matches);
            if ($annotation === false) {
                continue;
                // Line without annotation
            }
            if (array_key_exists('property', $matches) === false || array_key_exists('whitespace', $matches) === false || array_key_exists('annotation', $matches) === false) {
                continue;
            }
            if (!in_array($matches['property'], self::ANNOTATIONS_WITH_PARAMS, true) || $matches['whitespace'] !== '') {
                continue;
            }
            $errors[] = RuleErrorBuilder::message('Annotation "' . $matches['annotation'] . '" is invalid, "@' . $matches['property'] . '" should be followed by a space and a value.')->identifier('phpunit.invalidPhpDoc')
                ->build();
        }
        return $errors;
    }

}

Members

Title Sort descending Modifiers Object type Summary
AnnotationHelper::ANNOTATIONS_WITH_PARAMS private constant
AnnotationHelper::processDocComment public function *

API Navigation

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