pretty-php – opinionated PHP code formatter

pretty-php is an opinionated code formatter for PHP. It is designed to make PHP source code consistent without requiring developers to spend time choosing or maintaining an extensive collection of style rules.

The formatter takes a deterministic approach: the same input and settings produce the same formatting, helping projects avoid stylistic differences between contributors and making code review easier to follow. Its philosophy is influenced by Black, the Python formatter, with an emphasis on sensible defaults, predictable output, and producing small, readable diffs. It can be used as a standalone command-line tool or incorporated into a broader development workflow alongside linters and other quality checks.

This is free and open source software.

Key Features

  • Formats complete PHP files in place.
  • Offers a diff mode for reviewing proposed formatting changes without replacing files.
  • Checks formatted output against the original code for equivalence.
  • Supports PSR-12 and the PHP Extended Coding Style specification.
  • Includes presets for Symfony, Drupal, Laravel and WordPress coding styles.
  • Can group and sort import statements.
  • Provides controls for operator placement and treatment of existing newlines.
  • Can normalize strings and numeric literals.
  • Trims and aligns comments and removes empty DocBlocks.
  • Supports optional configuration through a JSON file while remaining usable without configuration.
  • Can be integrated with editors and continuous integration workflows.
  • Provides options for selectively disabling formatting rules.

Website: github.com/lkrms/pretty-php
Support:
Developer: Luke Arms
License: MIT License

pretty-php is written in PHP. Learn PHP with our recommended free books and free tutorials.


Best Free and Open Source Software Explore our comprehensive directory of recommended free and open source software. Our carefully curated collection spans every major software category.

This directory is part of our ongoing series of informative articles for Linux enthusiasts. It features hundreds of detailed reviews, along with open source alternatives to proprietary solutions from major corporations such as Google, Microsoft, Apple, Adobe, IBM, Cisco, Oracle, and Autodesk.

You’ll also find interesting projects to try, hardware coverage, free programming books and tutorials, and much more.

Discovered a useful open source Linux program that we haven’t covered yet? Let us know by completing this form.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted