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

        // Check for the existence of the token.
        if (isset($tokens[$stackPtr]) === false) {
            return '';
        }

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

        $start = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
        if ($start === false) {
            return '';
        }

        // Bow out if the next token is a variable as we don't know where it was defined.
        if ($tokens[$start]['code'] === \T_VARIABLE) {
            return '';
        }

        // Bow out if the next token is the class keyword.
        if ($tokens[$start]['type'] === 'T_ANON_CLASS' || $tokens[$start]['code'] === \T_CLASS) {
            return '';
        }

        $find = array(
            \T_NS_SEPARATOR,
            \T_STRING,
            \T_NAMESPACE,
            \T_WHITESPACE,
        );

        $end       = $phpcsFile->findNext($find, ($start + 1), null, true, null, true);
        $className = $phpcsFile->getTokensAsString($start, ($end - $start));
        $className = trim($className);

        return $this->getFQName($phpcsFile, $stackPtr, $className);
    }
public function getFQClassNameFromNewToken(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        // Check for the existence of the token.
        if (isset($tokens[$stackPtr]) === false) {
            return '';
        }

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

        $start = $phpcsFile->findNext(Tokens::$emptyTokens, $stackPtr + 1, null, true, null, true);
        if ($start === false) {
            return '';
        }

        // Bow out if the next token is a variable as we don't know where it was defined.
        if ($tokens[$start]['code'] === \T_VARIABLE) {
            return '';
        }

        // Bow out if the next token is the class keyword.
        if ($tokens[$start]['type'] === 'T_ANON_CLASS' || $tokens[$start]['code'] === \T_CLASS) {
            return '';
        }

        $find = array(
            \T_NS_SEPARATOR,
            \T_STRING,
            \T_NAMESPACE,
            \T_WHITESPACE,
        );

        $end       = $phpcsFile->findNext($find, ($start + 1), null, true, null, true);
        $className = $phpcsFile->getTokensAsString($start, ($end - $start));
        $className = trim($className);

        return $this->getFQName($phpcsFile, $stackPtr, $className);
    }
public function getFQClassNameFromNewToken ( File $ phpcsFile , $ stackPtr ) { $ tokens = $ phpcsFile -> getTokens ( ) ; // Check for the existence of the token. if ( isset ( $ tokens [ $ stackPtr ] ) === false ) { return '' ; } if ( $ tokens [ $ stackPtr ] [ 'code' ] !== \ T_NEW ) { return '' ; } $ start = $ phpcsFile -> findNext ( Tokens :: $ emptyTokens , $ stackPtr + 1 , null , true , null , true ) ; if ( $ start === false ) { return '' ; } // Bow out if the next token is a variable as we don't know where it was defined. if ( $ tokens [ $ start ] [ 'code' ] === \ T_VARIABLE ) { return '' ; } // Bow out if the next token is the class keyword. if ( $ tokens [ $ start ] [ 'type' ] === 'T_ANON_CLASS' || $ tokens [ $ start ] [ 'code' ] === \ T_CLASS ) { return '' ; } $ find = array ( \ T_NS_SEPARATOR , \ T_STRING , \ T_NAMESPACE , \ T_WHITESPACE , ) ; $ end = $ phpcsFile -> findNext ( $ find , ( $ start + 1 ) , null , true , null , true ) ; $ className = $ phpcsFile -> getTokensAsString ( $ start , ( $ end - $ start ) ) ; $ className = trim ( $ className ) ; return $ this -> getFQName ( $ phpcsFile , $ stackPtr , $ className ) ; }
Returns the fully qualified class name for a new class instantiation.

Returns an empty string if the class name could not be reliably inferred.

@param \PHP_CodeSniffer_File $phpcsFile The file being scanned.
@param int                   $stackPtr  The position of a T_NEW token.

@return string
Returns the fully qualified class name for a new class instantiation .