Skip to content
Reverts the php-ast AST back into (somewhat) PSR-compliant code
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/AstReverter Use composer's autoloader Aug 10, 2017
tests Fix autoload file inclusion Aug 10, 2017
.gitignore Add .gitignore Aug 30, 2015
.travis.yml Ensure php-ast is installed on Travis Aug 10, 2017
LICENSE Initial commit Aug 26, 2015
README.md Document support for php-ast version 50 Aug 10, 2017
composer.json Use composer's autoloader Aug 10, 2017
phpunit.xml.dist Use composer's autoloader Aug 10, 2017

README.md

php-ast-reverter

A tool that reverts an abstract syntax tree (AST) produced by the php-ast extension back into (somewhat) PSR-compliant code. This enables for code preprocessing to be done.

Requirements:

  • PHP 7.*
  • php-ast extension (compatible with versions 30, 35, 40, 45, and 50)

Installation

Composer

composer require tpunt/php-ast-reverter

Example

Running the following code snippet:

<?php

$code = <<<'end'
<?php

/**
 * My testing class
 */
class ClassName extends AnotherClass implements AnInterface
{
    /**
     * Some property
     */
    private $prop = 0;

    const TEST = 'string';

    use TraitA, TraitB {
        TraitA::func1 insteadof TraitB;
        TraitB::func1 as protected func2;
    }

    /**
     * Some useless constructor
     */
    function __construct(int $arg = 1)
    {
        $this->prop = $arg;
    }
}
end;

$ast = ast\parse_code($code, $version=40);

echo (new AstReverter\AstReverter)->getCode($ast);

Will output:

<?php

/**
 * My testing class
 */
class ClassName extends AnotherClass implements AnInterface
{
    /**
     * Some property
     */
    private $prop = 0;
    const TEST = "string";
    use TraitA, TraitB {
        TraitA::func1 insteadof TraitB;
        TraitB::func1 as protected func2;
    }
    /**
     * Some useless constructor
     */
    public function __construct(int $arg = 1)
    {
        $this->prop = $arg;
    }
}
You can’t perform that action at this time.