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

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

@return void
336468
public function process(File $phpcsFile, $stackPtr)
    {
        // Get all parameters from method signature.
        $paramNames = PHPCSHelper::getMethodParameters($phpcsFile, $stackPtr);
        if (empty($paramNames)) {
            return;
        }

        $supportsPHP4 = $this->supportsBelow('4.4');

        foreach ($paramNames as $param) {
            if ($param['type_hint'] === '') {
                continue;
            }

            // Strip off potential nullable indication.
            $typeHint = ltrim($param['type_hint'], '?');

            if ($supportsPHP4 === true) {
                $phpcsFile->addError(
                    'Type declarations were not present in PHP 4.4 or earlier.',
                    $param['token'],
                    'TypeHintFound'
                );

            } elseif (isset($this->newTypes[$typeHint])) {
                $itemInfo = array(
                    'name' => $typeHint,
                );
                $this->handleFeature($phpcsFile, $param['token'], $itemInfo);

                // As of PHP 7.0, using `self` or `parent` outside class scope throws a fatal error.
                // Only throw this error for PHP 5.2+ as before that the "type hint not supported" error
                // will be thrown.
                if (($typeHint === 'self' || $typeHint === 'parent')
                    && $this->inClassScope($phpcsFile, $stackPtr, false) === false
                    && $this->supportsAbove('5.2') !== false
                ) {
                    $phpcsFile->addError(
                        "'%s' type cannot be used outside of class scope",
                        $param['token'],
                        ucfirst($typeHint) . 'OutsideClassScopeFound',
                        array($typeHint)
                    );
                }
            } elseif (isset($this->invalidTypes[$typeHint])) {
                $error = "'%s' is not a valid type declaration. Did you mean %s ?";
                $data  = array(
                    $typeHint,
                    $this->invalidTypes[$typeHint],
                );

                $phpcsFile->addError($error, $param['token'], 'InvalidTypeHintFound', $data);
            }
        }
    }
204878
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // Make sure this is trailing whitespace.
        $line = $tokens[$stackPtr]['line'];
        if (($stackPtr < count($tokens) - 1)
            && $tokens[($stackPtr + 1)]['line'] === $line
        ) {
            return;
        }

        if (strpos($tokens[$stackPtr]['content'], "\n") > 0
            || strpos($tokens[$stackPtr]['content'], "\r") > 0
        ) {
            $warning = 'Please trim any trailing whitespace';
            $phpcsFile->addWarning($warning, $stackPtr, 'Invalid');
        }
    }
1107269
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $token = $tokens[$stackPtr];

        if (!array_key_exists('scope_opener', $token) || !array_key_exists('scope_closer', $token)) {
            return;
        }

        $scopeOpener = $token['scope_opener'];
        $firstContent = $phpcsFile->findNext(T_WHITESPACE, $scopeOpener + 1, null, true);

        if ($tokens[$firstContent]['line'] !== $tokens[$scopeOpener]['line'] + 1) {
            $phpcsFile->addError('Blank line found at start of control structure', $scopeOpener, 'SpacingBeforeOpen');
        }

        $scopeCloser = $token['scope_closer'];
        $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, $scopeCloser - 1, null, true);

        if ($tokens[$lastContent]['line'] !== $tokens[$scopeCloser]['line'] - 1) {
            $phpcsFile->addError('Blank line found at end of control structure', $lastContent + 2, 'SpacingAfterClose');
        }
    }
928174
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        if ($tokens[$stackPtr]['code'] === T_IS_NOT_EQUAL) {
            $error = '"%s" is not allowed, use "!==" instead';
            $data  = array($tokens[$stackPtr]['content']);
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'IsNotEqualNotAllowed', $data);
            if ($fix === true) {
                $phpcsFile->fixer->beginChangeset();
                $phpcsFile->fixer->replaceToken($stackPtr, '!==');
                $phpcsFile->fixer->endChangeset();
            }
        }

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

        $varName = $tokens[$stackPtr]['content'];
        if ($varName !== '$GLOBALS'
            && $varName !== '$HTTP_RAW_POST_DATA'
            && $varName !== '$_COOKIE'
            && $varName !== '$_ENV'
            && $varName !== '$_FILES'
            && $varName !== '$_GET'
            && $varName !== '$_POST'
            && $varName !== '$_REQUEST'
            && $varName !== '$_SERVER'
        ) {
            return;
        }

        $error = "The $varName super global must not be accessed directly.";
        $phpcsFile->addError($error, $stackPtr, 'NoSuperGlobals');
    }
349677
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        $ignore = array(
                T_DOUBLE_COLON,
                T_OBJECT_OPERATOR,
                T_FUNCTION,
                T_CONST,
        );

        $prevToken = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
        if (in_array($tokens[$prevToken]['code'], $ignore) === true) {
            // Not a call to a PHP function.
            return;
        }

        $function = strtolower($tokens[$stackPtr]['content']);
        $pattern  = null;

        if ($this->patternMatch === true) {
            $count   = 0;
            $pattern = preg_replace(
                    $this->forbiddenFunctionNames,
                    $this->forbiddenFunctionsNames,
                    $function,
                    1,
                    $count
            );

            if ($count === 0) {
                return;
            }

            // Remove the pattern delimiters and modifier.
            $pattern = substr($pattern, 1, -2);
        } else {
            if (in_array($function, $this->forbiddenFunctionNames) === false) {
                return;
            }
        }

        $this->addError($phpcsFile, $stackPtr, $function, $pattern);

    }
488797
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsBelow('5.5') !== true) {
            return;
        }

        $tokens = $phpcsFile->getTokens();
        $find   = array(
            \T_ARRAY            => \T_ARRAY,
            \T_OPEN_SHORT_ARRAY => \T_OPEN_SHORT_ARRAY,
        );

        while (($hasArray = $phpcsFile->findNext($find, ($stackPtr + 1), null, false, null, true)) !== false) {
            $phpcsFile->addError(
                'Constant arrays using the "const" keyword are not allowed in PHP 5.5 or earlier',
                $hasArray,
                'Found'
            );

            // Skip past the content of the array.
            $stackPtr = $hasArray;
            if ($tokens[$hasArray]['code'] === \T_OPEN_SHORT_ARRAY && isset($tokens[$hasArray]['bracket_closer'])) {
                $stackPtr = $tokens[$hasArray]['bracket_closer'];
            } elseif ($tokens[$hasArray]['code'] === \T_ARRAY && isset($tokens[$hasArray]['parenthesis_closer'])) {
                $stackPtr = $tokens[$hasArray]['parenthesis_closer'];
            }
        }
    }
897878
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $line   = $tokens[$stackPtr]['line'];

        if ($tokens[$stackPtr + 1]['line'] === $line
            && $tokens[$stackPtr + 1]['code'] !== T_WHITESPACE
        ) {
            $fix = $phpcsFile->addFixableError(
                'Add a single space after each comma delimiter',
                $stackPtr,
                'Invalid'
            );

            if ($fix === true) {
                $phpcsFile->fixer->addContent($stackPtr, " ");
            }
        }
    }
754807
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        $beforeToken = $tokens[$stackPtr - 1];
        if ($beforeToken['code'] !== T_WHITESPACE) {
            $phpcsFile->addError('Expected 1 space before =>, 0 found', $stackPtr, 'SpaceBeforeArrow');
        } elseif ($beforeToken['content'] !== ' ') {
            $phpcsFile->addError('Expected 1 space before =>, %s found', $stackPtr, 'SpaceBeforeArrow', [strlen($beforeToken['content'])]);
        }

        $afterToken = $tokens[$stackPtr + 1];
        if ($afterToken['code'] !== T_WHITESPACE) {
            $phpcsFile->addError('Expected 1 space after =>, 0 found', $stackPtr, 'SpaceAfterArrow');
        } elseif ($afterToken['content'] !== ' ') {
            $phpcsFile->addError('Expected 1 space after =>, %s found', $stackPtr, 'SpaceAfterArrow', [strlen($afterToken['content'])]);
        }
    }
453423
public function process(File $phpcsFile, $stackPtr)
    {
        parent::process($phpcsFile, $stackPtr);

        $tokens = $phpcsFile->getTokens();
        $find   = Tokens::$methodPrefixes;
        $find[] = T_WHITESPACE;

        $commentEnd = $phpcsFile->findPrevious($find, ($stackPtr - 1), null, true);
        if ($tokens[$commentEnd]['code'] !== T_DOC_COMMENT_CLOSE_TAG) {
            return;
        }

        $commentStart = $tokens[$commentEnd]['comment_opener'];

        $empty = array(
                  T_DOC_COMMENT_WHITESPACE,
                  T_DOC_COMMENT_STAR,
                 );

        $short = $phpcsFile->findNext($empty, ($commentStart + 1), $commentEnd, true);
        if ($short === false || $tokens[$short]['code'] !== T_DOC_COMMENT_STRING) {
            return;
        }

        if ($this->isInheritDoc($phpcsFile, $commentStart) === true) {
            return;
        }

        $this->checkShort($phpcsFile, $stackPtr, $tokens[$short]['content'], $short);
    }
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;
        }
    }
569051
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $arrayStart = DWS_Helpers_Bracket::bracketStart($phpcsFile, $stackPtr);
        $arrayEnd = DWS_Helpers_Bracket::bracketEnd($phpcsFile, $stackPtr);

        $isSingleLine = $tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line'];

        $commas = DWS_Helpers_Array::commaPositions($phpcsFile, $arrayStart);

        $lastComma = array_pop($commas);
        $trailingComma = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $lastComma + 1, $arrayEnd, true) === false;

        if ($isSingleLine) {
            if ($trailingComma) {
                $phpcsFile->addError('No trailing comma allowed on single-line arrays', $lastComma, 'SingleLineTrailingComma');
            }
        } elseif (!$trailingComma) {
            $previousItem = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, $arrayEnd - 1, $arrayStart, true);
            $phpcsFile->addError('Trailing comma required for multi-line arrays', $previousItem, 'MultiLineTrailingComma');
        }
    }
737507
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        if (
            $tokens[$stackPtr + 2]['type'] == 'T_STRING'
            &&
            (
                $tokens[$stackPtr + 3]['type'] == 'T_OPEN_PARENTHESIS'
                ||
                (
                    $tokens[$stackPtr + 3]['type'] == 'T_WHITESPACE'
                    &&
                    $tokens[$stackPtr + 4]['type'] == 'T_OPEN_PARENTHESIS'
                )
            )
        ) {
            $className = $tokens[$stackPtr + 2]['content'];
            if (array_key_exists($className, $this->newClasses) === false) {
                return;
            }
            $this->addError($phpcsFile, $stackPtr, $className);
        }



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

        if (isset($tokens[$stackPtr]['scope_closer']) === false) {
            // Probably an interface method.
            return;
        }

        $closeBrace  = $tokens[$stackPtr]['scope_closer'];
        $prevContent = $phpcsFile->findPrevious(T_WHITESPACE, ($closeBrace - 1), null, true);

        // Special case for empty JS functions.
        if ($phpcsFile->tokenizerType === 'JS' && $prevContent === $tokens[$stackPtr]['scope_opener']) {
            // In this case, the opening and closing brace must be
            // right next to each other.
            if ($tokens[$stackPtr]['scope_closer'] !== ($tokens[$stackPtr]['scope_opener'] + 1)) {
                $error = 'The opening and closing braces of empty functions must be directly next to each other; e.g., function () {}';
                $fix   = $phpcsFile->addFixableError($error, $closeBrace, 'SpacingBetween');
                if ($fix === true) {
                    $phpcsFile->fixer->beginChangeset();
                    for ($i = ($tokens[$stackPtr]['scope_opener'] + 1); $i < $closeBrace; $i++) {
                        $phpcsFile->fixer->replaceToken($i, '');
                    }

                    $phpcsFile->fixer->endChangeset();
                }
            }

            return;
        }

        $nestedFunction = false;
        if ($phpcsFile->hasCondition($stackPtr, T_FUNCTION) === true
            || $phpcsFile->hasCondition($stackPtr, T_CLOSURE) === true
            || isset($tokens[$stackPtr]['nested_parenthesis']) === true
        ) {
            $nestedFunction = true;
        }

        $braceLine = $tokens[$closeBrace]['line'];
        $prevLine  = $tokens[$prevContent]['line'];
        $found     = ($braceLine - $prevLine - 1);

        $afterKeyword  = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
        $beforeKeyword = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
        if ($nestedFunction === true) {
            if ($found < 0) {
                $error = 'Closing brace of nested function must be on a new line';
                $fix   = $phpcsFile->addFixableError($error, $closeBrace, 'ContentBeforeClose');
                if ($fix === true) {
                    $phpcsFile->fixer->addNewlineBefore($closeBrace);
                }
            } else if ($found > $this->allowedNestedLines) {
                $error = 'Expected %s blank lines before closing brace of nested function; %s found';
                $data  = array(
                          $this->allowedNestedLines,
                          $found,
                         );
                $fix   = $phpcsFile->addFixableError($error, $closeBrace, 'SpacingBeforeNestedClose', $data);

                if ($fix === true) {
                    $phpcsFile->fixer->beginChangeset();
                    $changeMade = false;
                    for ($i = ($prevContent + 1); $i < $closeBrace; $i++) {
                        // Try to maintain indentation.
                        if ($tokens[$i]['line'] === ($braceLine - 1)) {
                            break;
                        }

                        $phpcsFile->fixer->replaceToken($i, '');
                        $changeMade = true;
                    }

                    // Special case for when the last content contains the newline
                    // token as well, like with a comment.
                    if ($changeMade === false) {
                        $phpcsFile->fixer->replaceToken(($prevContent + 1), '');
                    }

                    $phpcsFile->fixer->endChangeset();
                }//end if
            }//end if
        } else {
            if ($found !== (int) $this->allowedLines) {
                if ($this->allowedLines === 1) {
                    $plural = '';
                } else {
                    $plural = 's';
                }

                $error = 'Expected %s blank line%s before closing function brace; %s found';
                $data  = array(
                          $this->allowedLines,
                          $plural,
                          $found,
                         );
                $fix   = $phpcsFile->addFixableError($error, $closeBrace, 'SpacingBeforeClose', $data);

                if ($fix === true) {
                    if ($found > $this->allowedLines) {
                        $phpcsFile->fixer->beginChangeset();
                        for ($i = ($prevContent + 1); $i < ($closeBrace); $i++) {
                            $phpcsFile->fixer->replaceToken($i, '');
                        }

                        $phpcsFile->fixer->replaceToken(($closeBrace - 1), $phpcsFile->eolChar);
                        $phpcsFile->fixer->endChangeset();
                    } else {
                        $phpcsFile->fixer->addNewlineBefore($closeBrace);
                    }
                }
            }//end if
        }//end if

    }
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);
        }
    }
220588
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens    = $phpcsFile->getTokens();
        $errorData = [strtolower($tokens[$stackPtr]['content'])];

        if (false === isset($tokens[$stackPtr]['scope_opener']))
        {
            // @todo sort while thing...
            if ($tokens[$stackPtr]['code'] !== T_WHILE)
            {
                $error = 'Possible parse error: %s missing opening or closing brace';
                $phpcsFile->addWarning($error, $stackPtr, 'MissingBrace', $errorData);
            }

            return;
        }

        $curlyBrace  = $tokens[$stackPtr]['scope_opener'];
        $lastContent = $phpcsFile->findPrevious(T_WHITESPACE, ($curlyBrace - 1), $stackPtr, true);
        $classLine   = $tokens[$lastContent]['line'];
        $braceLine   = $tokens[$curlyBrace]['line'];

        if ($braceLine === $classLine)
        {
            $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'same line');
            $error = 'Opening brace of a %s must be on the line after the definition';
            $fix   = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceNewLine', $errorData);

            if (true === $fix)
            {
                $phpcsFile->fixer->beginChangeset();

                if (T_WHITESPACE === $tokens[($curlyBrace - 1)]['code'])
                {
                    $phpcsFile->fixer->replaceToken(($curlyBrace - 1), '');
                }

                $phpcsFile->fixer->addNewlineBefore($curlyBrace);
                $phpcsFile->fixer->endChangeset();
            }

            return;
        }
        else
        {
            $phpcsFile->recordMetric($stackPtr, 'Class opening brace placement', 'new line');

            if ($braceLine > ($classLine + 1))
            {
                $error = 'Opening brace of a %s must be on the line following the %s declaration.; Found %s line(s).';
                $data  = [
                          $tokens[$stackPtr]['content'],
                          $tokens[$stackPtr]['content'],
                          ($braceLine - $classLine - 1),
                         ];
                $fix   = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceWrongLine', $data);

                if (true === $fix)
                {
                    $phpcsFile->fixer->beginChangeset();

                    for ($i = ($curlyBrace - 1); $i > $lastContent; $i--)
                    {
                        if ($tokens[$i]['line'] === ($tokens[$curlyBrace]['line'] + 1))
                        {
                            break;
                        }

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

                    $phpcsFile->fixer->endChangeset();
                }

                return;
            }
        }

        if ($tokens[($curlyBrace + 1)]['content'] !== $phpcsFile->eolChar)
        {
            $error = 'Opening %s brace must be on a line by itself.';
            $fix   = $phpcsFile->addFixableError($error, $curlyBrace, 'OpenBraceNotAlone', $errorData);

            if (true === $fix)
            {
                $phpcsFile->fixer->addContent($curlyBrace, $phpcsFile->eolChar);
            }
        }

        if (T_WHITESPACE === $tokens[($curlyBrace - 1)]['code'])
        {
            $prevContent = $tokens[($curlyBrace - 1)]['content'];

            if ($prevContent === $phpcsFile->eolChar)
            {
                $spaces = 0;
            }
            else
            {
                $blankSpace = substr($prevContent, strpos($prevContent, $phpcsFile->eolChar));
                $spaces     = strlen($blankSpace);
            }

            $expected = ($tokens[$stackPtr]['level'] * $this->indent);

            if ($spaces !== $expected)
            {
                $error = 'Expected %s spaces before opening brace; %s found';
                $data  = [
                          $expected,
                          $spaces,
                         ];
                $fix   = $phpcsFile->addFixableError($error, $curlyBrace, 'SpaceBeforeBrace', $data);

                if ($fix === true)
                {
                    $indent = str_repeat(' ', $expected);

                    if ($spaces === 0)
                    {
                        $phpcsFile->fixer->addContentBefore($curlyBrace, $indent);
                    }
                    else
                    {
                        $phpcsFile->fixer->replaceToken(($curlyBrace - 1), $indent);
                    }
                }
            }
        }
    }
17486
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsAbove('5.3') === false) {
            return;
        }

        $tokens  = $phpcsFile->getTokens();
        $varName = substr($tokens[$stackPtr]['content'], 1);

        if (isset($this->removedGlobalVariables[$varName]) === false) {
            return;
        }

        if ($this->isClassProperty($phpcsFile, $stackPtr) === true) {
            // Ok, so this was a class property declaration, not our concern.
            return;
        }

        // Check for static usage of class properties shadowing the removed global variables.
        if ($this->inClassScope($phpcsFile, $stackPtr, false) === true) {
            $prevToken = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true, null, true);
            if ($prevToken !== false && $tokens[$prevToken]['code'] === \T_DOUBLE_COLON) {
                return;
            }
        }

        // Do some additional checks for the $php_errormsg variable.
        if ($varName === 'php_errormsg'
            && $this->isTargetPHPErrormsgVar($phpcsFile, $stackPtr, $tokens) === false
        ) {
            return;
        }

        // Still here, so throw an error/warning.
        $itemInfo = array(
            'name' => $varName,
        );
        $this->handleFeature($phpcsFile, $stackPtr, $itemInfo);
    }