Checks bracket spacing.

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

@return void
345037
protected function checkBracketSpacing(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        if (isset($tokens[$stackPtr]['parenthesis_opener']) === false) {
            return;
        }

        $parenOpener    = $tokens[$stackPtr]['parenthesis_opener'];
        $parenCloser    = $tokens[$stackPtr]['parenthesis_closer'];
        $spaceAfterOpen = 0;
        if ($tokens[($parenOpener + 1)]['code'] === T_WHITESPACE) {
            $spaceAfterOpen = $tokens[($parenOpener + 1)]['length'];
        }

        if ($spaceAfterOpen !== $this->requiredSpacesAfterOpen) {
            $error = 'Expected %s spaces after "%s" opening bracket; %s found';
            $data  = array(
                      $this->requiredSpacesAfterOpen,
                      $tokens[$stackPtr]['content'],
                      $spaceAfterOpen,
                     );
            $fix   = $phpcsFile->addFixableError($error, ($parenOpener + 1), 'SpacingAfterOpenBrace', $data);

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

                for ($i = $spaceAfterOpen; $i < $this->requiredSpacesAfterOpen; $i++) {
                    $phpcsFile->fixer->addContent($parenOpener, ' ');
                }

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

        if ($tokens[$parenOpener]['line'] === $tokens[$parenCloser]['line']) {
            $spaceBeforeClose = 0;
            if ($tokens[($parenCloser - 1)]['code'] === T_WHITESPACE) {
                $spaceBeforeClose = $tokens[($parenCloser - 1)]['length'];
            }

            if ($spaceBeforeClose !== $this->requiredSpacesBeforeClose) {
                $error = 'Expected %s spaces before "%s" closing bracket; %s found';
                $data  = array(
                          $this->requiredSpacesBeforeClose,
                          $tokens[$stackPtr]['content'],
                          $spaceBeforeClose,
                         );
                $fix   = $phpcsFile->addFixableError($error, ($parenCloser - 1), 'SpaceBeforeCloseBrace', $data);

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

                    for ($i = $spaceBeforeClose; $i < $this->requiredSpacesBeforeClose; $i++) {
                        $phpcsFile->fixer->addContentBefore($parenCloser, ' ');
                    }

                    $phpcsFile->fixer->endChangeset();
                }
            }
        }//end if
    }
262394
protected function checkUseForClass(File $phpcsFile, $stackPtr) {
		$nextIndex = $phpcsFile->findNext(T_EXTENDS, $stackPtr + 1);
		if ($nextIndex) {
			$this->checkUseForExtends($phpcsFile, $nextIndex);
		}

		$nextIndex = $phpcsFile->findNext(T_IMPLEMENTS, $stackPtr + 1);
		if ($nextIndex) {
			$this->checkUseForImplements($phpcsFile, $nextIndex);
		}
	}
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'])]);
        }
    }
924572
protected function checkLeadingContent(File $phpcsFile, $stackPtr)
    {
        $tokens                   = $phpcsFile->getTokens();
        $leadingContent           = $this->getLeadingContent($phpcsFile, $stackPtr);
        $controlStructureStartPtr = $this->getLeadingCommentOrSelf($phpcsFile, $stackPtr);

        if ($tokens[$leadingContent]['code'] === T_OPEN_TAG) {
            // At the beginning of the script or embedded code.
            return;
        }

        $firstNonWhitespace = $phpcsFile->findPrevious(
            T_WHITESPACE,
            ($controlStructureStartPtr - 1),
            $leadingContent,
            true
        );
        $firstNonWhitespace = $firstNonWhitespace ?: $leadingContent;
        $leadingLineNumber  = $tokens[$firstNonWhitespace]['line'];

        if ($tokens[$leadingContent]['code'] === T_OPEN_CURLY_BRACKET
            || $this->insideSwitchCase($phpcsFile, $leadingContent) === true
            || ($this->elseOrElseIf($phpcsFile, $stackPtr) === true && $this->ifOrElseIf($phpcsFile, $leadingContent) === true)
            || ($this->isCatch($phpcsFile, $stackPtr) === true && $this->isTryOrCatch($phpcsFile, $leadingContent) === true)
        ) {
            if ($this->isFunction($phpcsFile, $leadingContent) === true) {
                // The previous content is the opening brace of a function
                // so normal function rules apply and we can ignore it.
                return;
            }

            if ($this->isClosure($phpcsFile, $stackPtr, $leadingContent) === true) {
                return;
            }

            if ($tokens[$controlStructureStartPtr]['line'] !== ($leadingLineNumber + 1)) {
                $data = array($tokens[$stackPtr]['content']);
                $diff = $tokens[$controlStructureStartPtr]['line'] - ($leadingLineNumber + 1);
                if ($diff < 0) {
                    $error = 'Beginning of the "%s" control structure must be first content on the line';
                    $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'ContentBeforeStart', $data);
                } else {
                    $data[] = $diff;
                    $error  = 'Expected 0 blank lines before "%s" control structure; %s found';
                    $fix    = $phpcsFile->addFixableError($error, $stackPtr, 'LineBeforeOpen', $data);
                }

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

                    for ($i = ($firstNonWhitespace + 1); $i < $controlStructureStartPtr; $i++) {
                        if ($tokens[$i]['line'] === $tokens[$controlStructureStartPtr]['line']) {
                            // Keep existing indentation.
                            break;
                        }

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

                    $phpcsFile->fixer->addNewline($firstNonWhitespace);
                    $phpcsFile->fixer->endChangeset();
                }
            }//end if
        } elseif ($tokens[$controlStructureStartPtr]['line'] === ($leadingLineNumber + 1)) {
            // Code on the previous line before control structure start.
            $data  = array($tokens[$stackPtr]['content']);
            $error = 'No blank line found before "%s" control structure';
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'NoLineBeforeOpen', $data);

            if ($fix === true) {
                $phpcsFile->fixer->beginChangeset();
                $phpcsFile->fixer->addNewline($firstNonWhitespace);
                $phpcsFile->fixer->endChangeset();
            }
        }//end if
    }
728369
public function process(File $phpcsFile, $stackPtr)
    {
        $functionPtr = $phpcsFile->findPrevious(T_FUNCTION, ($stackPtr - 1));

        if ($functionPtr !== false) {
            $doubleColonPtr = $phpcsFile->findNext(T_DOUBLE_COLON, ($stackPtr + 1));

            if ($doubleColonPtr !== false) {
                $tokens        = $phpcsFile->getTokens();
                $functionName  = $phpcsFile->getDeclarationName($functionPtr);
                $methodNamePtr = $phpcsFile->findNext(T_STRING, ($stackPtr + 1));

                if ($methodNamePtr !== false && $tokens[$methodNamePtr]['content'] !== $functionName) {
                    $error = 'Method name mismatch in parent:: call';
                    $phpcsFile->addError($error, $stackPtr, 'WrongName');
                }
            }
        }//end if
    }
1050132
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens     = $phpcsFile->getTokens();
        $arrayStart = $tokens[$stackPtr]['parenthesis_opener'];
        $arrayEnd   = $tokens[$arrayStart]['parenthesis_closer'];

        if ($arrayStart !== ($stackPtr + 1)) {
            $error = 'There must be no space between the Array keyword and the opening parenthesis';
            $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterKeyword');
            if ($fix === true) {
                $phpcsFile->fixer->beginChangeset();

                for ($i = ($stackPtr + 1); $i < $arrayStart; $i++) {
                    $phpcsFile->fixer->replaceToken($i, '');
                }

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

        // Check for empty arrays.
        $content = $phpcsFile->findNext(array(T_WHITESPACE), ($arrayStart + 1), ($arrayEnd + 1), true);
        if ($content === $arrayEnd) {
            // Empty array, but if the brackets aren't together, there's a problem.
            if (($arrayEnd - $arrayStart) !== 1) {
                $error = 'Empty array declaration must have no space between the parentheses';
                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceInEmptyArray');
                if ($fix === true) {
                    $phpcsFile->fixer->beginChangeset();

                    for ($i = ($arrayStart + 1); $i < $arrayEnd; $i++) {
                        $phpcsFile->fixer->replaceToken($i, '');
                    }

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

                // We can return here because there is nothing else to check. All code
                // below can assume that the array is not empty.
                return;
            }
        }

        $lastItem = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($arrayEnd - 1), $stackPtr, true);

        // Empty array.
        if ($lastItem === $arrayStart) {
            return;
        }

        // Inline array.
        $isInlineArray = $tokens[$arrayStart]['line'] === $tokens[$arrayEnd]['line'];

        // Check if the last item in a multiline array has a "closing" comma.
        if ($tokens[$lastItem]['code'] !== T_COMMA && $isInlineArray === false) {
            $error = 'A comma should follow the last multiline array item. Found: '.$tokens[$lastItem]['content'];
            $fix   = $phpcsFile->addFixableWarning($error, $lastItem, 'NoLastComma');
            if ($fix === true) {
                $phpcsFile->fixer->beginChangeset();
                $phpcsFile->fixer->addContent($lastItem, ',');
                $phpcsFile->fixer->endChangeset();
            }

            return;
        }

        if ($isInlineArray === true) {
            if ($tokens[$lastItem]['code'] === T_COMMA) {
                $error = 'Comma not allowed after last value in single-line array declaration';
                $fix   = $phpcsFile->addFixableWarning($error, $lastItem, 'LastComma');
                if ($fix === true) {
                    $phpcsFile->fixer->beginChangeset();
                    $phpcsFile->fixer->replaceToken($lastItem, '');
                    $phpcsFile->fixer->endChangeset();
                }

                return;
            }

            // Inline array must not have spaces within parenthesis.
            if ($content !== ($arrayStart + 1)) {
                $error = 'Space found after opening parenthesis of Array';
                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterOpen');
                if ($fix === true) {
                    $phpcsFile->fixer->beginChangeset();

                    for ($i = ($arrayStart + 1); $i < $content; $i++) {
                        $phpcsFile->fixer->replaceToken($i, '');
                    }

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

            if ($lastItem !== ($arrayEnd - 1)) {
                $error = 'Space found before closing parenthesis of Array';
                $fix   = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceBeforeClose');
                if ($fix === true) {
                    $phpcsFile->fixer->beginChangeset();

                    for ($i = ($lastItem + 1); $i < $arrayEnd; $i++) {
                        $phpcsFile->fixer->replaceToken($i, '');
                    }

                    $phpcsFile->fixer->endChangeset();
                }
            }
        }//end if
    }
369558
public function process(File $phpcsFile, $stackPtr)
    {
        if ($this->supportsAbove('7.0') === false) {
            return;
        }

        $tokens = $phpcsFile->getTokens();

        // Determine the start and end of the part of the statement we need to examine.
        $start = ($stackPtr + 1);
        $next  = $phpcsFile->findNext(Tokens::$emptyTokens, $start, null, true);
        if ($next !== false && $tokens[$next]['code'] === \T_OPEN_PARENTHESIS) {
            $start = ($next + 1);
        }

        $end = PHPCSHelper::findEndOfStatement($phpcsFile, $start);
        if (isset($this->inclusiveStopPoints[$tokens[$end]['code']]) === true) {
            --$end;
        }

        if ($this->isNegativeNumber($phpcsFile, $start, $end, true) !== true) {
            // Not a negative number or undetermined.
            return;
        }

        $phpcsFile->addError(
            'Bitwise shifts by negative number will throw an ArithmeticError in PHP 7.0. Found: %s',
            $stackPtr,
            'Found',
            array($phpcsFile->getTokensAsString($start, ($end - $start + 1)))
        );
    }
1102129
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        if (isset($tokens[$stackPtr]['parenthesis_opener']) === false) {
            return;
        }

        $equalOperator = $phpcsFile->findNext(
            T_EQUAL,
            $tokens[$stackPtr]['parenthesis_opener'],
            $tokens[$stackPtr]['parenthesis_closer']
        );

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

        $phpcsFile->addError(
            'Assignment in "'.$tokens[$stackPtr]['content'].'" control structure is forbidden',
            $equalOperator,
            'Forbidden'
        );
    }
906334
protected function checkCatchToken(File $phpcsFile, int $stackPtr): void
    {
        $tokens = $phpcsFile->getTokens();

        if ($tokens[$stackPtr]['code'] !== T_CATCH) {
            return;
        }

        $this->expectSingleSpaceBefore($phpcsFile, $stackPtr, 'catch');
        $this->expectSingleSpaceAfter($phpcsFile, $stackPtr, 'catch');
    }
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);
        }



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

        if ($tokens[$stackPtr]['code'] === T_INLINE_THEN) {
            $end = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
            if ($tokens[$end]['code'] !== T_CLOSE_PARENTHESIS) {
                // This inline IF statement does not have its condition
                // bracketed, so we need to guess where it starts.
                for ($i = ($end - 1); $i >= 0; $i--) {
                    if ($tokens[$i]['code'] === T_SEMICOLON) {
                        // Stop here as we assume it is the end
                        // of the previous statement.
                        break;
                    } else if ($tokens[$i]['code'] === T_OPEN_TAG) {
                        // Stop here as this is the start of the file.
                        break;
                    } else if ($tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET) {
                        // Stop if this is the closing brace of
                        // a code block.
                        if (isset($tokens[$i]['scope_opener']) === true) {
                            break;
                        }
                    } else if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) {
                        // Stop if this is the opening brace of
                        // a code block.
                        if (isset($tokens[$i]['scope_closer']) === true) {
                            break;
                        }
                    }
                }//end for

                $start = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true);
            } else {
                if (isset($tokens[$end]['parenthesis_opener']) === false) {
                    return;
                }

                $start = $tokens[$end]['parenthesis_opener'];
            }//end if
        } else if ($tokens[$stackPtr]['code'] === T_FOR) {
            if (isset($tokens[$stackPtr]['parenthesis_opener']) === false) {
                return;
            }

            $openingBracket = $tokens[$stackPtr]['parenthesis_opener'];
            $closingBracket = $tokens[$stackPtr]['parenthesis_closer'];

            $start = $phpcsFile->findNext(T_SEMICOLON, $openingBracket, $closingBracket);
            $end   = $phpcsFile->findNext(T_SEMICOLON, ($start + 1), $closingBracket);
            if ($start === false || $end === false) {
                return;
            }
        } else {
            if (isset($tokens[$stackPtr]['parenthesis_opener']) === false) {
                return;
            }

            $start = $tokens[$stackPtr]['parenthesis_opener'];
            $end   = $tokens[$stackPtr]['parenthesis_closer'];
        }//end if

        $requiredOps = 0;
        $foundOps    = 0;
        $foundBools  = 0;

        for ($i = $start; $i <= $end; $i++) {
            $type = $tokens[$i]['code'];
            if (in_array($type, array_keys(self::$invalidOps[$tokenizer])) === true) {
                $error = 'Operator %s prohibited; use %s instead';
                $data  = [
                    $tokens[$i]['content'],
                    self::$invalidOps[$tokenizer][$type],
                ];
                $phpcsFile->addError($error, $i, 'NotAllowed', $data);
                $foundOps++;
            } else if (in_array($type, self::$validOps) === true) {
                $foundOps++;
            }

            if ($tokens[$i]['code'] === T_TRUE || $tokens[$i]['code'] === T_FALSE) {
                $foundBools++;
            }

            if ($phpcsFile->tokenizerType !== 'JS'
                && ($tokens[$i]['code'] === T_BOOLEAN_AND
                || $tokens[$i]['code'] === T_BOOLEAN_OR)
            ) {
                $requiredOps++;

                // When the instanceof operator is used with another operator
                // like ===, you can get more ops than are required.
                if ($foundOps > $requiredOps) {
                    $foundOps = $requiredOps;
                }

                // If we get to here and we have not found the right number of
                // comparison operators, then we must have had an implicit
                // true operation i.e., if ($a) instead of the required
                // if ($a === true), so let's add an error.
                if ($requiredOps !== $foundOps) {
                    $error = 'Implicit true comparisons prohibited; use === TRUE instead';
                    $phpcsFile->addError($error, $stackPtr, 'ImplicitTrue');
                    $foundOps++;
                }
            }
        }//end for

        $requiredOps++;

        if ($phpcsFile->tokenizerType !== 'JS'
            && $foundOps < $requiredOps
            && ($requiredOps !== $foundBools)
            && $tokens[($stackPtr + 1)]['code'] !== T_INLINE_ELSE
        ) {
            $error = 'Implicit true comparisons prohibited; use === TRUE instead';
            $phpcsFile->addError($error, $stackPtr, 'ImplicitTrue');
        }

    }
1196437
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $stackPrev = $stackPtr - 1;
        $stackNext = $stackPtr + 1;

        // One space after the namespace keyword.
        if ($tokens[$stackNext]['content'] !== ' ') {
            $error = 'There must be a single space after the NAMESPACE keyword';
            $fix = $phpcsFile->addFixableError($error, $stackPtr, 'SpaceAfterNamespace');
            if ($fix === true) {
                $phpcsFile->fixer->replaceToken($stackNext, ' ');
            }
        }

        // Find the previous token that is NOT whitespace
        $lastNonWhitespace = $phpcsFile->findPrevious(T_WHITESPACE, $stackPrev, null, true);

        // should not happen; something is horribly wrong
        if ($lastNonWhitespace === false) {
            return;
        }

        $diff = ($tokens[$stackPtr]['line'] - $tokens[$lastNonWhitespace]['line']);

        if ($diff !== 2) {
            $error = 'There must be one blank line before the namespace declaration';
            $fix = $phpcsFile->addFixableError($error, $stackPtr, 'BlankLineBefore');

            if ($fix === true) {
                /*
                 * If there is less than a 2 line difference, add newlines in.
                 * If there is more than a 2 line difference, take newlines out.
                 */
                if ($diff < 2) {
                    $phpcsFile->fixer->beginChangeset();
                    for ($i = 0; $i < (2 - $diff); $i++) {
                        $phpcsFile->fixer->addNewlineBefore($stackPtr);
                    }
                    $phpcsFile->fixer->endChangeset();
                } else {
                    /*
                     * Remove all whitespace between the namespace and the previous non-whitespace
                     * tokens. If a newline was removed from the same line as the previous
                     * non-whitespace token, we need to make sure to add that back in.
                     */
                    $phpcsFile->fixer->beginChangeset();
                    $newlineRemoved = false;
                    for ($i = ($lastNonWhitespace + 1); $i < $stackPtr; $i++) {
                        if ($tokens[$lastNonWhitespace]['line'] === $tokens[$i]['line']) {
                            $newlineRemoved = true;
                        }
                        $phpcsFile->fixer->replaceToken($i, '');
                    }
                    if ($newlineRemoved) {
                        $phpcsFile->fixer->addNewline($lastNonWhitespace);
                    }
                    $phpcsFile->fixer->addNewline($lastNonWhitespace);
                    $phpcsFile->fixer->endChangeset();
                }
            }
        } elseif ($tokens[$stackPtr]['column'] !== 1) {
            $error = 'Line indented incorrectly; expected 0 spaces, found '.($tokens[$stackPtr]['column'] - 1);
            $fix = $phpcsFile->addFixableError($error, $stackPtr, 'NoSpaceBeforeNamespace');

            if ($fix === true) {
                $content = explode("\n", $tokens[$stackPrev]['content']);
                $content[count($content) - 1] = '';
                $phpcsFile->fixer->replaceToken($stackPrev, implode("\n", $content));
            }
        }
    }
525097
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

		$valid = false;

		if (preg_match('|//\s|', $tokens[$stackPtr]['content']))
		{
			$valid = true;
		}

		if (preg_match('|\*[\s/]|', $tokens[$stackPtr]['content']))
		{
			$valid = true;
		}

		if ($valid === false)
		{
            $error = 'A space is required at the start of the comment %s';
            $data  = array(trim($tokens[$stackPtr]['content']));
            $phpcsFile->addError($error, $stackPtr, 'Found', $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);
    }
752958
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $operatorCode = $tokens[$stackPtr]['code'];

        if ($operatorCode === T_BITWISE_AND) {
            // If its not a reference, then we expect one space either side of the
            // bitwise operator.
            if ($phpcsFile->isReference($stackPtr) === false) {
                // Check there is one space before the & operator.
                if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) {
                    $error = 'Expected 1 space before "&" operator; 0 found';
                    $phpcsFile->addError($error, $stackPtr, 'NoSpaceBeforeAmp');
                } else {
                    if (strlen($tokens[($stackPtr - 1)]['content']) !== 1) {
                        $found = strlen($tokens[($stackPtr - 1)]['content']);
                        $error = sprintf('Expected 1 space before "&" operator; %s found', $found);

                        $phpcsFile->addError($error, $stackPtr, 'SpacingBeforeAmp');
                    }
                }

                // Check there is one space after the & operator.
                if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
                    $error = 'Expected 1 space after "&" operator; 0 found';
                    $phpcsFile->addError($error, $stackPtr, 'NoSpaceAfterAmp');
                } else {
                    if (strlen($tokens[($stackPtr + 1)]['content']) !== 1) {
                        $found = strlen($tokens[($stackPtr + 1)]['content']);
                        $error = sprintf('Expected 1 space after "&" operator; %s found', $found);

                        $phpcsFile->addError($error, $stackPtr, 'SpacingAfterAmp');
                    }
                }
            }
        } else {
            if ($operatorCode === T_MINUS || $operatorCode === T_PLUS) {
                // Check minus spacing, but make sure we aren't just assigning
                // a minus value or returning one.
                $prev = $phpcsFile->findPrevious(T_WHITESPACE, ($stackPtr - 1), null, true);
                $prevCode = $tokens[$prev]['code'];
                if ($prevCode === T_RETURN) {
                    // Just returning a negative value; eg. return -1.
                    return;
                }

                if (in_array($prevCode, PHP_CodeSniffer_Tokens::$operators) === true) {
                    // Just trying to operate on a negative value; eg. ($var * -1).
                    return;
                }

                if (in_array($prevCode, PHP_CodeSniffer_Tokens::$comparisonTokens) === true) {
                    // Just trying to compare a negative value; eg. ($var === -1).
                    return;
                }

                // A list of tokens that indicate that the token is not
                // part of an arithmetic operation.
                $invalidTokens = [
                    T_COMMA,
                    T_OPEN_PARENTHESIS,
                    T_OPEN_SQUARE_BRACKET,
                    T_DOUBLE_ARROW,
                    T_COLON,
                    T_INLINE_THEN, // the ternary "?"
                    T_CASE,
                ];

                if (in_array($prevCode, $invalidTokens) === true) {
                    // Just trying to use a negative value; eg. myFunction($var, -2).
                    return;
                }

                $number = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);

                if (in_array($tokens[$number]['code'], array(T_LNUMBER, T_VARIABLE)) === true) {
                    $semi = $phpcsFile->findNext(T_WHITESPACE, ($number + 1), null, true);

                    if ($tokens[$semi]['code'] === T_SEMICOLON) {
                        if ($prev !== false && (in_array($tokens[$prev]['code'], PHP_CodeSniffer_Tokens::$assignmentTokens) === true)) {
                            // This is a negative assignment.
                            return;
                        }
                    }
                }
            }

            $operator = $tokens[$stackPtr]['content'];

            if ($tokens[($stackPtr - 1)]['code'] !== T_WHITESPACE) {
                $error = "Expected 1 space before \"$operator\"; 0 found";
                $phpcsFile->addError($error, $stackPtr, 'NoSpaceBefore');
            } elseif (strlen($tokens[($stackPtr - 1)]['content']) !== 1) {
                // Don't throw an error for assignments, because other standards allow
                // multiple spaces there to align multiple assignments.
                if (in_array($operatorCode, PHP_CodeSniffer_Tokens::$assignmentTokens) === false) {
                    $found = strlen($tokens[($stackPtr - 1)]['content']);
                    $error = sprintf('Expected 1 space before "%s"; %s found', $operator, $found);

                    $phpcsFile->addError($error, $stackPtr, 'SpacingBefore');
                }
            }

            if ($tokens[($stackPtr + 1)]['code'] !== T_WHITESPACE) {
                $error = "Expected 1 space after \"$operator\"; 0 found";
                $phpcsFile->addError($error, $stackPtr, 'NoSpaceAfter');
            } elseif (strlen($tokens[($stackPtr + 1)]['content']) !== 1) {
                $found = strlen($tokens[($stackPtr + 1)]['content']);
                $error = sprintf('Expected 1 space after "%s"; %s found', $operator, $found);

                $phpcsFile->addError($error, $stackPtr, 'SpacingAfter');
            }
        }
    }
159035
public function process(File $phpcsFile, $stackPtr)
    {
        $traitName    = $phpcsFile->getDeclarationName($stackPtr);
        $firstLetter  = $traitName[0];
        $secondLetter = $traitName[1];

        if ($firstLetter !== 'T' || $secondLetter === strtolower($secondLetter)) {
            $phpcsFile->addError(
                'Trait name is not prefixed with "T"',
                $stackPtr,
                'WrongPrefix'
            );
        }
    }