Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BuilderFactory Node\Stmt\If_ miss semicolon #731

Closed
bytehello opened this issue Nov 6, 2020 · 1 comment
Closed

BuilderFactory Node\Stmt\If_ miss semicolon #731

bytehello opened this issue Nov 6, 2020 · 1 comment

Comments

@bytehello
Copy link

BASE INFO

php version

PHP 7.3.13 (cli) (built: Dec 26 2019 22:25:59) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.13, Copyright (c) 1998-2018 Zend Technologies

PHP-Parser version

nikic/php-parser                     v4.10.2            A PHP parser written in PHP  

MISS semicolon

below code can not show correct result

use PhpParser\Error;
use PhpParser\NodeDumper;
use PhpParser\ParserFactory;
use PhpParser\BuilderFactory;
use PhpParser\PrettyPrinter;
use PhpParser\Node;
use PhpParser\Node\Stmt\If_;

$factor = new BuilderFactory;
        $node = $factor->namespace('Name\Space')
            ->addStmt(
                $factor->class('SomeClass')
                ->addStmt($factor->method('check')
                ->makeProtected()
                ->addParam($factor->param('orderData'))
                ->addStmt(
                    new If_($factor->var('result'), [
                        'stmts' => array(
                            new Node\Expr\Print_(new Node\Expr\Variable('someParam'))
                        )
                    ])
                    )))
            ->getNode();
        $stmts = array($node);
        $prettyPrinter = new PrettyPrinter\Standard();
        echo $prettyPrinter->prettyPrintFile($stmts);

output :

<?php

namespace Name\Space;

class SomeClass
{
    protected function check($orderData)
    {
        if ($result) {
            print $someParam
        }
    }
}

NOTICE print $someParam miss semicolon

@bytehello
Copy link
Author

my falut; below is correct

new Node\Expr\Print_(new Node\Expr\Variable('someParam')) -> BuilderHelpers::normalizeStmt(new Node\Expr\Print_(new Node\Expr\Variable('someParam')))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant