public function transform(StreamMetaData $metadata): string
    {
        $includeExpressionFinder = new NodeFinderVisitor([Include_::class]);

        // TODO: move this logic into walkSyntaxTree(Visitor $nodeVistor) method
        $traverser = new NodeTraverser();
        $traverser->addVisitor($includeExpressionFinder);
        $traverser->traverse($metadata->syntaxTree);

        /** @var Include_[] $includeExpressions */
        $includeExpressions = $includeExpressionFinder->getFoundNodes();

        if (empty($includeExpressions)) {
            return self::RESULT_ABSTAIN;
        }

        foreach ($includeExpressions as $includeExpression) {
            $startPosition = $includeExpression->getAttribute('startTokenPos');
            $endPosition   = $includeExpression->getAttribute('endTokenPos');

            $metadata->tokenStream[$startPosition][1] .= ' \\' . __CLASS__ . '::rewrite(';
            if ($metadata->tokenStream[$startPosition+1][0] === T_WHITESPACE) {
                unset($metadata->tokenStream[$startPosition+1]);
            }

            $metadata->tokenStream[$endPosition][1] .= ', __DIR__)';
        }

        return self::RESULT_TRANSFORMED;
    }
public function transform(StreamMetaData $metadata): string
    {
        $includeExpressionFinder = new NodeFinderVisitor([Include_::class]);

        // TODO: move this logic into walkSyntaxTree(Visitor $nodeVistor) method
        $traverser = new NodeTraverser();
        $traverser->addVisitor($includeExpressionFinder);
        $traverser->traverse($metadata->syntaxTree);

        /** @var Include_[] $includeExpressions */
        $includeExpressions = $includeExpressionFinder->getFoundNodes();

        if (empty($includeExpressions)) {
            return self::RESULT_ABSTAIN;
        }

        foreach ($includeExpressions as $includeExpression) {
            $startPosition = $includeExpression->getAttribute('startTokenPos');
            $endPosition   = $includeExpression->getAttribute('endTokenPos');

            $metadata->tokenStream[$startPosition][1] .= ' \\' . __CLASS__ . '::rewrite(';
            if ($metadata->tokenStream[$startPosition+1][0] === T_WHITESPACE) {
                unset($metadata->tokenStream[$startPosition+1]);
            }

            $metadata->tokenStream[$endPosition][1] .= ', __DIR__)';
        }

        return self::RESULT_TRANSFORMED;
    }
public function transform ( StreamMetaData $ metadata ) : string { $ includeExpressionFinder = new NodeFinderVisitor ( [ Include_ :: class ] ) ; // TODO: move this logic into walkSyntaxTree(Visitor $nodeVistor) method $ traverser = new NodeTraverser ( ) ; $ traverser -> addVisitor ( $ includeExpressionFinder ) ; $ traverser -> traverse ( $ metadata -> syntaxTree ) ; /** @var Include_[] $includeExpressions */ $ includeExpressions = $ includeExpressionFinder -> getFoundNodes ( ) ; if ( empty ( $ includeExpressions ) ) { return self :: RESULT_ABSTAIN ; } foreach ( $ includeExpressions as $ includeExpression ) { $ startPosition = $ includeExpression -> getAttribute ( 'startTokenPos' ) ; $ endPosition = $ includeExpression -> getAttribute ( 'endTokenPos' ) ; $ metadata -> tokenStream [ $ startPosition ] [ 1 ] .= ' \\' . __CLASS__ . '::rewrite(' ; if ( $ metadata -> tokenStream [ $ startPosition + 1 ] [ 0 ] === T_WHITESPACE ) { unset ( $ metadata -> tokenStream [ $ startPosition + 1 ] ) ; } $ metadata -> tokenStream [ $ endPosition ] [ 1 ] .= ', __DIR__)' ; } return self :: RESULT_TRANSFORMED ; }
Wrap all includes into rewrite filter

@return string See RESULT_XXX constants in the interface
Wrap all includes into rewrite filter