src/Tokenizer/Transformer/TypeAlternationTransformer.php
public function process(Tokens $tokens, Token $token, $index)
    {
        if (!$token->equals('|')) {
            return;
        }

        $prevIndex = $tokens->getPrevMeaningfulToken($index);
        $prevToken = $tokens[$prevIndex];

        if (!$prevToken->isGivenKind(T_STRING)) {
            return;
        }

        do {
            $prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
            if (null === $prevIndex) {
                break;
            }

            $prevToken = $tokens[$prevIndex];

            if ($prevToken->isGivenKind([T_NS_SEPARATOR, T_STRING])) {
                continue;
            }

            if (
                $prevToken->isGivenKind(CT::T_TYPE_ALTERNATION)
                || (
                    $prevToken->equals('(')
                    && $tokens[$tokens->getPrevMeaningfulToken($prevIndex)]->isGivenKind(T_CATCH)
                )
            ) {
                $tokens[$index] = new Token([CT::T_TYPE_ALTERNATION, '|']);
            }

            break;
        } while (true);
    }
public function process(Tokens $tokens, Token $token, $index)
    {
        if (!$token->equals('|')) {
            return;
        }

        $prevIndex = $tokens->getPrevMeaningfulToken($index);
        $prevToken = $tokens[$prevIndex];

        if (!$prevToken->isGivenKind(T_STRING)) {
            return;
        }

        do {
            $prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
            if (null === $prevIndex) {
                break;
            }

            $prevToken = $tokens[$prevIndex];

            if ($prevToken->isGivenKind([T_NS_SEPARATOR, T_STRING])) {
                continue;
            }

            if (
                $prevToken->isGivenKind(CT::T_TYPE_ALTERNATION)
                || (
                    $prevToken->equals('(')
                    && $tokens[$tokens->getPrevMeaningfulToken($prevIndex)]->isGivenKind(T_CATCH)
                )
            ) {
                $tokens[$index] = new Token([CT::T_TYPE_ALTERNATION, '|']);
            }

            break;
        } while (true);
    }
public function process ( Tokens $ tokens , Token $ token , $ index ) { if ( ! $ token -> equals ( '|' ) ) { return ; } $ prevIndex = $ tokens -> getPrevMeaningfulToken ( $ index ) ; $ prevToken = $ tokens [ $ prevIndex ] ; if ( ! $ prevToken -> isGivenKind ( T_STRING ) ) { return ; } do { $ prevIndex = $ tokens -> getPrevMeaningfulToken ( $ prevIndex ) ; if ( null === $ prevIndex ) { break ; } $ prevToken = $ tokens [ $ prevIndex ] ; if ( $ prevToken -> isGivenKind ( [ T_NS_SEPARATOR , T_STRING ] ) ) { continue ; } if ( $ prevToken -> isGivenKind ( CT :: T_TYPE_ALTERNATION ) || ( $ prevToken -> equals ( '(' ) && $ tokens [ $ tokens -> getPrevMeaningfulToken ( $ prevIndex ) ] -> isGivenKind ( T_CATCH ) ) ) { $ tokens [ $ index ] = new Token ( [ CT :: T_TYPE_ALTERNATION , '|' ] ) ; } break ; } while ( true ) ; }
{@inheritdoc}
{