PHPackages                             lkrms/pretty-php - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. lkrms/pretty-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lkrms/pretty-php
================

The opinionated PHP code formatter

v0.4.95(5mo ago)14659.1k↓27.7%3[20 issues](https://github.com/lkrms/pretty-php/issues)1MITPHPPHP &gt;=7.4CI passing

Since Dec 19Pushed 5mo ago4 watchersCompare

[ Source](https://github.com/lkrms/pretty-php)[ Packagist](https://packagist.org/packages/lkrms/pretty-php)[ GitHub Sponsors](https://github.com/lkrms)[ RSS](/packages/lkrms-pretty-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (20)Versions (142)Used By (1)

pretty-php: the opinionated code formatter
==========================================

[](#pretty-php-the-opinionated-code-formatter)

 [ ![pretty-php logo](https://github.com/lkrms/pretty-php/raw/main/images/logo-600x600-rounded.png) ](https://github.com/lkrms/pretty-php)

 [![Latest Stable Version](https://camo.githubusercontent.com/a4d28b86981e94e40f41c71542b561514a1ffc13fac4392c65514a02bea2f554/68747470733a2f2f706f7365722e707567782e6f72672f6c6b726d732f7072657474792d7068702f76)](https://packagist.org/packages/lkrms/pretty-php) [![License](https://camo.githubusercontent.com/bf52381416366684d5e0d6b2f044a09d0df608843996dda819be5d57a219e701/68747470733a2f2f706f7365722e707567782e6f72672f6c6b726d732f7072657474792d7068702f6c6963656e7365)](https://packagist.org/packages/lkrms/pretty-php) [![CI Status](https://github.com/lkrms/pretty-php/actions/workflows/ci.yml/badge.svg)](https://github.com/lkrms/pretty-php/actions) [![Code Coverage](https://camo.githubusercontent.com/a5cc591005416fa1789c5edf6091e9d5fd6e1f15fcfc5a4ffb1193d30829a049/68747470733a2f2f636f6465636f762e696f2f67682f6c6b726d732f7072657474792d7068702f67726170682f62616467652e7376673f746f6b656e3d57304b565a553731384b)](https://codecov.io/gh/lkrms/pretty-php) [![Visual Studio Marketplace install count](https://camo.githubusercontent.com/dcc8cb1b682eb0120aabc2adf4980c277a407b3e625dac28ec389be426004988/68747470733a2f2f696d672e736869656c64732e696f2f76697375616c2d73747564696f2d6d61726b6574706c6163652f692f6c6b726d732e7072657474792d7068703f6c6162656c3d4d61726b6574706c616365253230696e7374616c6c7326636f6c6f723d253233303036366238)](https://marketplace.visualstudio.com/items?itemName=lkrms.pretty-php) [![Open VSX Registry download count](https://camo.githubusercontent.com/203c215efcf8dcf8db0125bf616eb0c81a314213adaf004f4708da0216c661d1/68747470733a2f2f696d672e736869656c64732e696f2f6f70656e2d7673782f64742f6c6b726d732f7072657474792d7068703f6c6162656c3d4f70656e253230565358253230646f776e6c6f61647326636f6c6f723d253233613630656535)](https://open-vsx.org/extension/lkrms/pretty-php)

---

`pretty-php` is a fast, deterministic, minimally configurable code formatter for PHP, written in PHP.

It looks after the whitespace in your code so you have more time and energy for the content.

Inspired by [Black](https://github.com/psf/black), `pretty-php` aims to produce the smallest diffs possible and for code to look the same regardless of the project you're working on, eliminating visual dissonance and improving the effectiveness of code review.

You can run `pretty-php` from the command line, use it in your [editor](#editor-integrations), add it to your CI workflows, pair it with your preferred linter, and more.

It has sensible defaults and runs without configuration.

If you have questions or feedback, I'd love to [hear from you](https://github.com/lkrms/pretty-php/discussions).

Features
--------

[](#features)

- Formats code written for **PHP 8.4** and below (when running on a compatible version of PHP), including [property hooks](https://wiki.php.net/rfc/property-hooks) introduced in PHP 8.4
- Code is formatted for **readability**, **consistency**, and **small diffs**
- **Previous formatting is ignored**, and nothing other than whitespace is changed (see [Pragmatism](#pragmatism) for exceptions)
- Entire files are formatted in place
- Formatting options are deliberately limited (`pretty-php` is opinionated so you don't have to be)
- Configuration via a simple JSON file is supported but not required
- Formatted and original code are compared for equivalence
- Compliant with [PSR-12](https://www.php-fig.org/psr/psr-12/) and [PER](https://www.php-fig.org/per/coding-style/) (see [PSR-12 compliance](docs/PSR-12.md) for details)
- Supports **Symfony**, **Drupal**, **Laravel** and **WordPress** code styles via presets

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

[](#installation)

### Requirements

[](#requirements)

- Linux, macOS or Windows
- PHP 8.4, 8.3, 8.2, 8.1, 8.0 or 7.4 with the standard `tokenizer`, `mbstring`and `json` extensions enabled

### PHP archive (PHAR)

[](#php-archive-phar)

`pretty-php` is distributed as a PHP archive you can download and run:

```
wget -O pretty-php.phar https://github.com/lkrms/pretty-php/releases/latest/download/pretty-php.phar
```

```
php pretty-php.phar --version
```

The PHAR can be made executable:

```
chmod +x pretty-php.phar
```

```
./pretty-php.phar --version
```

Official releases distributed via GitHub are signed and can be verified as follows:

```
wget -O pretty-php.phar https://github.com/lkrms/pretty-php/releases/latest/download/pretty-php.phar
wget -O pretty-php.phar.asc https://github.com/lkrms/pretty-php/releases/latest/download/pretty-php.phar.asc
gpg --recv-keys 0xE8CC5BC780B581F2
gpg --verify pretty-php.phar.asc pretty-php.phar
```

Installation with [PHIVE](https://phar.io), which verifies PHAR releases automatically, is also supported:

```
phive install lkrms/pretty-php
```

```
./tools/pretty-php --version
```

Adding `lkrms/pretty-php` to your project as a Composer dependency is not recommended. A separate API package will be provided in the future.

### Arch Linux

[](#arch-linux)

Arch Linux users can install `pretty-php` from the AUR. For example, if your preferred AUR helper is `yay`:

```
yay -S pretty-php
```

### macOS

[](#macos)

Homebrew users on macOS can install `pretty-php` using the following command, which automatically taps `lkrms/misc` if necessary:

```
brew install lkrms/misc/pretty-php
```

Usage
-----

[](#usage)

Once installed, getting started with `pretty-php` is as simple as giving it something to format. For example, to format `bootstrap.php` and any PHP files in the `src` directory:

```
pretty-php bootstrap.php src
```

To see what would change without actually replacing any files, add the `--diff`option:

```
pretty-php --diff bootstrap.php src
```

For detailed usage information, see [usage](docs/Usage.md) or run:

```
pretty-php --help
```

Editor integrations
-------------------

[](#editor-integrations)

- **pretty-php for Visual Studio Code**
    Official VS Code extension
    [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=lkrms.pretty-php) | [Open VSX Registry](https://open-vsx.org/extension/lkrms/pretty-php) | [Repository](https://github.com/lkrms/vscode-pretty-php)

Pragmatism
----------

[](#pragmatism)

`pretty-php` generally abides by its own rules ("previous formatting is ignored, and nothing other than whitespace is changed"), but exceptions are occasionally made and documented here.

- **Some newlines are preserved**
    Line breaks adjacent to most operators, delimiters and brackets are copied from the input to the output (see [Newlines](docs/Newlines.md) for details).

    Use `-N/--ignore-newlines`, `-O/--operators-first` or `-L/--operators-last` to disable or modify this behaviour.
- **Strings and numbers are normalised**
    Single-quoted strings are preferred unless the alternative is shorter or backslash escapes are required.

    Use `-S/--no-simplify-strings` and `-n/--no-simplify-numbers` to disable or modify this behaviour.
- **Imports are grouped and sorted by name, depth-first**
    See [Import sorting](docs/Imports.md) for details.

    Use `-M/--no-sort-imports` or `-m/--sort-imports-by` to disable or modify this behaviour.
- **Comments are moved if necessary for correct placement of adjacent tokens**
    Use `--disable=move-comments` to disable this behaviour.
- **Comments beside code are not moved to the next line**
- **Comments are trimmed and aligned**
- **Empty DocBlocks are removed**

License
-------

[](#license)

This project is licensed under the [MIT License](LICENSE).

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance69

Regular maintenance activity

Popularity46

Moderate usage in the ecosystem

Community13

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~7 days

Recently: every ~74 days

Total

140

Last Release

165d ago

PHP version history (6 changes)v0.1.0PHP &gt;=7.4,&lt;=8.2

v0.1.3PHP &gt;=7.4,&lt;8.3

v0.3.0PHP &gt;=8,&lt;8.3

v0.3.20PHP &gt;=8 &lt;8.3

v0.4.7PHP &gt;=7.4 &lt;8.3

v0.4.19PHP &gt;=7.4

### Community

Maintainers

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

---

Top Contributors

[![lkrms](https://avatars.githubusercontent.com/u/2563783?v=4)](https://github.com/lkrms "lkrms (1222 commits)")

---

Tags

deterministicformatteropinionatedphp

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/lkrms-pretty-php/health.svg)

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

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M568](/packages/symfony-maker-bundle)[jean85/pretty-package-versions

A library to get pretty versions strings of installed dependencies

1.3k289.5M63](/packages/jean85-pretty-package-versions)[infection/infection

Infection is a Mutation Testing framework for PHP. The mutation adequacy score can be used to measure the effectiveness of a test set in terms of its ability to detect faults.

2.2k26.2M1.8k](/packages/infection-infection)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[pocketmine/pocketmine-mp

A server software for Minecraft: Bedrock Edition written in PHP

3.5k74.6k86](/packages/pocketmine-pocketmine-mp)[orchestra/canvas

Code Generators for Laravel Applications and Packages

20917.2M158](/packages/orchestra-canvas)

PHPackages © 2026

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