friendsofphp / php-cs-fixer
A tool to automatically fix PHP code style
Fund package maintenance!
keradus
Installs: 165 049 035
Dependents: 18 575
Suggesters: 65
Security: 0
Stars: 12 869
Watchers: 207
Forks: 1 580
Open Issues: 140
Type:application
Requires
- php: ^7.4 || ^8.0
- ext-filter: *
- ext-json: *
- ext-tokenizer: *
- clue/ndjson-react: ^1.0
- composer/semver: ^3.4
- composer/xdebug-handler: ^3.0.3
- fidry/cpu-core-counter: ^1.0
- react/child-process: ^0.6.5
- react/event-loop: ^1.0
- react/promise: ^2.0 || ^3.0
- react/socket: ^1.0
- react/stream: ^1.0
- sebastian/diff: ^4.0 || ^5.0 || ^6.0
- symfony/console: ^5.4 || ^6.0 || ^7.0
- symfony/event-dispatcher: ^5.4 || ^6.0 || ^7.0
- symfony/filesystem: ^5.4 || ^6.0 || ^7.0
- symfony/finder: ^5.4 || ^6.0 || ^7.0
- symfony/options-resolver: ^5.4 || ^6.0 || ^7.0
- symfony/polyfill-mbstring: ^1.28
- symfony/polyfill-php80: ^1.28
- symfony/polyfill-php81: ^1.28
- symfony/process: ^5.4 || ^6.0 || ^7.0
- symfony/stopwatch: ^5.4 || ^6.0 || ^7.0
Requires (Dev)
- facile-it/paraunit: ^1.3 || ^2.3
- infection/infection: ^0.29.5
- justinrainbow/json-schema: ^5.2
- keradus/cli-executor: ^2.1
- mikey179/vfsstream: ^1.6.11
- php-coveralls/php-coveralls: ^2.7
- php-cs-fixer/accessible-object: ^1.1
- php-cs-fixer/phpunit-constraint-isidenticalstring: ^1.5
- php-cs-fixer/phpunit-constraint-xmlmatchesxsd: ^1.5
- phpunit/phpunit: ^9.6.19 || ^10.5.21 || ^11.2
- symfony/var-dumper: ^5.4 || ^6.0 || ^7.0
- symfony/yaml: ^5.4 || ^6.0 || ^7.0
Suggests
- ext-dom: For handling output formats in XML
- ext-mbstring: For handling non-UTF8 characters.
- dev-master
- v3.64.0
- v3.63.2
- v3.63.1
- v3.63.0
- v3.62.0
- v3.61.1
- v3.61.0
- v3.60.0
- v3.59.3
- v3.59.2
- v3.59.1
- v3.59.0
- v3.58.1
- v3.58.0
- v3.57.2
- v3.57.1
- v3.57.0
- v3.56.2
- v3.56.1
- v3.56.0
- v3.55.0
- v3.54.0
- v3.53.0
- v3.52.1
- v3.52.0
- v3.51.0
- v3.50.0
- v3.49.0
- v3.48.0
- v3.47.1
- v3.47.0
- v3.46.0
- v3.45.0
- v3.44.0
- v3.43.1
- v3.43.0
- v3.42.0
- v3.41.1
- v3.41.0
- v3.40.2
- v3.40.1
- v3.40.0
- v3.39.1
- v3.39.0
- v3.38.2
- v3.38.1
- v3.38.0
- v3.37.1
- v3.37.0
- v3.36.0
- v3.35.1
- v3.35.0
- v3.34.1
- v3.34.0
- v3.33.1
- v3.33.0
- v3.32.1
- v3.32.0
- v3.31.0
- v3.30.0
- v3.29.0
- v3.28.0
- v3.27.0
- v3.26.1
- v3.26.0
- v3.25.1
- v3.25.0
- v3.24.0
- v3.23.0
- v3.22.0
- v3.21.3
- v3.21.2
- v3.21.1
- v3.21.0
- v3.20.0
- v3.19.2
- v3.19.1
- v3.19.0
- v3.18.0
- v3.17.0
- v3.16.0
- v3.15.1
- v3.15.0
- v3.14.5
- v3.14.4
- v3.14.3
- v3.14.2
- v3.14.1
- v3.14.0
- v3.13.2
- v3.13.1
- v3.13.0
- v3.12.0
- v3.11.0
- v3.10.0
- v3.9.6
- v3.9.5
- v3.9.4
- v3.9.3
- v3.9.2
- v3.9.1
- v3.8.0
- v3.7.0
- v3.6.0
- v3.5.0
- v3.4.0
- v3.3.2
- v3.3.1
- v3.3.0
- v3.2.1
- v3.2.0
- v3.1.0
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v3.0.0-rc.1
- v3.0.0-beta.2
- v3.0.0-beta.1
- v2.19.3
- v2.19.2
- v2.19.1
- v2.19.0
- v2.18.7
- v2.18.6
- v2.18.5
- v2.18.4
- v2.18.3
- v2.18.2
- v2.18.1
- v2.18.0
- v2.17.5
- v2.17.4
- v2.17.3
- v2.17.2
- v2.17.1
- v2.17.0
- v2.16.10
- v2.16.9
- v2.16.8
- v2.16.7
- v2.16.6
- v2.16.5
- v2.16.4
- v2.16.3
- v2.16.2
- v2.16.1
- v2.16.0
- v2.15.10
- v2.15.9
- v2.15.8
- v2.15.7
- v2.15.6
- v2.15.5
- v2.15.4
- v2.15.3
- v2.15.2
- v2.15.1
- v2.15.0
- v2.14.6
- v2.14.5
- v2.14.4
- v2.14.3
- v2.14.2
- v2.14.1
- v2.14.0
- v2.13.3
- v2.13.2
- v2.13.1
- v2.13.0
- v2.12.12
- v2.12.11
- v2.12.10
- v2.12.9
- v2.12.8
- v2.12.7
- v2.12.6
- v2.12.5
- v2.12.4
- v2.12.3
- v2.12.2
- v2.12.1
- v2.12.0
- v2.11.2
- v2.11.1
- v2.11.0
- v2.10.5
- v2.10.4
- v2.10.3
- v2.10.2
- v2.10.1
- v2.10.0
- v2.9.3
- v2.9.2
- v2.9.1
- v2.9.0
- v2.8.4
- v2.8.3
- v2.8.2
- v2.8.1
- v2.8.0
- v2.7.5
- v2.7.4
- v2.7.3
- v2.7.2
- v2.7.1
- v2.7.0
- v2.6.1
- v2.6.0
- v2.5.1
- v2.5.0
- v2.4.2
- v2.4.1
- v2.4.0
- v2.3.3
- v2.3.2
- v2.3.1
- v2.3.0
- v2.2.20
- v2.2.19
- v2.2.18
- v2.2.17
- v2.2.16
- v2.2.15
- v2.2.14
- v2.2.13
- v2.2.12
- v2.2.11
- v2.2.10
- v2.2.9
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.1
- v2.2.0
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0.0
- v2.0.0-RC
- v2.0.0-beta
- v2.0.0-alpha
- v1.13.3
- v1.13.2
- v1.13.1
- v1.13.0
- v1.12.4
- v1.12.3
- v1.12.2
- v1.12.1
- v1.12.0
- v1.11.8
- v1.11.7
- v1.11.6
- v1.11.5
- v1.11.4
- v1.11.3
- v1.11.2
- v1.11.1
- v1.11
- v1.10.3
- v1.10.2
- v1.10.1
- v1.10
- v1.9.3
- v1.9.2
- v1.9.1
- v1.9
- v1.8.1
- v1.8
- v1.7.1
- v1.7
- v1.6.2
- v1.6.1
- v1.6
- v1.5.2
- v1.5.1
- v1.5
- v1.4.2
- v1.4.1
- v1.4
- v1.3
- v1.2
- v1.1
- v1.0
- v0.5.7
- v0.5.6
- v0.5.5
- v0.5.4
- v0.5.3
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.0
- v0.3.0
- v0.2.0
- v0.1.0
- dev-readonly
- dev-release_notes_template
This package is auto-updated.
Last update: 2024-11-16 15:41:56 UTC
README
PHP Coding Standards Fixer
The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards; whether you want to follow PHP coding standards as defined in the PSR-1, PSR-2, etc., or other community driven ones like the Symfony one. You can also define your (team's) style through configuration.
It can modernize your code (like converting the pow
function to the **
operator on PHP 5.6)
and (micro) optimize it.
If you are already using a linter to identify coding standards problems in your code, you know that fixing them by hand is tedious, especially on large projects. This tool does not only detect them, but also fixes them for you.
Supported PHP Versions
- PHP 7.4
- PHP 8.0
- PHP 8.1
- PHP 8.2
- PHP 8.3
Note Each new PHP version requires a huge effort to support the new syntax. That's why the latest PHP version might not be supported yet. If you need it, please, consider supporting the project in any convenient way, for example with code contribution or reviewing existing PRs. To run PHP CS Fixer on yet unsupported versions "at your own risk" - leverage the PHP_CS_FIXER_IGNORE_ENV.
Documentation
Installation
The recommended way to install PHP CS Fixer is to use Composer
in a dedicated composer.json
file in your project, for example in the
tools/php-cs-fixer
directory:
mkdir -p tools/php-cs-fixer composer require --working-dir=tools/php-cs-fixer friendsofphp/php-cs-fixer
Or using the main composer.json
:
composer require --dev friendsofphp/php-cs-fixer
For more details and other installation methods, see installation instructions.
Run with Docker
You can use pre-built Docker images to run php-cs-fixer
.
docker run -it --rm -v $(pwd):/code ghcr.io/php-cs-fixer/php-cs-fixer:${FIXER_VERSION:-3-php8.3} fix src
$FIXER_VERSION
used in example above is an identifier of a release you want to use, which is based on Fixer and PHP versions combined. There are different tags for each Fixer's SemVer level and PHP version with syntax <php-cs-fixer-version>-php<php-version>
. For example:
3.57.0-php7.4
3.57-php8.0
3-php8.3
Usage
Assuming you installed PHP CS Fixer as instructed above, you can run the
following command to fix the PHP files in the src
directory:
tools/php-cs-fixer/vendor/bin/php-cs-fixer fix src
See usage, list of built-in rules, list of rule sets and configuration file documentation for more details.
If you need to apply code styles that are not supported by the tool, you can create custom rules.
Editor Integration
Dedicated plugins exist for:
Community
The PHP CS Fixer is maintained on GitHub at https://github.com/PHP-CS-Fixer/PHP-CS-Fixer. Bug reports and ideas about new features are welcome there.
You can reach us in the GitHub Discussions regarding the project, configuration, possible improvements, ideas and questions. Please visit us there!
Contribute
The tool comes with quite a few built-in fixers, but everyone is more than welcome to contribute more of them.