https://github.com/dusterio/prettyhp
PrettyHP is an opinionated PHP code formatter
https://github.com/dusterio/prettyhp
Last synced: 8 months ago
JSON representation
PrettyHP is an opinionated PHP code formatter
- Host: GitHub
- URL: https://github.com/dusterio/prettyhp
- Owner: dusterio
- License: mit
- Created: 2017-07-12T08:58:26.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-05-28T04:14:02.000Z (about 3 years ago)
- Last Synced: 2025-06-01T07:16:31.875Z (about 1 year ago)
- Language: PHP
- Size: 37.1 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# prettyhp

[](https://travis-ci.org/dusterio/prettyhp)
[](https://codeclimate.com/github/dusterio/prettyhp/badges)
[](https://packagist.org/packages/dusterio/prettyhp)
[](https://packagist.org/packages/dusterio/prettyhp)
[](https://packagist.org/packages/dusterio/prettyhp)
PrettyHP is an opinionated PHP code formatter
It removes all original styling and ensures that all outputted code conforms to a consistent style.
PrettyHP will try to comply with PSR as much as possible.
Inspired by JavaScript's [prettier](https://github.com/prettier/prettier)
## But why?
Your IDE or editor may already have some basic formatting built-in, but:
- At least PhpStorm cannot re-format code automatically before committing to VCS;
- Different team members may have different editors, views and standards;
- At least PhpStorm doesn't really enforce styling, it just does some basic indenting.
Why not use existing PHP code formatters?
### phpfmt
phpfmt is officially closed, the repo is deleted by the authors.
### php-cs-fixer
I'm a very experienced developer and Linux user, yet I couldn't get it up and running in 10+ minutes. Something is just wrong
about it. Since the tool's verbose mode is not implemented, I couldn't debug it any further.
## Installation
```bash
$ composer require --dev dusterio/prettyhp
```
We recommend to add a pre-commit Git hook so that any modified PHP files are
prettified right before the commit:
```bash
$ cat .git/hooks/pre-commit
git diff --staged --diff-filter=dx --name-only HEAD | grep ".*\.php$" | xargs -I % sh -c 'vendor/bin/prettyhp format %; git add %'
```
## Manual usage
PrettyHP is meant for PSR 4 compliant files – one file should contain one PHP class.
```bash
$ vendor/bin/prettyhp [filename]
```