Skip to content

Support: How to parse a statement and methods #1078

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

Open
tacman opened this issue Mar 26, 2025 · 2 comments
Open

Support: How to parse a statement and methods #1078

tacman opened this issue Mar 26, 2025 · 2 comments

Comments

@tacman
Copy link

tacman commented Mar 26, 2025

What an amazing tool! I rarely use it directly, but many of the tools I use depend on it.

But today I'm trying to use it directly, and stuck on how to loop through a $stmt.

    public function testDemo(): void
    {
        $browser = $this->pantherBrowser()
            ->visit('/')
            ->assertOn('/')
            ->takeScreenshot('home.png')
            ->visit('/en/batsi#tab-locations')
            ->takeScreenshot('basti-locations.png')
        ;
        $browser
            ->click('#tab-artists')
            ->takeScreenshot('artists.png')
            ;
    }

I want to loop through each statement and get back each method call, along with its parameters.

Can anyone point me in the right direction? Thx.

@staabm
Copy link
Contributor

staabm commented Mar 26, 2025

I would put the code in question into a web-ui e.g. https://phpast.com/ or https://getrector.com/ast which generates a "clickable-ast".

that way you get an overview how the code is represented in AST and how you can access all the required information.

depending on what you need, you usually use addVisitor and NodeTraverser (see readme of this project) and collect all you need

@tacman
Copy link
Author

tacman commented Mar 26, 2025

Thanks!

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

2 participants