PHPackages                             tcopestake/php-parser-psr-2-pretty-printer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. tcopestake/php-parser-psr-2-pretty-printer

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

tcopestake/php-parser-psr-2-pretty-printer
==========================================

A PSR-2 pretty printer for PHP-Parser.

41452PHP

Since Aug 30Pushed 6y ago2 watchersCompare

[ Source](https://github.com/tcopestake/PHP-Parser-PSR-2-pretty-printer)[ Packagist](https://packagist.org/packages/tcopestake/php-parser-psr-2-pretty-printer)[ RSS](/packages/tcopestake-php-parser-psr-2-pretty-printer/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (3)Used By (0)

PHP-Parser PSR-2 pretty printer
===============================

[](#php-parser-psr-2-pretty-printer)

##### Unsurprisingly, a PSR-2 pretty printer for [PHP-Parser](https://github.com/nikic/PHP-Parser).

[](#unsurprisingly-a-psr-2-pretty-printer-for-php-parser)

Installation
------------

[](#installation)

### Composer

[](#composer)

Add the package to your composer.json requirements e.g.

```
"require": {
    "tcopestake/php-parser-psr-2-pretty-printer": "dev-release"
}

```

Usage
-----

[](#usage)

To use this pretty printer, instantiate `PHPParserPSR2_Printer` instead of (for example) `PHPParser_PrettyPrinter_Default` and use it as you would normally. e.g:

```
$printer = new PHPParserPSR2_Printer;

...

echo $printer->prettyPrint($stmts);

```

Features
--------

[](#features)

Intentional changes that differ from the default pretty printer are:

- If more than one interface is implemented, each definition will go on a new line.
- Space between "use" and parameters in closure definitions.
- If more than two parameters are defined for a method, each definition goes on a new line.
- If more than two arguments are passed to a method, each argument goes on a new line.
- **Optional** method renaming. (see below)

Method renaming
---------------

[](#method-renaming)

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:

```
protected function do_something() {
    return 1 + 1;
}

function get_class_to_do_something() {
    return $this->do_something();
}

```

becomes:

```
protected function doSomething()
{
    return 1 + 1;
}

public function getClassToDoSomething()
{
    return $this->doSomething();
}

```

Example
-------

[](#example)

Input:

```
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:

```
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) {

        }
    }

}

```

License
-------

[](#license)

MIT

###  Health Score

25

—

LowBetter than 36% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/b15461d1c72035566fa4224e8b8dcafec816c1c6cfd74b994eacb18d03b131da?d=identicon)[tcopestake](/maintainers/tcopestake)

---

Top Contributors

[![tcopestake](https://avatars.githubusercontent.com/u/3993027?v=4)](https://github.com/tcopestake "tcopestake (7 commits)")[![ajthinking](https://avatars.githubusercontent.com/u/3457668?v=4)](https://github.com/ajthinking "ajthinking (1 commits)")

### Embed Badge

![Health badge](/badges/tcopestake-php-parser-psr-2-pretty-printer/health.svg)

```
[![Health](https://phpackages.com/badges/tcopestake-php-parser-psr-2-pretty-printer/health.svg)](https://phpackages.com/packages/tcopestake-php-parser-psr-2-pretty-printer)
```

###  Alternatives

[aura/di

A serializable dependency injection container with constructor and setter injection, interface and trait awareness, configuration inheritance, and much more.

352982.2k60](/packages/aura-di)[maclof/kubernetes-client

A simple yet elegant client for accessing and controlling a Kubernetes cluster.

234907.8k4](/packages/maclof-kubernetes-client)[icamys/php-sitemap-generator

Simple PHP sitemap generator.

175356.9k7](/packages/icamys-php-sitemap-generator)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
