protected function extractNamespace(
        File $file
    ) {
        $namespace = '';

        $tokens = $file->getTokens();

        $prev = $file->findNext(T_NAMESPACE, 0);

        for ($i = $prev + 2; $i < count($tokens); $i++) {
            if (!in_array($tokens[$i]['code'], [T_STRING, T_NS_SEPARATOR])) {
                break;
            }

            $namespace .= $tokens[$i]['content'];
        }

        return $namespace;
    }
protected function extractNamespace(
        File $file
    ) {
        $namespace = '';

        $tokens = $file->getTokens();

        $prev = $file->findNext(T_NAMESPACE, 0);

        for ($i = $prev + 2; $i < count($tokens); $i++) {
            if (!in_array($tokens[$i]['code'], [T_STRING, T_NS_SEPARATOR])) {
                break;
            }

            $namespace .= $tokens[$i]['content'];
        }

        return $namespace;
    }
protected function extractNamespace ( File $ file ) { $ namespace = '' ; $ tokens = $ file -> getTokens ( ) ; $ prev = $ file -> findNext ( T_NAMESPACE , 0 ) ; for ( $ i = $ prev + 2 ; $ i < count ( $ tokens ) ; $ i ++ ) { if ( ! in_array ( $ tokens [ $ i ] [ 'code' ] , [ T_STRING , T_NS_SEPARATOR ] ) ) { break ; } $ namespace .= $ tokens [ $ i ] [ 'content' ] ; } return $ namespace ; }
Extract the first namespace found in the file.

@param PHP_CodeSniffer_File $file

@return string
Extract the first namespace found in the file .