Home

Awesome

<h1 align="center">pretty-php: the opinionated code formatter</h1> <p align="center"> <a href="https://github.com/lkrms/pretty-php"> <img src="https://github.com/lkrms/pretty-php/raw/main/images/logo-600x600-rounded.png" alt="pretty-php logo" width="250"> </a> <p> <p align="center"> <a href="https://packagist.org/packages/lkrms/pretty-php"><img src="https://poser.pugx.org/lkrms/pretty-php/v" alt="Latest Stable Version" /></a> <a href="https://packagist.org/packages/lkrms/pretty-php"><img src="https://poser.pugx.org/lkrms/pretty-php/license" alt="License" /></a> <a href="https://github.com/lkrms/pretty-php/actions"><img src="https://github.com/lkrms/pretty-php/actions/workflows/ci.yml/badge.svg" alt="CI Status" /></a> <a href="https://codecov.io/gh/lkrms/pretty-php"><img src="https://codecov.io/gh/lkrms/pretty-php/graph/badge.svg?token=W0KVZU718K" alt="Code Coverage" /></a> <a href="https://marketplace.visualstudio.com/items?itemName=lkrms.pretty-php"><img src="https://img.shields.io/visual-studio-marketplace/i/lkrms.pretty-php?label=Marketplace%20installs&color=%230066b8" alt="Visual Studio Marketplace install count" /></a> <a href="https://open-vsx.org/extension/lkrms/pretty-php"><img src="https://img.shields.io/open-vsx/dt/lkrms/pretty-php?label=Open%20VSX%20downloads&color=%23a60ee5" alt="Open VSX Registry download count" /></a> </p>

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

By taking responsibility for the whitespace in your code, pretty-php makes it easier to focus on the content, providing time and mental energy savings that accrue over time.

Code formatted by pretty-php produces the smallest diffs possible and looks the same regardless of the project you're working on, eliminating visual dissonance and improving the speed and effectiveness of code review.

You can use pretty-php as a standalone tool, run it from your editor, pair it with a linter, or add it to your CI workflows. Configuration is optional in each case.

If you have questions or feedback, I'd love to hear from you.

pretty-php isn't stable yet, so updates may introduce formatting changes that affect your code.

Features

Installation

Requirements

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, 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.

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

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

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 or run:

pretty-php --help

Editor integrations

Pragmatism

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

License

This project is licensed under the MIT License.