public/phpmyadmin/vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php
/**
     * Add and fix the missing brackets error.
     *
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
     * @param int                         $stackPtr  The position of the current token in the
     *                                               stack passed in $tokens.
     *
     * @return void
     */
Add and fix the missing brackets error.
@param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
@param int                         $stackPtr  The position of the current token in the
stack passed in $tokens.

@return void
Add and fix the missing brackets error . @param \ PHP_CodeSniffer \ Files \ File $phpcsFile The file being scanned . @param int $stackPtr The position of the current token in the stack passed in $tokens . @return void
public function addMissingBracketsError($phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $allowed = [
            T_VARIABLE                 => true,
            T_LNUMBER                  => true,
            T_DNUMBER                  => true,
            T_STRING                   => true,
            T_CONSTANT_ENCAPSED_STRING => true,
            T_WHITESPACE               => true,
            T_NS_SEPARATOR             => true,
            T_THIS                     => true,
            T_SELF                     => true,
            T_OBJECT_OPERATOR          => true,
            T_DOUBLE_COLON             => true,
            T_MODULUS                  => true,
            T_ISSET                    => true,
            T_ARRAY                    => true,
            T_NONE                     => true,
        ];
        for ($before = ($stackPtr - 1); $before > 0; $before--) {
            if ($phpcsFile->tokenizerType === 'JS' && $tokens[$before]['code'] === T_PLUS) {
                break;
            }
            if (isset(Tokens::$emptyTokens[$tokens[$before]['code']]) === true
                || isset(Tokens::$operators[$tokens[$before]['code']]) === true
                || isset(Tokens::$castTokens[$tokens[$before]['code']]) === true
                || isset($allowed[$tokens[$before]['code']]) === true
            ) {
                continue;
            }
            if ($tokens[$before]['code'] === T_CLOSE_PARENTHESIS) {
                $before = $tokens[$before]['parenthesis_opener'];
                continue;
            }
            if ($tokens[$before]['code'] === T_CLOSE_SQUARE_BRACKET) {
                $before = $tokens[$before]['bracket_opener'];
                continue;
            }
            if ($tokens[$before]['code'] === T_CLOSE_SHORT_ARRAY) {
                $before = $tokens[$before]['bracket_opener'];
                continue;
            }
            break;
        }
        $before = $phpcsFile->findNext(Tokens::$emptyTokens, ($before + 1), null, true);
        for ($after = ($stackPtr + 1); $after < $phpcsFile->numTokens; $after++) {
            if ($phpcsFile->tokenizerType === 'JS' && $tokens[$after]['code'] === T_PLUS) {
                break;
            }
            if (isset(Tokens::$emptyTokens[$tokens[$after]['code']]) === true
                || isset(Tokens::$operators[$tokens[$after]['code']]) === true
                || isset(Tokens::$castTokens[$tokens[$after]['code']]) === true
                || isset($allowed[$tokens[$after]['code']]) === true
            ) {
                continue;
            }
            if ($tokens[$after]['code'] === T_OPEN_PARENTHESIS) {
                $after = $tokens[$after]['parenthesis_closer'];
                continue;
            }
            if ($tokens[$after]['code'] === T_OPEN_SQUARE_BRACKET) {
                $after = $tokens[$after]['bracket_closer'];
                continue;
            }
            if ($tokens[$after]['code'] === T_OPEN_SHORT_ARRAY) {
                $after = $tokens[$after]['bracket_closer'];
                continue;
            }
            break;
        }
        $after = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($after - 1), null, true);
        $error = 'Operation must be bracketed';
        if ($before === $after || $before === $stackPtr || $after === $stackPtr) {
            $phpcsFile->addError($error, $stackPtr, 'MissingBrackets');
            return;
        }
        $fix = $phpcsFile->addFixableError($error, $stackPtr, 'MissingBrackets');
        if ($fix === true) {
            $phpcsFile->fixer->beginChangeset();
            $phpcsFile->fixer->replaceToken($before, '('.$tokens[$before]['content']);
            $phpcsFile->fixer->replaceToken($after, $tokens[$after]['content'].')');
            $phpcsFile->fixer->endChangeset();
        }
    }
public function addMissingBracketsError ( $ phpcsFile , $ stackPtr ) { $ tokens = $ phpcsFile -> getTokens ( ) ; $ allowed = [ T_VARIABLE => true , T_LNUMBER => true , T_DNUMBER => true , T_STRING => true , T_CONSTANT_ENCAPSED_STRING => true , T_WHITESPACE => true , T_NS_SEPARATOR => true , T_THIS => true , T_SELF => true , T_OBJECT_OPERATOR => true , T_DOUBLE_COLON => true , T_MODULUS => true , T_ISSET => true , T_ARRAY => true , T_NONE => true , ] ; for ( $ before = ( $ stackPtr - 1 ) ; $ before > 0 ; $ before -- ) { if ( $ phpcsFile -> tokenizerType === 'JS' && $ tokens [ $ before ] [ 'code' ] === T_PLUS ) { break ; } if ( isset ( Tokens :: $ emptyTokens [ $ tokens [ $ before ] [ 'code' ] ] ) === true || isset ( Tokens :: $ operators [ $ tokens [ $ before ] [ 'code' ] ] ) === true || isset ( Tokens :: $ castTokens [ $ tokens [ $ before ] [ 'code' ] ] ) === true || isset ( $ allowed [ $ tokens [ $ before ] [ 'code' ] ] ) === true ) { continue ; } if ( $ tokens [ $ before ] [ 'code' ] === T_CLOSE_PARENTHESIS ) { $ before = $ tokens [ $ before ] [ 'parenthesis_opener' ] ; continue ; } if ( $ tokens [ $ before ] [ 'code' ] === T_CLOSE_SQUARE_BRACKET ) { $ before = $ tokens [ $ before ] [ 'bracket_opener' ] ; continue ; } if ( $ tokens [ $ before ] [ 'code' ] === T_CLOSE_SHORT_ARRAY ) { $ before = $ tokens [ $ before ] [ 'bracket_opener' ] ; continue ; } break ; } $ before = $ phpcsFile -> findNext ( Tokens :: $ emptyTokens , ( $ before + 1 ) , null , true ) ; for ( $ after = ( $ stackPtr + 1 ) ; $ after < $ phpcsFile -> numTokens ; $ after ++ ) { if ( $ phpcsFile -> tokenizerType === 'JS' && $ tokens [ $ after ] [ 'code' ] === T_PLUS ) { break ; } if ( isset ( Tokens :: $ emptyTokens [ $ tokens [ $ after ] [ 'code' ] ] ) === true || isset ( Tokens :: $ operators [ $ tokens [ $ after ] [ 'code' ] ] ) === true || isset ( Tokens :: $ castTokens [ $ tokens [ $ after ] [ 'code' ] ] ) === true || isset ( $ allowed [ $ tokens [ $ after ] [ 'code' ] ] ) === true ) { continue ; } if ( $ tokens [ $ after ] [ 'code' ] === T_OPEN_PARENTHESIS ) { $ after = $ tokens [ $ after ] [ 'parenthesis_closer' ] ; continue ; } if ( $ tokens [ $ after ] [ 'code' ] === T_OPEN_SQUARE_BRACKET ) { $ after = $ tokens [ $ after ] [ 'bracket_closer' ] ; continue ; } if ( $ tokens [ $ after ] [ 'code' ] === T_OPEN_SHORT_ARRAY ) { $ after = $ tokens [ $ after ] [ 'bracket_closer' ] ; continue ; } break ; } $ after = $ phpcsFile -> findPrevious ( Tokens :: $ emptyTokens , ( $ after - 1 ) , null , true ) ; $ error = 'Operation must be bracketed' ; if ( $ before === $ after || $ before === $ stackPtr || $ after === $ stackPtr ) { $ phpcsFile -> addError ( $ error , $ stackPtr , 'MissingBrackets' ) ; return ; } $ fix = $ phpcsFile -> addFixableError ( $ error , $ stackPtr , 'MissingBrackets' ) ; if ( $ fix === true ) { $ phpcsFile -> fixer -> beginChangeset ( ) ; $ phpcsFile -> fixer -> replaceToken ( $ before , '(' . $ tokens [ $ before ] [ 'content' ] ) ; $ phpcsFile -> fixer -> replaceToken ( $ after , $ tokens [ $ after ] [ 'content' ] . ')' ) ; $ phpcsFile -> fixer -> endChangeset ( ) ; } }
Add and fix the missing brackets error.
Add and fix the missing brackets error .
// Find the first token in the expression. // Special case for plus operators because we can't tell if they are used // for addition or string contact. So assume string concat to be safe. //end for // Find the last token in the expression. // Special case for plus operators because we can't tell if they are used // for addition or string concat. So assume string concat to be safe. //end for // Can only fix this error if both tokens are available for fixing. // Adding one bracket without the other will create parse errors.