dev-master
9999999-devA PSR-2 pretty printer for PHP-Parser.
The Requires
- php >=5.2
- nikic/php-parser *
dev-release
dev-releaseA PSR-2 pretty printer for PHP-Parser.
The Requires
- php >=5.2
- nikic/php-parser *
Wallogit.com
2017 © Pedro Peláez
A PSR-2 pretty printer for PHP-Parser.
Add the package to your composer.json requirements e.g., (*1)
"require": {
"tcopestake/php-parser-psr-2-pretty-printer": "dev-release"
}
To use this pretty printer, instantiate PHPParserPSR2_Printer instead of (for example) PHPParser_PrettyPrinter_Default and use it as you would normally. e.g:, (*2)
$printer = new PHPParserPSR2_Printer; ... echo $printer->prettyPrint($stmts);
Intentional changes that differ from the default pretty printer are:, (*3)
By default, method names are considered volatile and are therefore not renamed. However, if you're feeling brave you can call setMethodsVolatile(false) to have the printer convert snake-cased method names to camel case. For example:, (*4)
protected function do_something() {
return 1 + 1;
}
function get_class_to_do_something() {
return $this->do_something();
}
becomes:, (*5)
protected function doSomething()
{
return 1 + 1;
}
public function getClassToDoSomething()
{
return $this->doSomething();
}
Input:, (*6)
class ABC extends \A implements \B, \C {
public function a_method_name($awefwefwef, $ywefwefwefwefwef, $wwefwefwefwefwe) {
$x = function() use($awefwefwef, $wwefwefwefwefwe)
{
if(1==1)
return $ywefwefwefwefwef;
};
// do something
echo $x;
}
function bxy(array $g)
{
// do something
return $this->a_method_name($g, $f, $x);
}
function z(array $g)
{
foreach($y as $n)
{
}
}
}
Output:, (*7)
class ABC extends \A implements
\B,
\C
{
public function aMethodName(
$awefwefwef,
$ywefwefwefwefwef,
$wwefwefwefwefwe
) {
$x = function () use ($awefwefwef, $wwefwefwefwefwe) {
if (1 == 1) {
return $ywefwefwefwefwef;
}
};
// do something
echo $x;
}
public function bxy(array $g)
{
// do something
return $this->aMethodName(
$g,
$f,
$x
);
}
public function z(array $g)
{
foreach ($y as $n) {
}
}
}
MIT, (*8)
A PSR-2 pretty printer for PHP-Parser.
A PSR-2 pretty printer for PHP-Parser.