Processes this test, when one of its tokens is encountered.

@param File $phpcsFile The file being scanned.
@param int  $stackPtr  The position of the current token in the
stack passed in $tokens.

@return void
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);
        }
    }
568017
public function process( PHP_CodeSniffer_File $phpcsFile, $stackPtr )
    {
        $tokens = $phpcsFile->getTokens();

        switch ($tokens[ $stackPtr ][ 'type' ])
        {
            case T_IF:
            case T_ELSEIF:
            case T_SWITCH:
            case T_WHILE:
            case T_FOR:
            case T_FOREACH:
            case T_OPEN_PARENTHESIS:
                if ( $tokens[ $stackPtr + 1 ][ 'type' ] !== T_WHITESPACE &&
                    ($tokens[ $stackPtr + 1 ][ 'content' ] !== '\n' && $tokens[ $stackPtr
                    + 1 ] !== T_CLOSE_PARENTHESIS) )
                {
                    $error = 'Need a space after the opening parentheses';
                    $phpcsFile->addError( $error, $stackPtr );
                }
                break;

            case T_CLOSE_PARENTHESIS:
                if ( $tokens[ $stackPtr - 1 ][ 'content' ] != ' ' )
                {
                    $error = 'Need a space before the closing parentheses';
                    $phpcsFile->addError( $error, $stackPtr );
                }
                break;
            default:
                break;
        }
    }
746937
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens            = $phpcsFile->getTokens();
        $declarationEndPtr = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1));

        $nextCodePtr = $phpcsFile->findNext(
            T_WHITESPACE,
            ($declarationEndPtr + 1),
            null,
            true
        );

        if ($nextCodePtr === false) {
            return;
        }

        $diff = ($tokens[$nextCodePtr]['line'] - $tokens[$declarationEndPtr]['line'] - 1);

        if ($diff === $this->emptyLineCount) {
            return;
        }

        if ($diff < 0) {
            $diff = 0;
        }

        $data  = array($diff);
        $error = 'Expected '.$this->emptyLineCount.' blank line(-s) after namespace declaration; %s found';
        $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'BlankLineAfter', $data);

        if ($fix === false) {
            return;
        }

        $phpcsFile->fixer->beginChangeset();

        if ($diff > 0) {
            for ($j = ($declarationEndPtr + 1); $j < $nextCodePtr; $j++) {
                if ($tokens[$j]['line'] === $tokens[$nextCodePtr]['line']) {
                    // Keep existing indentation.
                    break;
                }

                $phpcsFile->fixer->replaceToken($j, '');
            }
        }

        for ($i = 0; $i <= $this->emptyLineCount; $i++) {
            $phpcsFile->fixer->addNewline($declarationEndPtr);
        }

        $phpcsFile->fixer->endChangeset();
    }
1193267
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $token  = $tokens[$stackPtr];

        // Check if the break/continue is within a valid loop structure.
        if (empty($token['conditions']) === false) {
            foreach ($token['conditions'] as $tokenCode) {
                if (isset($this->validLoopStructures[$tokenCode]) === true) {
                    return;
                }
            }
        } else {
            // Deal with older PHPCS versions.
            if (isset($token['scope_condition']) === true && isset($this->backCompat[$tokens[$token['scope_condition']]['code']]) === true) {
                return;
            }
        }

        // If we're still here, no valid loop structure container has been found, so throw an error.
        $error     = "Using '%s' outside of a loop or switch structure is invalid";
        $isError   = false;
        $errorCode = 'Found';
        $data      = array($token['content']);

        if ($this->supportsAbove('7.0')) {
            $error    .= ' and will throw a fatal error since PHP 7.0';
            $isError   = true;
            $errorCode = 'FatalError';
        }

        $this->addMessage($phpcsFile, $error, $stackPtr, $isError, $errorCode, $data);
    }
1027724
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsAbove('7.2') === false) {
            return;
        }

        $funcName = $phpcsFile->getDeclarationName($stackPtr);

        if (strtolower($funcName) !== '__autoload') {
            return;
        }

        if ($this->validDirectScope($phpcsFile, $stackPtr, $this->checkForScopes) !== false) {
            return;
        }

        if ($this->determineNamespace($phpcsFile, $stackPtr) !== '') {
            return;
        }

        $phpcsFile->addWarning('Use of __autoload() function is deprecated since PHP 7.2', $stackPtr, 'Found');
    }
173483
public function process(File $phpcsFile, $stackPtr)
	{
		// We want all the errors from the PEAR standard, plus some of our own.
		parent::process($phpcsFile, $stackPtr);

		// Just in case.
		$tokens = $phpcsFile->getTokens();
		if (isset($tokens[$stackPtr]['scope_opener']) === false) {
			return;
		}

		$this->processOpen($phpcsFile, $stackPtr);
	}
881658
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens    = $phpcsFile->getTokens();
        $prevToken = $phpcsFile->findPrevious(
            Tokens::$emptyTokens,
            ($stackPtr - 1),
            null,
            true
        );

        $expectedBlankLineCount = 1;
        $leadingLinePtr         = $this->getLeadingLinePointer($phpcsFile, $stackPtr, $prevToken);
        $blankLineCount         = ($tokens[$leadingLinePtr]['line'] - ($tokens[$prevToken]['line'] + 1));

        if (isset($tokens[$prevToken]['scope_opener']) === true && $tokens[$prevToken]['scope_opener'] === $prevToken) {
            $expectedBlankLineCount = 0;
        }

        if ($blankLineCount !== $expectedBlankLineCount) {
            $error = 'Expected %s blank line before return statement; %s found';
            $data  = array(
                      $expectedBlankLineCount,
                      $blankLineCount,
                     );
            $phpcsFile->addError($error, $stackPtr, 'BlankLineBeforeReturn', $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, " ");
                }
            }
        }
    }
138727
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->bowOutEarly() === true) {
            return;
        }

        $tokens = $phpcsFile->getTokens();

        if ($tokens[$stackPtr]['code'] === \T_OPEN_SHORT_ARRAY
            && $this->isShortList($phpcsFile, $stackPtr) === false
        ) {
            // Short array, not short list.
            return;
        }

        if ($tokens[$stackPtr]['code'] === \T_LIST) {
            $nextNonEmpty = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true);
            if ($nextNonEmpty === false
                || $tokens[$nextNonEmpty]['code'] !== \T_OPEN_PARENTHESIS
                || isset($tokens[$nextNonEmpty]['parenthesis_closer']) === false
            ) {
                // Parse error or live coding.
                return;
            }

            $opener = $nextNonEmpty;
            $closer = $tokens[$nextNonEmpty]['parenthesis_closer'];
        } else {
            // Short list syntax.
            $opener = $stackPtr;

            if (isset($tokens[$stackPtr]['bracket_closer'])) {
                $closer = $tokens[$stackPtr]['bracket_closer'];
            }
        }

        if (isset($opener, $closer) === false) {
            return;
        }

        $this->examineList($phpcsFile, $opener, $closer);
    }
304679
public function process(File $phpcsFile, $stackPtr)
    {
        /*
         * Due to a tokenizer bug which gets hit when the PHP 7.3 heredoc/nowdoc syntax
         * is used, this part of the sniff cannot possibly work on PHPCS < 2.6.0.
         * See upstream issue #928.
         */
        if ($this->supportsBelow('7.2') === true && version_compare(PHPCSHelper::getVersion(), '2.6.0', '>=')) {
            $this->detectIndentedNonStandAloneClosingMarker($phpcsFile, $stackPtr);
        }

        $tokens = $phpcsFile->getTokens();
        if ($this->supportsAbove('7.3') === true && $tokens[$stackPtr]['code'] !== \T_STRING) {
            $this->detectClosingMarkerInBody($phpcsFile, $stackPtr);
        }
    }
641177
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
	{
		$tokens = $phpcsFile->getTokens();
		
		// Only work on level 1 "use", means including traits
		if ($tokens[$stackPtr]['level' ] != 1) {
			return;
		}

		$nextComma = $phpcsFile->findNext(T_COMMA, $stackPtr);
		$nextSemi = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);

		if ($nextComma !== false && $nextComma < $nextSemi) {
			$error = 'Only one trait should be included per "use"';
			$phpcsFile->addError($error, $stackPtr, 'OnlyOneTraitPerUse');
		}
	}
138692
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // Check if this is a single line or multi-line declaration.
        $openBracket  = $tokens[$stackPtr]['parenthesis_opener'];
        $closeBracket = $tokens[$stackPtr]['parenthesis_closer'];
        if ($tokens[$openBracket]['line'] === $tokens[$closeBracket]['line']) {
            $this->processSingleLineDeclaration($phpcsFile, $stackPtr, $tokens);
        } else {
            $this->processMultiLineDeclaration($phpcsFile, $stackPtr, $tokens);
        }
    }
562782
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // In case we have more than one class/interface/trait
        // per file, we want to reset at the start of each.
        if ($tokens[$stackPtr]['code'] !== T_FUNCTION) {
            $this->lastMethodName = null;
            return;
        }

        // We only care about class methods, so ignore global functions (level 0).
        if ($tokens[$stackPtr]['level'] === 1) {
            $methodName = $phpcsFile->getDeclarationName($stackPtr);
            if ($this->lastMethodName !== null && $methodName <= $this->lastMethodName) {
                $phpcsFile->addError('Method "%s" is not in alphabetical order.', $stackPtr, 'OutOfOrder', [$methodName]);
            }

            $this->lastMethodName = $methodName;
        }

    }
612732
public function process(File $phpcsFile, $stackPtr)
    {

        $tokens = $phpcsFile->getTokens();

        $fileName = basename($phpcsFile->getFilename());

        if (strpos($fileName, '_helper.php') !== false) {
            return;
        }

        $className = trim($phpcsFile->getDeclarationName($stackPtr));

        if (strpos($className, 'Migration') === 0 && strpos($fileName, '_') !== false) {
            return;
        }

        $nextContentPtr = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
        $type           = $tokens[$stackPtr]['content'];

        if ($fileName !== $className.'.php' && $this->badFilename === false) {
            $data  = array(
                      $fileName,
                      $className.'.php',
                     );
            $error = 'Filename "%s" doesn\'t match the expected filename "%s"';
            $phpcsFile->addError($error, $nextContentPtr, ucfirst($type).'BadFilename', $data);
            $phpcsFile->recordMetric($nextContentPtr, 'Filename matches '.$type, 'no');
            $this->badFilename = true;
        } else {
            $phpcsFile->recordMetric($nextContentPtr, 'Filename matches '.$type, 'yes');
        }

        // Ignore the rest of the file.
        return ($phpcsFile->numTokens + 1);

    }
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);
    }
184428
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // Find the opening bracket of the inline IF.
        for ($i = ($stackPtr - 1); $i > 0; $i--) {
            if (isset($tokens[$i]['parenthesis_opener']) === true
                && $tokens[$i]['parenthesis_opener'] < $i
            ) {
                $i = $tokens[$i]['parenthesis_opener'];
                continue;
            }

            if ($tokens[$i]['code'] === T_OPEN_PARENTHESIS) {
                break;
            }
        }

        if ($i <= 0) {
            // Could not find the begining of the statement. Probably not
            // wrapped with brackets, so assume it ends with a semicolon.
            $statementEnd = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1));
        } else {
            $statementEnd = $tokens[$i]['parenthesis_closer'];
        }

        // Make sure there are spaces around the question mark.
        $contentBefore = $phpcsFile->findPrevious(array(T_WHITESPACE), ($stackPtr - 1), null, true);
        $contentAfter  = $phpcsFile->findNext(array(T_WHITESPACE), ($stackPtr + 1), null, true);
        if ($tokens[$contentBefore]['code'] !== T_CLOSE_PARENTHESIS) {
            $error = 'Inline shorthand IF statement requires brackets around comparison';
            $phpcsFile->addError($error, $stackPtr, 'BracketsShorthandIf');

            return;
        }

        $spaceBefore = ($tokens[$stackPtr]['column'] - ($tokens[$contentBefore]['column'] + strlen($tokens[$contentBefore]['content'])));

        // todo: this should check for (a) at least one space or (b) proper
        // indentation for mutli-line
        if ($spaceBefore !== 1) {
            $error = "Inline shorthand IF statement requires 1 space before THEN; $spaceBefore found.";
            //$phpcsFile->addError($error, $stackPtr);
        }

        $spaceAfter = (($tokens[$contentAfter]['column']) - ($tokens[$stackPtr]['column'] + 1));
        if ($spaceAfter !== 1 && $tokens[$stackPtr + 1]['content'] != ':') {
            $error = "Inline shorthand IF statement requires 1 space after THEN; $spaceAfter found.";
            $phpcsFile->addError($error, $stackPtr, 'SpacingShorthandIf');
        }

        // If there is an else in this condition, make sure it has correct spacing.
        $inlineElse = $phpcsFile->findNext(array(T_COLON), ($stackPtr + 1), $statementEnd, false);
        if ($inlineElse === false) {
            // No else condition.
            return;
        }

        $contentBefore = $phpcsFile->findPrevious(array(T_WHITESPACE), ($inlineElse - 1), null, true);
        $contentAfter  = $phpcsFile->findNext(array(T_WHITESPACE), ($inlineElse + 1), null, true);

        $spaceBefore = ($tokens[$inlineElse]['column'] - ($tokens[$contentBefore]['column'] + strlen($tokens[$contentBefore]['content'])));

        // todo: this should check for (a) at least one space or (b) proper
        // indentation for mutli-line
        if ($spaceBefore !== 1) {
            $error = "Inline shorthand IF statement requires 1 space before ELSE; $spaceBefore found.";
            //$phpcsFile->addError($error, $inlineElse);
        }

        $spaceAfter = (($tokens[$contentAfter]['column']) - ($tokens[$inlineElse]['column'] + 1));
        if ($spaceAfter !== 1) {
            $error = "Inline shorthand IF statement requires 1 space after ELSE; $spaceAfter found.";
            $phpcsFile->addError($error, $inlineElse, 'SpacingShorthandIf');
        }
    }
572931
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsAbove('7.0') === false) {
            return;
        }

        $tokens = $phpcsFile->getTokens();

        // Verify that the next token is a square open bracket. If not, bow out.
        $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true, null, true);

        if ($nextToken === false || $tokens[$nextToken]['code'] !== \T_OPEN_SQUARE_BRACKET || isset($tokens[$nextToken]['bracket_closer']) === false) {
            return;
        }

        // The previous non-empty token has to be a $, -> or ::.
        $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true);
        if ($prevToken === false || \in_array($tokens[$prevToken]['code'], array(\T_DOLLAR, \T_OBJECT_OPERATOR, \T_DOUBLE_COLON), true) === false) {
            return;
        }

        // For static object calls, it only applies when this is a function call.
        if ($tokens[$prevToken]['code'] === \T_DOUBLE_COLON) {
            $hasBrackets = $tokens[$nextToken]['bracket_closer'];
            while (($hasBrackets = $phpcsFile->findNext(Tokens::$emptyTokens, ($hasBrackets + 1), null, true, null, true)) !== false) {
                if ($tokens[$hasBrackets]['code'] === \T_OPEN_SQUARE_BRACKET) {
                    if (isset($tokens[$hasBrackets]['bracket_closer'])) {
                        $hasBrackets = $tokens[$hasBrackets]['bracket_closer'];
                        continue;
                    } else {
                        // Live coding.
                        return;
                    }

                } elseif ($tokens[$hasBrackets]['code'] === \T_OPEN_PARENTHESIS) {
                    // Caught!
                    break;

                } else {
                    // Not a function call, so bow out.
                    return;
                }
            }

            // Now let's also prevent false positives when used with self and static which still work fine.
            $classToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($prevToken - 1), null, true, null, true);
            if ($classToken !== false) {
                if ($tokens[$classToken]['code'] === \T_STATIC || $tokens[$classToken]['code'] === \T_SELF) {
                    return;
                } elseif ($tokens[$classToken]['code'] === \T_STRING && $tokens[$classToken]['content'] === 'self') {
                    return;
                }
            }
        }

        $phpcsFile->addError(
            'Indirect access to variables, properties and methods will be evaluated strictly in left-to-right order since PHP 7.0. Use curly braces to remove ambiguity.',
            $stackPtr,
            'Found'
        );
    }