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

Breadcrumb

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

function FileCommentSniff::processAuthor

Process the author tag(s) that this header comment has.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

array $tags The tokens for these tags.:

Return value

void

File

vendor/squizlabs/php_codesniffer/src/Standards/PEAR/Sniffs/Commenting/FileCommentSniff.php, line 459

Class

FileCommentSniff

Namespace

PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting

Code

protected function processAuthor($phpcsFile, array $tags) {
    $tokens = $phpcsFile->getTokens();
    foreach ($tags as $tag) {
        if ($tokens[$tag + 2]['code'] !== T_DOC_COMMENT_STRING) {
            // No content.
            continue;
        }
        $content = $tokens[$tag + 2]['content'];
        $local = '\\da-zA-Z-_+';
        // Dot character cannot be the first or last character in the local-part.
        $localMiddle = $local . '.\\w';
        if (preg_match('/^([^<]*)\\s+<([' . $local . ']([' . $localMiddle . ']*[' . $local . '])*@[\\da-zA-Z][-.\\w]*[\\da-zA-Z]\\.[a-zA-Z]{2,})>$/', $content) === 0) {
            $error = 'Content of the @author tag must be in the form "Display Name <username@example.com>"';
            $phpcsFile->addError($error, $tag, 'InvalidAuthors');
        }
    }
}
RSS feed
Powered by Drupal