Process the subpackage tag.

@param   PHP_CodeSniffer_File  $phpcsFile  The file being scanned.
@param   array                 $tags       The tokens for these tags.

@return  void
509961
protected function processSubpackage(PHP_CodeSniffer_File $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'];

			// Is the subpackage included and empty.
			if (empty($content) || $content == '')
			{
				$error     = 'if included, @subpackage tag must contain a name';
				$phpcsFile->addError($error, $tag, 'EmptySubpackage');
			}
		}//end foreach
	}
903361
public function process(File $phpcsFile, $stackPointer)
    {
        $tokens       = $phpcsFile->getTokens();
        $currentToken = $tokens[$stackPointer];

        $closingParenthesisCandidate = $currentToken['parenthesis_closer'];
        $whitespaceCandidate         = $tokens[$closingParenthesisCandidate - 1];
        $linebreakCandidate          = $tokens[$closingParenthesisCandidate - 2];
        $commaCandidate              = $tokens[$closingParenthesisCandidate - 3];

        $hasClosingParenthesis = ($tokens[$closingParenthesisCandidate]['type'] === 'T_CLOSE_PARENTHESIS'
            && $whitespaceCandidate['type'] === 'T_WHITESPACE');

        $hasLinebreakBeforeClosingParenthesis = ($linebreakCandidate['type'] === 'T_WHITESPACE'
            && $linebreakCandidate['content'] === chr(10));

        $hasCommaAfterLastElement = $commaCandidate['type'] === 'T_COMMA';

        if ($hasClosingParenthesis && $hasLinebreakBeforeClosingParenthesis && !$hasCommaAfterLastElement)
        {
            $type  = 'Production.LastArrayElementComma.ArrayElementWithoutComma';
            $data  = $commaCandidate['content'];
            $error = 'Array element without comma: ' . $commaCandidate['line'];
            $phpcsFile->addWarning($error, $closingParenthesisCandidate - 3, $type, $data);
        }
    }
1344330
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsBelow('5.3') === false) {
            return;
        }

        $tokens = $phpcsFile->getTokens();
        $token  = $tokens[$stackPtr];

        $error = '%s is available since 5.4';
        $data  = array();

        if ($token['type'] === 'T_OPEN_SHORT_ARRAY') {
            $data[] = 'Short array syntax (open)';
        } elseif ($token['type'] === 'T_CLOSE_SHORT_ARRAY') {
            $data[] = 'Short array syntax (close)';
        }

        $phpcsFile->addError($error, $stackPtr, 'Found', $data);
    }
1373368
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsBelow('5.2') === false) {
            return;
        }

        $tokens = $phpcsFile->getTokens();

        // Get next non-whitespace token, and check it isn't the related inline else
        // symbol, which is not allowed prior to PHP 5.3.
        $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);

        if ($next !== false && $tokens[$next]['code'] === \T_INLINE_ELSE) {
            $phpcsFile->addError(
                'Middle may not be omitted from ternary operators in PHP < 5.3',
                $stackPtr,
                'MiddleMissing'
            );
        }
    }
802238
protected function fixOrder(File $phpCsFile, int $docBlockStartIndex, int $docBlockEndIndex, array $tags): void
    {
        $errors = [];
        foreach ($tags as $i => $tag) {
            if (isset($tag['error'])) {
                $errors[$i] = $tag['error'];
            }
        }

        if (!$errors) {
            return;
        }

        $fix = $phpCsFile->addFixableError('Invalid order of tags: ' . implode(', ', $errors), $docBlockEndIndex, 'OrderInvalid');
        if (!$fix) {
            return;
        }

        $tokens = $phpCsFile->getTokens();

        $phpCsFile->fixer->beginChangeset();

        $order = $this->getTagOrderMap();

        $newOrder = [];
        foreach ($tags as $tag) {
            $tagOrder = isset($order[$tag['tag']]) ? $order[$tag['tag']] : -1;
            $newOrder[$tagOrder][] = $this->getContent($tokens, $tag['start'], $tag['end']);
        }

        ksort($newOrder);
        if (isset($newOrder[-1])) {
            ksort($newOrder[-1]);
        }

        $content = '';
        foreach ($newOrder as $tagGroup) {
            $content .= implode('', $tagGroup);
        }

        $firstTagTokenIndex = $tags[0]['start'];
        $lastTagTokenIndex = $tags[count($tags) - 1]['end'];

        for ($i = $firstTagTokenIndex; $i < $lastTagTokenIndex; $i++) {
            $phpCsFile->fixer->replaceToken($i, '');
        }

        $phpCsFile->fixer->replaceToken($lastTagTokenIndex, $content);

        $phpCsFile->fixer->endChangeset();
    }
761027
protected function loadStatements(File $phpcsFile) {
		if ($this->existingStatements !== null) {
			return;
		}

		$existingStatements = $this->getUseStatements($phpcsFile);
		$this->existingStatements = $existingStatements;
		$this->allStatements = $existingStatements;
		$this->newStatements = [];
	}
480700
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens    = $phpcsFile->getTokens();
        $namespace = $phpcsFile->findPrevious(T_NAMESPACE, ($stackPtr - 1));

        if ($namespace === false) {
            $error = 'Each %s must be in a namespace of at least one level (a top-level vendor name)';
            $data  = array($tokens[$stackPtr]['content']);
            $phpcsFile->addError($error, $stackPtr, 'MissingNamespace', $data);
        }
    }
816276
protected function processCategory(File $phpcsFile, array $tags)
    {
        $tokens = $phpcsFile->getTokens();
        foreach ($tags as $tag) {
            if ($tokens[($tag + 2)]['code'] !== T_DOC_COMMENT_STRING) {
                // No content.
                continue;
            }

            $warning = 'The category tag is considered deprecated. It is recommended to use the @package tag instead.';

            $phpcsFile->addWarning($warning, $tag, 'CategoryDepreciated');
        }//end foreach

    }
1249191
protected function processCopyright(File $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 = array();
            if (preg_match('/^([0-9]{4})((.{1})([0-9]{4}))? (.+)$/', $content, $matches) !== 0) {
                // Check earliest-latest year order.
                if ($matches[3] !== '') {
                    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] < $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" must be "YYYY [- YYYY] Name of the copyright holder"';
                $phpcsFile->addError($error, $tag, 'IncompleteCopyright');
            }
        }//end foreach

    }
886526
public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
    {
        $tokens = $phpcsFile->getTokens();

        // We can't process SWITCH statements unless we know where they start and end.
        if ( isset( $tokens[ $stackPtr ][ 'scope_opener' ] ) === FALSE ||
            isset( $tokens[ $stackPtr ][ 'scope_closer' ] ) === FALSE
        )
        {
            return;
        }

        $switch = $tokens[ $stackPtr ];
        $nextCase = $stackPtr;
        $caseAlignment = ($switch[ 'column' ] + 4);
        $caseCount = 0;
        $foundDefault = FALSE;

        while ( ($nextCase = $phpcsFile->findNext( array( T_CASE, T_DEFAULT, T_SWITCH ),
        ($nextCase + 1 ), $switch[ 'scope_closer' ] )) !== FALSE )
        {
            // Skip nested SWITCH statements; they are handled on their own.
            if ( $tokens[ $nextCase ][ 'code' ] === T_SWITCH )
            {
                $nextCase = $tokens[ $nextCase ][ 'scope_closer' ];
                continue;
            }

            if ( $tokens[ $nextCase ][ 'code' ] === T_DEFAULT )
            {
                $type = 'Default';
                $foundDefault = TRUE;
            }
            else
            {
                $type = 'Case';
                $caseCount++;
            }

            if ( $tokens[ $nextCase ][ 'content' ] !==
                strtolower( $tokens[ $nextCase ][ 'content' ] )
            )
            {
                $expected = strtolower( $tokens[ $nextCase ][ 'content' ] );
                $error = strtoupper( $type ) .
                    ' keyword must be lowercase; expected "%s" but found "%s"';
                $data = array(
                    $expected,
                    $tokens[ $nextCase ][ 'content' ],
                );
                $phpcsFile->addError( $error, $nextCase, $type . 'NotLower',
                    $data );
            }

            if ( $tokens[ $nextCase ][ 'column' ] !== $caseAlignment )
            {
                $error = strtoupper( $type ) .
                    ' keyword must be indented 4 spaces from SWITCH keyword';
                $phpcsFile->addError( $error, $nextCase, $type . 'Indent' );
            }

            if ( $type === 'Case' && ($tokens[ ($nextCase + 1) ][ 'type' ] !== 'T_WHITESPACE'
                || $tokens[ ($nextCase + 1) ][ 'content' ] !== ' ')
            )
            {
                $error = 'CASE keyword must be followed by a single space';
                $phpcsFile->addError( $error, $nextCase, 'SpacingAfterCase' );
            }

            $opener = $tokens[ $nextCase ][ 'scope_opener' ];
            if ( $tokens[ ($opener - 1) ][ 'type' ] === 'T_WHITESPACE' )
            {
                $error = 'There must be no space before the colon in a ' .
                    strtoupper( $type ) . ' statement';
                $phpcsFile->addError( $error, $nextCase,
                    'SpaceBeforeColon' . $type );
            }

            $nextBreak = $tokens[ $nextCase ][ 'scope_closer' ];

            if ( $tokens[ $nextBreak ][ 'code' ] === T_BREAK ||
                $tokens[ $nextBreak ][ 'code' ] === T_RETURN
            )
            {
                if ( $tokens[ $nextBreak ][ 'scope_condition' ] === $nextCase )
                {
                    // Only need to check a couple of things once, even if the
                    // break is shared between multiple case statements, or even
                    // the default case.
                    $breakLine = $tokens[ $nextBreak ][ 'line' ];
                    $prevLine = 0;
                    for ( $i = ($nextBreak - 1); $i > $stackPtr; $i-- )
                    {
                        if ( $tokens[ $i ][ 'type' ] !== 'T_WHITESPACE' )
                        {
                            $prevLine = $tokens[ $i ][ 'line' ];
                            break;
                        }
                    }

                    $breakLine = $tokens[ $nextBreak ][ 'line' ];
                    $nextLine = $tokens[ $tokens[ $stackPtr ][ 'scope_closer' ] ][ 'line' ];
                    $semicolon = $phpcsFile->findNext( T_SEMICOLON, $nextBreak );
                    for ( $i = ($semicolon + 1);
                            $i < $tokens[ $stackPtr ][ 'scope_closer' ]; $i++ )
                    {
                        if ( $tokens[ $i ][ 'type' ] !== 'T_WHITESPACE' )
                        {
                            $nextLine = $tokens[ $i ][ 'line' ];
                            break;
                        }
                    }

                    if ( $type === 'Case' )
                    {
                        // Ensure the BREAK statement is followed by
                        // a single blank line, or the end switch brace.
                        if ( $nextLine !== ($breakLine + 2) && $i !== 
                            $tokens[ $stackPtr ][ 'scope_closer' ]
                            )
                        {
                            $error = 'Case breaking statements must be ';
                            $error .= 'followed by a single blank line';
                            $phpcsFile->addError( $error, $nextBreak,
                                'SpacingAfterBreak' );
                        }
                    }
                    else
                    {
                        // Ensure the BREAK statement is not followed by a blank line.
                        if ( $nextLine !== ($breakLine + 1) )
                        {
                            $error = 'Blank lines are not allowed after the ';
                            $error .= 'DEFAULT case\'s breaking statement';
                            $phpcsFile->addError( $error, $nextBreak,
                                'SpacingAfterDefaultBreak' );
                        }
                    }

                    $caseLine = $tokens[ $nextCase ][ 'line' ];
                    $nextLine = $tokens[ $nextBreak ][ 'line' ];
                    for ( $i = ($opener + 1); $i < $nextBreak; $i++ )
                    {
                        if ( $tokens[ $i ][ 'type' ] !== 'T_WHITESPACE' )
                        {
                            $nextLine = $tokens[ $i ][ 'line' ];
                            break;
                        }
                    }

                    if ( $nextLine !== ($caseLine + 1) )
                    {
                        $error = 'Blank lines are not allowed after ' . strtoupper( $type ) . ' statements';
                        $phpcsFile->addError( $error, $nextCase,
                            'SpacingAfter' . $type );
                    }
                }

                if ( $tokens[ $nextBreak ][ 'code' ] === T_BREAK )
                {
                    if ( $type === 'Case' )
                    {
                        // Ensure empty CASE statements are not allowed.
                        // They must have some code content in them. A comment is not enough.
                        // But count RETURN statements as valid content if they also
                        // happen to close the CASE statement.
                        $foundContent = FALSE;
                        for ( $i = ($tokens[ $nextCase ][ 'scope_opener' ] + 1);
                                $i < $nextBreak; $i++ )
                        {
                            if ( $tokens[ $i ][ 'code' ] === T_CASE )
                            {
                                $i = $tokens[ $i ][ 'scope_opener' ];
                                continue;
                            }

                            if ( in_array( $tokens[ $i ][ 'code' ],
                                    PHP_CodeSniffer_Tokens::$emptyTokens ) === FALSE )
                            {
                                $foundContent = TRUE;
                                break;
                            }
                        }

                        if ( $foundContent === FALSE )
                        {
                            $error = 'Empty CASE statements are not allowed';
                            $phpcsFile->addError( $error, $nextCase, 'EmptyCase' );
                        }
                    }
                    else
                    {
                        // Ensure empty DEFAULT statements are not allowed.
                        // They must (at least) have a comment describing why
                        // the default case is being ignored.
                        $foundContent = FALSE;
                        for ( $i = ($tokens[ $nextCase ][ 'scope_opener' ] + 1);
                                $i < $nextBreak; $i++ )
                        {
                            if ( $tokens[ $i ][ 'type' ] !== 'T_WHITESPACE' )
                            {
                                $foundContent = TRUE;
                                break;
                            }
                        }

                        if ( $foundContent === FALSE )
                        {
                            $error = 'Comment required for empty DEFAULT case';
                            $phpcsFile->addError( $error, $nextCase,
                                'EmptyDefault' );
                        }
                    }
                }
            }
            else if ( $type === 'Default' )
            {
                $error = 'DEFAULT case must have a breaking statement';
                $phpcsFile->addError( $error, $nextCase, 'DefaultNoBreak' );
            }
        }

        if ( $foundDefault === FALSE )
        {
            $error = 'All SWITCH statements must contain a DEFAULT case';
            $phpcsFile->addError( $error, $stackPtr, 'MissingDefault' );
        }

        if ( $tokens[ $switch[ 'scope_closer' ] ][ 'column' ] !== $switch[ 'column' ] )
        {
            $error = 'Closing brace of SWITCH statement must be aligned with SWITCH keyword';
            $phpcsFile->addError( $error, $switch[ 'scope_closer' ],
                'CloseBraceAlign' );
        }

        if ( $caseCount === 0 )
        {
            $error = 'SWITCH statements must contain at least one CASE statement';
            $phpcsFile->addError( $error, $stackPtr, 'MissingCase' );
        }
    }
800374
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $content = $tokens[$stackPtr]['content'];
        if (in_array(strtolower($content), self::$disallowedFunctionNames)) {
            //Checking previous token as it could be a static method or object method
            $previousTokenPtr = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr - 1, null, true);
            if (!is_null($previousTokenPtr)) {
                switch($tokens[$previousTokenPtr]['code']) {
                    case T_OBJECT_OPERATOR:
                    case T_DOUBLE_COLON:
                        return;
                }
            }
            $error = 'Disallowed function "%s" was called';
            $data = array($content);
            $phpcsFile->addError($error, $stackPtr, 'DisallowedFunctionCalled', $data);
        }
    }
353296
public function process(File $phpcsFile, $stackPointer)
    {
        $tokens = $phpcsFile->getTokens();
        if ($tokens[$stackPointer + 1]['type'] === self::WANTED_TOKEN)
        {
            return;
        }
        $type  = 'Production.WhitespaceAfterControlStructure.NoWhitespaceAfterControlStructure';
        $data  = [$tokens[$stackPointer]['content']];
        $error = 'There must be a whitespace after ' . $tokens[$stackPointer]['content'] . '.';
        $phpcsFile->addWarning($error, $stackPointer, $type, $data);
    }
1305612
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        if ($tokens[$stackPtr -1]['code'] !== T_WHITESPACE
            || $tokens[$stackPtr +1]['code'] !== T_WHITESPACE
        ) {
            $fix = $phpcsFile->addFixableError(
                'Add a single space around binary operators',
                $stackPtr,
                'Invalid'
            );

            if ($fix === true) {
                if ($tokens[$stackPtr -1]['code'] !== T_WHITESPACE) {
                    $phpcsFile->fixer->addContentBefore($stackPtr, " ");
                }

                if ($tokens[$stackPtr +1]['code'] !== T_WHITESPACE) {
                    $phpcsFile->fixer->addContent($stackPtr, " ");
                }
            }
        }
    }
107733
protected function processCopyright(File $phpcs_file, array $tags): void
    {
        $tokens = $phpcs_file->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('/^(\d{4})((.{1})(\d{4}|present))? (.+)$/', $content, $matches) === 0) {
                $error = '@copyright tag must contain a year and the name of the copyright holder';
                $phpcs_file->addError($error, $tag, 'IncompleteCopyright');
                continue;
            }

            // Check earliest-latest year order.
            if (! ($matches[3] ?? false)) {
                continue;
            }

            if ($matches[3] !== '-') {
                $error = 'A hyphen must be used between the earliest and latest year';
                $phpcs_file->addError($error, $tag, 'CopyrightHyphen');
            }

            if (\is_int($matches[4] ?? '') && $matches[4] < $matches[1]) {
                $error = sprintf(
                    'Invalid year span "%s%s%s" found; consider "%s%s" instead',
                    $matches[1],
                    $matches[3],
                    $matches[4],
                    $matches[4],
                    $matches[1]
                );

                $phpcs_file->addWarning($error, $tag, 'InvalidCopyright');
            }
        }
    }
268363
protected function fixDocCommentCloseTags(File $phpCsFile, int $index): void
    {
        $tokens = $phpCsFile->getTokens();

        $content = $tokens[$index]['content'];
        if ($content === '*/') {
            return;
        }

        $fix = $phpCsFile->addFixableError('Inline Doc Block comment end tag should be `*/`, got `' . $content . '`', $index, 'EndTag');
        if (!$fix) {
            return;
        }

        $phpCsFile->fixer->beginChangeset();

        $phpCsFile->fixer->replaceToken($index, '*/');

        $phpCsFile->fixer->endChangeset();
    }
518384
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        if ($this->supportsAbove('5.4')) {
            $tokens = $phpcsFile->getTokens();
            $nextSemicolonToken = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr), null, false);
            for ($curToken = $stackPtr + 1; $curToken < $nextSemicolonToken; $curToken++) {
                $gotError = false;
                if ($tokens[$curToken]['type'] == 'T_STRING') {
                    // If the next non-whitespace token after the string
                    // is an opening parenthesis then it's a function call.
                    $openBracket = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $curToken + 1, null, true);
                    if ($tokens[$openBracket]['code'] !== T_OPEN_PARENTHESIS) {
                        continue;
                    } else {
                        $gotError = true;
                    }
                }
                switch ($tokens[$curToken]['type']) {
                    case 'T_VARIABLE':
                    case 'T_FUNCTION':
                        $gotError = true;
                        break;
                }
                if ($gotError === true) {
                    $error = 'Using a variable argument on break or continue is forbidden since PHP 5.4';
                    $phpcsFile->addError($error, $stackPtr);
                }
            }
        }
    }
1213881
public function process(File $phpcsFile, $stackPointer)
    {
        $this->file      = $phpcsFile;
        $tokens          = $phpcsFile->getTokens();
        $type            = $tokens[$stackPointer]['type'];
        $commentContext  = $tokens[$stackPointer]['content'];
        $isAtStartOfLine = $tokens[$stackPointer]['column'] === 1;

        if (($type === 'T_USE') && $isAtStartOfLine)
        {
            $this->collectUsedNamespace($tokens, $stackPointer);
        }
        elseif ($type === 'T_DOC_COMMENT_TAG' && in_array($commentContext, $this->wantedAnnotations, true))
        {
            $this->findFullyQualifiedNameSpaceInDocBlock($tokens, $stackPointer, $commentContext);
        }
    }