Skip to content

Trying to replace expression (Expr_FuncCall) with statement (Stmt_Echo) #8172

Answered by samsonasik
splitbrain asked this question in Q&A
Discussion options

You must be logged in to vote

You need to replace whole Expresssion for that:

First, define the node types as Expression stmt:

    public function getNodeTypes(): array
    {
        return [\PhpParser\Node\Stmt\Expression::class];
    }

Next, verify if the node expr is match with FuncCall

    /**
     * @param \PhpParser\Node\Stmt\Expression $node
     */
    public function refactor(Node $node): ?Node
    {
        if (! $node->expr instanceof \PhpParser\Node\Expr\FuncCall) {
            return null;
        }

        if (! $this->nodeNameResolver->isName($node->expr, 'ptln')) {
            return null;
        }

         // here replace with Echo_
         return new Echo_([
            $node->expr->args[0]->value

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@splitbrain
Comment options

Answer selected by samsonasik
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants