vendor/PHPCS/CodingStandard/MeiLiBo/Sniffs/Commenting/FileCommentSniff.php
/**
     * Processes each required or optional tag.
     *
     * @param int $commentStart The position in the stack where the comment started.
     * @param int $commentEnd   The position in the stack where the comment ended.
     *
     * @return void
     */
Processes each required or optional tag.
@param int $commentStart The position in the stack where the comment started.
@param int $commentEnd   The position in the stack where the comment ended.

@return void
Processes each required or optional tag . @param int $commentStart The position in the stack where the comment started . @param int $commentEnd The position in the stack where the comment ended . @return void
protected function processTags($commentStart, $commentEnd)
    {
        $tags = array(
                 'package'    => 'precedes @subpackage',
                 'subpackage' => 'follows @package',
                 'author'     => 'follows @subpackage',
                 'copyright'  => 'follows @author',
                 'license'    => 'follows @copyright',
                );
        $requiredTag = array(
                'author'
            );
        $foundTags   = $this->commentParser->getTagOrders();
        $errorPos    = 0;
        $orderIndex  = 0;
        $longestTag  = 0;
        $indentation = array();
        foreach ($tags as $tag => $orderText) {
            if (in_array($tag, $foundTags) === false && in_array($tag, $requiredTag)) {
                $error = 'Missing @%s tag in file comment';
                $data  = array($tag);
                $this->currentFile->addError($error, $commentEnd, 'Missing'.ucfirst($tag).'Tag', $data);
                continue;
            }
            $tagName = ucfirst($tag);
            if ($tagName === 'Author' || $tagName === 'Copyright') {
                $tagName .= 's';
            }
            $getMethod  = 'get'.$tagName;
            $tagElement = $this->commentParser->$getMethod();
            if (is_null($tagElement) === true || empty($tagElement) === true) {
                continue;
            } else if (is_array($tagElement) === true && empty($tagElement) === false) {
                $tagElement = $tagElement[0];
            }
            $errorPos = ($commentStart + $tagElement->getLine());
            $foundIndexes = array_keys($foundTags, $tag);
            if (count($foundIndexes) > 1) {
                $error = 'Only 1 @%s tag is allowed in file comment';
                $data  = array($tag);
                $this->currentFile->addError($error, $errorPos, 'Duplicate'.ucfirst($tag).'Tag', $data);
            }
            if ($foundIndexes[0] > $orderIndex) {
                $orderIndex = $foundIndexes[0];
            } else {
                $error = 'The @%s tag is in the wrong order; the tag %s';
                $data  = array(
                          $tag,
                          $orderText,
                         );
                $this->currentFile->addError($error, $errorPos, ucfirst($tag).'TagOrder', $data);
            }
            $len = strlen($tag);
            if ($len > $longestTag) {
                $longestTag = $len;
            }
            $indentation[] = array(
                              'tag'      => $tag,
                              'errorPos' => $errorPos,
                              'space'    => $this->getIndentation($tag, $tagElement),
                             );
            $method = 'process'.$tagName;
            if (method_exists($this, $method) === true) {
                call_user_func(array($this, $method), $errorPos);
            } else {
                $tagElement->process($this->currentFile, $commentStart, 'file');
            }
        }
        foreach ($indentation as $indentInfo) {
            $tagName = ucfirst($indentInfo['tag']);
            if ($tagName === 'Author') {
                $tagName .= 's';
            }
            if ($indentInfo['space'] !== 0 && $indentInfo['space'] !== ($longestTag + 1)) {
                $expected = ($longestTag - strlen($indentInfo['tag']) + 1);
                $space    = ($indentInfo['space'] - strlen($indentInfo['tag']));
                $error    = '@%s tag comment indented incorrectly; expected %s spaces but found %s';
                $data     = array(
                             $indentInfo['tag'],
                             $expected,
                             $space,
                            );
                $this->currentFile->addError($error, $indentInfo['errorPos'], ucfirst($indentInfo['tag']).'TagIndent', $data);
            }
        }
    }
protected function processTags ( $ commentStart , $ commentEnd ) { $ tags = array ( 'package' => 'precedes @subpackage' , 'subpackage' => 'follows @package' , 'author' => 'follows @subpackage' , 'copyright' => 'follows @author' , 'license' => 'follows @copyright' , ) ; $ requiredTag = array ( 'author' ) ; $ foundTags = $ this -> commentParser -> getTagOrders ( ) ; $ errorPos = 0 ; $ orderIndex = 0 ; $ longestTag = 0 ; $ indentation = array ( ) ; foreach ( $ tags as $ tag => $ orderText ) { if ( in_array ( $ tag , $ foundTags ) === false && in_array ( $ tag , $ requiredTag ) ) { $ error = 'Missing @%s tag in file comment' ; $ data = array ( $ tag ) ; $ this -> currentFile -> addError ( $ error , $ commentEnd , 'Missing' . ucfirst ( $ tag ) . 'Tag' , $ data ) ; continue ; } $ tagName = ucfirst ( $ tag ) ; if ( $ tagName === 'Author' || $ tagName === 'Copyright' ) { $ tagName .= 's' ; } $ getMethod = 'get' . $ tagName ; $ tagElement = $ this -> commentParser -> $ getMethod ( ) ; if ( is_null ( $ tagElement ) === true || empty ( $ tagElement ) === true ) { continue ; } else if ( is_array ( $ tagElement ) === true && empty ( $ tagElement ) === false ) { $ tagElement = $ tagElement [ 0 ] ; } $ errorPos = ( $ commentStart + $ tagElement -> getLine ( ) ) ; $ foundIndexes = array_keys ( $ foundTags , $ tag ) ; if ( count ( $ foundIndexes ) > 1 ) { $ error = 'Only 1 @%s tag is allowed in file comment' ; $ data = array ( $ tag ) ; $ this -> currentFile -> addError ( $ error , $ errorPos , 'Duplicate' . ucfirst ( $ tag ) . 'Tag' , $ data ) ; } if ( $ foundIndexes [ 0 ] > $ orderIndex ) { $ orderIndex = $ foundIndexes [ 0 ] ; } else { $ error = 'The @%s tag is in the wrong order; the tag %s' ; $ data = array ( $ tag , $ orderText , ) ; $ this -> currentFile -> addError ( $ error , $ errorPos , ucfirst ( $ tag ) . 'TagOrder' , $ data ) ; } $ len = strlen ( $ tag ) ; if ( $ len > $ longestTag ) { $ longestTag = $ len ; } $ indentation [ ] = array ( 'tag' => $ tag , 'errorPos' => $ errorPos , 'space' => $ this -> getIndentation ( $ tag , $ tagElement ) , ) ; $ method = 'process' . $ tagName ; if ( method_exists ( $ this , $ method ) === true ) { call_user_func ( array ( $ this , $ method ) , $ errorPos ) ; } else { $ tagElement -> process ( $ this -> currentFile , $ commentStart , 'file' ) ; } } foreach ( $ indentation as $ indentInfo ) { $ tagName = ucfirst ( $ indentInfo [ 'tag' ] ) ; if ( $ tagName === 'Author' ) { $ tagName .= 's' ; } if ( $ indentInfo [ 'space' ] !== 0 && $ indentInfo [ 'space' ] !== ( $ longestTag + 1 ) ) { $ expected = ( $ longestTag - strlen ( $ indentInfo [ 'tag' ] ) + 1 ) ; $ space = ( $ indentInfo [ 'space' ] - strlen ( $ indentInfo [ 'tag' ] ) ) ; $ error = '@%s tag comment indented incorrectly; expected %s spaces but found %s' ; $ data = array ( $ indentInfo [ 'tag' ] , $ expected , $ space , ) ; $ this -> currentFile -> addError ( $ error , $ indentInfo [ 'errorPos' ] , ucfirst ( $ indentInfo [ 'tag' ] ) . 'TagIndent' , $ data ) ; } } }
Processes each required or optional tag.
Processes each required or optional tag .
// Required tags in correct order. // Required tag missing. // Get the line number for current tag. // These tags are different because they return an array. // Work out the line number for this tag. // Make sure there is no duplicate tag. // Check tag order. // Store the indentation of each tag. // Process each tag if a method is defined. //end foreach // Check tag indentation.