private function processCatchToken(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // Bow out during live coding.
        if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) {
            return;
        }

        $opener = $tokens[$stackPtr]['parenthesis_opener'];
        $closer = ($tokens[$stackPtr]['parenthesis_closer'] + 1);
        $name   = '';
        $listen = array(
            // Parts of a (namespaced) class name.
            \T_STRING              => true,
            \T_NS_SEPARATOR        => true,
            // End/split tokens.
            \T_VARIABLE            => false,
            \T_BITWISE_OR          => false,
            \T_CLOSE_CURLY_BRACKET => false, // Shouldn't be needed as we expect a var before this.
        );

        for ($i = ($opener + 1); $i < $closer; $i++) {
            if (isset($listen[$tokens[$i]['code']]) === false) {
                continue;
            }

            if ($listen[$tokens[$i]['code']] === true) {
                $name .= $tokens[$i]['content'];
                continue;
            } else {
                if (empty($name) === true) {
                    // Weird, we should have a name by the time we encounter a variable or |.
                    // So this may be the closer.
                    continue;
                }

                $name   = ltrim($name, '\\');
                $nameLC = strtolower($name);

                if (isset($this->newExceptions[$nameLC]) === true) {
                    $itemInfo = array(
                        'name'   => $name,
                        'nameLc' => $nameLC,
                    );
                    $this->handleFeature($phpcsFile, $i, $itemInfo);
                }

                // Reset for a potential multi-catch.
                $name = '';
            }
        }
    }
private function processCatchToken(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // Bow out during live coding.
        if (isset($tokens[$stackPtr]['parenthesis_opener'], $tokens[$stackPtr]['parenthesis_closer']) === false) {
            return;
        }

        $opener = $tokens[$stackPtr]['parenthesis_opener'];
        $closer = ($tokens[$stackPtr]['parenthesis_closer'] + 1);
        $name   = '';
        $listen = array(
            // Parts of a (namespaced) class name.
            \T_STRING              => true,
            \T_NS_SEPARATOR        => true,
            // End/split tokens.
            \T_VARIABLE            => false,
            \T_BITWISE_OR          => false,
            \T_CLOSE_CURLY_BRACKET => false, // Shouldn't be needed as we expect a var before this.
        );

        for ($i = ($opener + 1); $i < $closer; $i++) {
            if (isset($listen[$tokens[$i]['code']]) === false) {
                continue;
            }

            if ($listen[$tokens[$i]['code']] === true) {
                $name .= $tokens[$i]['content'];
                continue;
            } else {
                if (empty($name) === true) {
                    // Weird, we should have a name by the time we encounter a variable or |.
                    // So this may be the closer.
                    continue;
                }

                $name   = ltrim($name, '\\');
                $nameLC = strtolower($name);

                if (isset($this->newExceptions[$nameLC]) === true) {
                    $itemInfo = array(
                        'name'   => $name,
                        'nameLc' => $nameLC,
                    );
                    $this->handleFeature($phpcsFile, $i, $itemInfo);
                }

                // Reset for a potential multi-catch.
                $name = '';
            }
        }
    }
private function processCatchToken ( File $ phpcsFile , $ stackPtr ) { $ tokens = $ phpcsFile -> getTokens ( ) ; // Bow out during live coding. if ( isset ( $ tokens [ $ stackPtr ] [ 'parenthesis_opener' ] , $ tokens [ $ stackPtr ] [ 'parenthesis_closer' ] ) === false ) { return ; } $ opener = $ tokens [ $ stackPtr ] [ 'parenthesis_opener' ] ; $ closer = ( $ tokens [ $ stackPtr ] [ 'parenthesis_closer' ] + 1 ) ; $ name = '' ; $ listen = array ( // Parts of a (namespaced) class name. \ T_STRING => true , \ T_NS_SEPARATOR => true , // End/split tokens. \ T_VARIABLE => false , \ T_BITWISE_OR => false , \ T_CLOSE_CURLY_BRACKET => false , // Shouldn't be needed as we expect a var before this. ) ; for ( $ i = ( $ opener + 1 ) ; $ i < $ closer ; $ i ++ ) { if ( isset ( $ listen [ $ tokens [ $ i ] [ 'code' ] ] ) === false ) { continue ; } if ( $ listen [ $ tokens [ $ i ] [ 'code' ] ] === true ) { $ name .= $ tokens [ $ i ] [ 'content' ] ; continue ; } else { if ( empty ( $ name ) === true ) { // Weird, we should have a name by the time we encounter a variable or |. // So this may be the closer. continue ; } $ name = ltrim ( $ name , '\\' ) ; $ nameLC = strtolower ( $ name ) ; if ( isset ( $ this -> newExceptions [ $ nameLC ] ) === true ) { $ itemInfo = array ( 'name' => $ name , 'nameLc' => $ nameLC , ) ; $ this -> handleFeature ( $ phpcsFile , $ i , $ itemInfo ) ; } // Reset for a potential multi-catch. $ name = '' ; } } }
Processes this test for when a catch token is encountered.

- Detect exceptions when used in a catch statement.

@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
Processes this test for when a catch token is encountered .