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

Breadcrumb

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

function FileCommentSniff::processCopyright

Process the copyright tags.

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 489

Class

FileCommentSniff

Namespace

PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting

Code

protected function processCopyright($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'];
        $matches = [];
        if (preg_match('/^([0-9]{4})((.{1})([0-9]{4}))? (.+)$/', $content, $matches) !== 0) {
            // Check earliest-latest year order.
            if ($matches[3] !== '' && $matches[3] !== null) {
                if ($matches[3] !== '-') {
                    $error = 'A hyphen must be used between the earliest and latest year';
                    $phpcsFile->addError($error, $tag, 'CopyrightHyphen');
                }
                if ($matches[4] !== '' && $matches[4] !== null && $matches[4] < $matches[1]) {
                    $error = "Invalid year span \"{$matches[1]}{$matches[3]}{$matches[4]}\" found; consider \"{$matches[4]}-{$matches[1]}\" instead";
                    $phpcsFile->addWarning($error, $tag, 'InvalidCopyright');
                }
            }
        }
        else {
            $error = '@copyright tag must contain a year and the name of the copyright holder';
            $phpcsFile->addError($error, $tag, 'IncompleteCopyright');
        }
    }
    
    //end foreach
}
RSS feed
Powered by Drupal