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

Breadcrumb

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

function FileCommentSniff::processPackage

Process the package tag.

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 362

Class

FileCommentSniff

Namespace

PHP_CodeSniffer\Standards\PEAR\Sniffs\Commenting

Code

protected function processPackage($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'];
        if (Common::isUnderscoreName($content) === true) {
            continue;
        }
        $newContent = str_replace(' ', '_', $content);
        $newContent = trim($newContent, '_');
        $newContent = preg_replace('/[^A-Za-z_]/', '', $newContent);
        if ($newContent === '') {
            $error = 'Package name "%s" is not valid';
            $data = [
                $content,
            ];
            $phpcsFile->addError($error, $tag, 'InvalidPackageValue', $data);
        }
        else {
            $nameBits = explode('_', $newContent);
            $firstBit = array_shift($nameBits);
            $newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . '_';
            foreach ($nameBits as $bit) {
                if ($bit !== '') {
                    $newName .= strtoupper($bit[0]) . substr($bit, 1) . '_';
                }
            }
            $error = 'Package name "%s" is not valid; consider "%s" instead';
            $validName = trim($newName, '_');
            $data = [
                $content,
                $validName,
            ];
            $phpcsFile->addError($error, $tag, 'InvalidPackage', $data);
        }
        
        //end if
    }
    
    //end foreach
}
RSS feed
Powered by Drupal