Introducing Play with AST page

Do you want to know what the AST structure from a PHP Source code? The getrector.com will help you with new interactive form.

Even for experienced Rector users, manual trial and error may be needed to decide which Node to use when creating a new Rector rule or refactoring an existing one. We are here to help you so that you can play before deciding which Node you want to use to refactor your code.

We created a new "Play with AST" page for you: https://getrector.com/ast, that you can:

  • Insert a PHP source code
  • Get All AST structure from the source code
  • Get Only AST structure for part of the code (click a part of the PHP source code)
  • Get node types can be used on Rector::getNodeTypes()

You can start with open https://getrector.com/ast, and insert a sample code, for example:

<?php

function foo()
{
    return 1;
}

Then, you can click the Show me button, then you can get the AST structure:


The source code on the first block is clickable; for example, you can click the "return" part:

Then, you will get the AST structure of return and node usage that can be used for creating custom rules:

That's it!


Happy coding!