2017 © Pedro Peláez
 

library php-parser

Syntax parser with back porting down to previous versions.

image

bhittani/php-parser

Syntax parser with back porting down to previous versions.

  • Thursday, February 16, 2017
  • by bhittani
  • Repository
  • 1 Watchers
  • 0 Stars
  • 165 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 11 Versions
  • 4 % Grown

The README.md

PHP Parser Build Status

Syntax parser with back porting down to previous versions., (*1)

This library contains custom traversal visitors for use with nikic/PHP-Parser., (*2)

Table of contents

Install

This library may be consumed by using composer., (*3)

In your terminal, run:, (*4)

$ composer require bhittani/php-parser

Usage

To utilize this library make sure you understand how nikic/PHP-Parser parses code., (*5)

This library contains a set of node visitors to manipulate php code., (*6)

Group import to individual imports

Back ports php 7+ syntax code., (*7)

use Bhittani\PhpParser\GroupToSingleImportsVisitor;

$traverser->addVisitor(new GroupToSingleImportsVisitor);

which will convert, (*8)

use Grouped\Imports\{Acme, Foo\Bar}

into, (*9)

use Grouped\Imports\Acme;
use Grouped\Imports\Foo\Bar;

Splat calls to call_user_func_array

Back ports php 5.6+ syntax code., (*10)

use Bhittani\PhpParser\SplatToCallUserFuncArrayVisitor;

$traverser->addVisitor(new SplatToCallUserFuncArrayVisitor);

which will convert, (*11)

$val = my_func($a, 'b', ...$params);

into, (*12)

$val = call_user_func_array('my_func', array_merge(array(
    $a, 'b'
), $params));

Class constants to strings

Back ports php 5.5+ syntax code., (*13)

use Bhittani\PhpParser\ClassConstToStrVisitor;

$traverser->addVisitor(new ClassConstToStrVisitor);

which will convert, (*14)

use Acme\Foo\Bar;

$barClass = Bar::class;

into, (*15)

use Acme\Foo\Bar;

$barClass = 'Acme\Foo\Bar';

Variadic to func_get_args

Back ports php 5.6+ syntax code., (*16)

use Bhittani\PhpParser\VariadicToFuncGetArgsVisitor;

$traverser->addVisitor(new VariadicToFuncGetArgsVisitor);

which will convert, (*17)

function my_func($a, $b, ...$params)
{
    // my_func code
}

into, (*18)

function my_func()
{
    $params = func_get_args();
    $a = array_shift($params);
    $b = array_shift($params);

    // my_func code
}

Remove imports

Removes all import statements., (*19)

use Bhittani\PhpParser\RemoveImportsVisitor;

$traverser->addVisitor(new RemoveImportsVisitor);

which will remove all use statements., (*20)

Append suffix

Appends a suffix to all imports, classes, traits, and interfaces., (*21)

use Bhittani\PhpParser\AppendSuffixVisitor;

$traverser->addVisitor(new AppendSuffixVisitor('_1'));

which will convert, (*22)

<?php

namespace Company\Package;

use Acme\Foo;
use Acme\Bar\{Beep, Boop};

interface Contract {}

abstract class AnAbstract {}

trait OurTrait {}

class Person extends AnAbstract implements Contract, AnotherContract
{
    use OurTrait;

    use Their\Trait;

    public function handle(Beep $beep, Model\User $age)
    {
        $foo = new Foo();
        $bar = new Bar();
        if ($beep->boop()) {
            throw new Exception('Error thrown.');
        }
    }
}

into, (*23)

<?php

namespace Company\Package;

use Acme\Foo_1 as Foo;
use Acme\Bar\{Beep_1 as Beep, Boop_1 as Boop};

interface Contract_1 {}

abstract class AnAbstract_1 {}

trait OurTrait_1 {}

class Person_1 extends AnAbstract_1 implements Contract_1, AnotherContract_1
{
    use OurTrait_1;

    use Their\Trait_1;

    public function handle(Beep $beep, Model\User_1 $age)
    {
        $foo = new Foo();
        $bar = new Bar_1();
        if ($beep->boop()) {
            throw new Exception('Error thrown.');
        }
    }
}

Notice that php's built-in entities won't be suffixed., (*24)

Test

Make sure you first CD into the library's root directory., (*25)

Do a composer install., (*26)

$ composer install

Run the tests., (*27)

$ vendor/bin/phpunit tests

or, (*28)

$ composer test

Credits

This library would not be possible without making use of nikic/PHP-Parser., (*29)

License

This library is released under the MIT License., (*30)

The Versions

16/02 2017

dev-master

9999999-dev http://github.com/kamalkhan/php-parser

Syntax parser with back porting down to previous versions.

  Sources   Download

MIT

The Requires

 

The Development Requires

parser syntax back-porting

16/02 2017

0.1.9

0.1.9.0 http://github.com/kamalkhan/php-parser

Syntax parser with back porting down to previous versions.

  Sources   Download

MIT

The Requires

 

The Development Requires

parser syntax back-porting

15/02 2017

0.1.8

0.1.8.0 http://github.com/kamalkhan/php-parser

Syntax parser with back porting down to previous versions.

  Sources   Download

MIT

The Requires

 

The Development Requires

parser syntax back-porting

14/02 2017

0.1.7

0.1.7.0 http://github.com/kamalkhan/php-parser

Syntax parser with back porting down to previous versions.

  Sources   Download

MIT

The Requires

 

The Development Requires

parser syntax back-porting

12/02 2017

0.1.6

0.1.6.0 http://github.com/kamalkhan/php-parser

Syntax parser with back porting down to previous versions.

  Sources   Download

MIT

The Requires

 

The Development Requires

parser syntax back-porting

15/12 2016

0.1.5

0.1.5.0 http://github.com/kamalkhan/php-parser

Syntax parser with back porting down to previous versions.

  Sources   Download

MIT

The Requires

 

The Development Requires

parser syntax back-porting

15/12 2016

0.1.4

0.1.4.0 http://github.com/kamalkhan/php-parser

Syntax parser with back porting down to previous versions.

  Sources   Download

MIT

The Requires

 

The Development Requires

parser syntax back-porting

15/12 2016

0.1.3

0.1.3.0 http://github.com/kamalkhan/php-parser

Syntax parser with back porting down to previous versions.

  Sources   Download

MIT

The Requires

 

The Development Requires

parser syntax back-porting

15/12 2016

0.1.2

0.1.2.0 http://github.com/kamalkhan/php-parser

Syntax parser with back porting down to previous versions.

  Sources   Download

MIT

The Requires

 

The Development Requires

parser syntax back-porting

14/12 2016

0.1.0

0.1.0.0 http://github.com/kamalkhan/php-parser

Syntax parser with back porting down to previous versions.

  Sources   Download

MIT

The Requires

 

The Development Requires

parser syntax back-porting

14/12 2016

0.1.1

0.1.1.0 http://github.com/kamalkhan/php-parser

Syntax parser with back porting down to previous versions.

  Sources   Download

MIT

The Requires

 

The Development Requires

parser syntax back-porting