PHPackages                             mmoreram/php-formatter - 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. mmoreram/php-formatter

AbandonedArchivedLibrary

mmoreram/php-formatter
======================

PHP custom formatter

v1.3.3(8y ago)169160.6k—8%17[1 PRs](https://github.com/mmoreram/php-formatter/pulls)20MITPHPPHP &gt;=7.0

Since Jul 31Pushed 4y ago10 watchersCompare

[ Source](https://github.com/mmoreram/php-formatter)[ Packagist](https://packagist.org/packages/mmoreram/php-formatter)[ RSS](/packages/mmoreram-php-formatter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (9)Versions (15)Used By (20)

PHP Formatter
=============

[](#php-formatter)

[![Build Status](https://camo.githubusercontent.com/3c7c913496f3ff0db461419c9b539164a74e78853922f2baa66ebf179e4b9b62/68747470733a2f2f7472617669732d63692e6f72672f6d6d6f726572616d2f7068702d666f726d61747465722e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/mmoreram/php-formatter)

This PHP formatter aims to provide you some bulk actions for you PHP projects to ensure their consistency. None of them fixes PSR rules. If you want to fix PSR rules, please check [friendsofphp/php-cs-fixer](https://github.com/friendsofphp/PHP-CS-Fixer).

Install
-------

[](#install)

Install PHP Formatter in this way:

```
$ composer global require mmoreram/php-formatter=dev-master
```

If it is the first time you globally install a dependency then make sure you include `~/.composer/vendor/bin` in $PATH as shown [here](http://getcomposer.org/doc/03-cli.md#global).

### Always keep your PHP Formatter installation up to date:

[](#always-keep-your-php-formatter-installation-up-to-date)

```
$ composer global update mmoreram/php-formatter
```

### .phar file

[](#phar-file)

You can also use already last built `.phar`.

```
$ git clone git@github.com:mmoreram/php-formatter.git
$ cd php-formatter
$ php build/php-formatter.phar
```

You can copy the `.phar` file as a global script

```
$ cp build/php-formatter.phar /usr/local/bin/php-formatter
```

### Compile

[](#compile)

Finally you can also compile your own version of the package. ( You need set `phar.readonly = Off` in your php.ini ). For the compilation of this package you need the [box-project/box2](https://github.com/box-project/box2) library.

```
$ git clone git@github.com:mmoreram/php-formatter.git
$ cd php-formatter
$ composer update --no-dev
$ box build -v
$ build/php-formatter.phar
```

You can copy the `.phar` file as a global script

```
$ cp build/php-formatter.phar /usr/local/bin/php-formatter
```

Config
------

[](#config)

You can place a file named `.formatter.yml` in the root of your project. In every command execution, this will be the priority of the definitions.

If an option is set in the command, this will be used. Otherwise, if is defined in a found config file, this will be used. Otherwise, default value will be used.

This is the config reference

```
use-sort:
    group:
        - _main
        - Mmoreram
    group-type: each
    sort-type: alph
    sort-direction: asc

strict: ~
header: |
    /*
     * This file is part of the php-formatter package
     *
     * Copyright (c) 2014 Marc Morera
     *
     * For the full copyright and license information, please view the LICENSE
     * file that was distributed with this source code.
     *
     * Feel free to edit as you please, and have fun.
     *
     * @author Marc Morera
     */
```

you can also define where to search the `.formatter.yml` file using the `--config|-c` option

```
$ php-formatter formatter:use:sort src/ --config="src/"
```

Commands
--------

[](#commands)

PHP Formatter is a set of commands useful for your PHP projects. They do not consider any kind of Common Coding Standard, like PSR-0 or PSR-1, is more like a useful way of working for developers and reviewers.

```
Console Tool

Usage:
  [options] command [arguments]

Options:
  --help           -h Display this help message.
  --quiet          -q Do not output any message.
  --verbose        -v|vv|vvv Increase the verbosity of messages
  --version        -V Display this application version.
  --ansi              Force ANSI output.
  --no-ansi           Disable ANSI output.
  --no-interaction -n Do not ask any interactive question.

Available commands:
  help                   Displays help for a command
  list                   Lists commands
formatter
  formatter:header:fix  Ensures that all PHP files has header defined in config file
  formatter:strict:fix  Ensures that all PHP files have strict mode defined in config file. Only valid for >=PHP7.0
  formatter:use:sort    Sort Use statements
```

### Sort all Use Statements

[](#sort-all-use-statements)

You can sort your Use Statements in different ways. For this command you must provide as an argument the path where to look for the PHP files you want to process.

- command: `php-formatter formatter:use:sort`
- argument: path
- option: --exclude \[***multiple***\]
- option: --group \[***multiple***\]
- option: --group-type=***one***|***each***
- option: --sort-type=***alph***|***length***
- option: --sort-direction=***asc***|***desc***
- option: --dry-run \[***no value***\]

#### Group

[](#group)

You can sort your Use statements using as many groups as you want (***--group***). It means that you can group lines with same root (***Symfony\\***) in a specific order.

Common group is named `_main` and if is not specified, is placed in the beginning. You can define where to place this group with the `--group` option

```
$ php-formatter formatter:use:sort src/ --group="Mmoreram" --group="_main" --group="Symfony"
```

This command will sort the code like this

```
use Mmoreram\MyClass;
use Mmoreram\MySecondClass;

use OneBundle\OneClass;
use AnotherBundle\AnotherClass;

use Symfony\OneClass;
use Symfony\AnotherClass;
```

As you can see, a blank line is placed between groups. If any group is defined, one big group is created with all namespaces.

When using a `.formatter.yml` you can also specify subgroups by entering an array

```
use-sort:
    group:
        - [Symfony\Component\HttpKernel, Symfony]
        - _main
```

This will create a Symfony group placing all `Symfony\Component\HttpKernel` classes on top.

Finally, the `--group-type` defines if you want one `use` literal in every namespace line

```
$ php-formatter formatter:use:sort src/ --group="Mmoreram" --group-type="each"
```

This command will sort the code like this

```
use AnotherBundle\AnotherClass;
use OneBundle\OneClass;
use Symfony\AnotherClass;
use Symfony\OneClass;

use Mmoreram\MyClass;
use Mmoreram\MySecondClass;
```

or if you want only one use for all groups.

```
$ php-formatter formatter:use:sort src/ --group="Mmoreram" --group-type="one"
```

This command will sort the code like this

```
use AnotherBundle\AnotherClass,
    OneBundle\OneClass,
    Symfony\AnotherClass,
    Symfony\OneClass;

use Mmoreram\MyClass,
    Mmoreram\MySecondClass;
```

#### Sort

[](#sort)

There are two options of sorting. You can sort your namespaces alphabetically ***(default value)***

```
$ php-formatter formatter:use:sort src/ --sort-type="alph"
```

This command will sort the code like this

```
use AnotherBundle\AnotherClass;
use Mmoreram\MyClass;
use Mmoreram\MySecondClass;
use OneBundle\OneClass;
use Symfony\AnotherClass;
use Symfony\OneClass;
```

or by length (two namespaces with same length will be sorted alphabetically)

```
$ php-formatter formatter:use:sort src/ --sort-type="length"
```

This command will sort the code like this

```
use AnotherBundle\AnotherClass;
use Mmoreram\MySecondClass;
use Symfony\AnotherClass;
use OneBundle\OneClass;
use Mmoreram\MyClass;
use Symfony\OneClass;
```

You can also define the direction of the sorting. This can be ascending ***(default value)***

```
$ php-formatter formatter:use:sort src/ --sort-direction="asc"
```

This command will sort the code like this

```
use AnotherBundle\AnotherClass;
use Mmoreram\MyClass;
use Mmoreram\MySecondClass;
use OneBundle\OneClass;
use Symfony\AnotherClass;
use Symfony\OneClass;
```

or descending

```
$ php-formatter formatter:use:sort src/ --sort-direction="desc"
```

This command will sort the code like this

```
use Symfony\OneClass;
use Symfony\AnotherClass;
use OneBundle\OneClass;
use Mmoreram\MySecondClass;
use Mmoreram\MyClass;
use AnotherBundle\AnotherClass;
```

### Fix all PHP headers

[](#fix-all-php-headers)

You can define your PHP header in your `.formatter.yml` file and this command will check and fix that all PHP files have it properly.

- command: `php-formatter formatter:header:fix`
- argument: path
- option: --exclude \[***multiple***\]
- option: --dry-run \[***no value***\]

### Fix all strict declarations

[](#fix-all-strict-declarations)

In your &gt;=7.0 PHP applications you can use simple type declarations in your methods. You can define your application as relaxed as you want by declaring the `strict_mode` variable in your files. Each php file must be configured itself, so in order to make sure all your files have the definition after the header if exists and before the namespace declaration, you can use this command.

- command: `php-formatter formatter:strict:fix`
- argument: path
- option: --exclude \[***multiple***\]
- option: --dry-run \[***no value***\]

You can have three values here. If you define a boolean, then each file found will have the declaration with the boolean given.

```
strict: true
```

Otherwise, if you define a '~' value then your declaration lines will be removed.

```
strict: '~'
```

Exclude folders/files
---------------------

[](#exclude-foldersfiles)

You can exclude folders and files by using the multi-option `--exclude` as many times as you need. This option works the same way the Symfony component [Finder](http://symfony.com/doc/current/components/finder.html) works, so to make sure you properly understand the way this option works, just check the documentation.

```
$ php-formatter formatter:header:fix src/ --exclude="vendor"
```

In that case, maybe the most used way, you will exclude all vendors from your process.

Dry run
-------

[](#dry-run)

You can use this tool just to test the files will be modified, using option --dry-run

```
$ php-formatter formatter:use:sort src/ --dry-run
```

Any command from this library will never have any impact in your code as long as you have defined this option.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity48

Moderate usage in the ecosystem

Community36

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 65.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.

###  Release Activity

Cadence

Every ~94 days

Total

14

Last Release

3087d ago

PHP version history (4 changes)v1.0.0PHP &gt;=5.3.3

v1.0.0.1PHP &gt;=5.4

v1.1.0PHP ^5.4|^7.0

v1.2.0PHP &gt;=7.0

### Community

Maintainers

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

---

Top Contributors

[![mmoreram](https://avatars.githubusercontent.com/u/521409?v=4)](https://github.com/mmoreram "mmoreram (38 commits)")[![jakzal](https://avatars.githubusercontent.com/u/190447?v=4)](https://github.com/jakzal "jakzal (6 commits)")[![hacfi](https://avatars.githubusercontent.com/u/428841?v=4)](https://github.com/hacfi "hacfi (6 commits)")[![jumbojett](https://avatars.githubusercontent.com/u/410057?v=4)](https://github.com/jumbojett "jumbojett (2 commits)")[![javiereguiluz](https://avatars.githubusercontent.com/u/73419?v=4)](https://github.com/javiereguiluz "javiereguiluz (1 commits)")[![desarrolla2](https://avatars.githubusercontent.com/u/661529?v=4)](https://github.com/desarrolla2 "desarrolla2 (1 commits)")[![matt-usurp](https://avatars.githubusercontent.com/u/1379839?v=4)](https://github.com/matt-usurp "matt-usurp (1 commits)")[![mhor](https://avatars.githubusercontent.com/u/4103719?v=4)](https://github.com/mhor "mhor (1 commits)")[![mickaelandrieu](https://avatars.githubusercontent.com/u/1247388?v=4)](https://github.com/mickaelandrieu "mickaelandrieu (1 commits)")[![hkdobrev](https://avatars.githubusercontent.com/u/506129?v=4)](https://github.com/hkdobrev "hkdobrev (1 commits)")

---

Tags

namespacephpphp-formattersortphpformatter

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/mmoreram-php-formatter/health.svg)

```
[![Health](https://phpackages.com/badges/mmoreram-php-formatter/health.svg)](https://phpackages.com/packages/mmoreram-php-formatter)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19562.3M1.3k](/packages/drupal-core)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)

PHPackages © 2026

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