sirix / php-cs-fixer-config
Sirix PHP coding standards fixer configuration.
1.0.1
2024-03-29 09:46 UTC
Requires
- php: ^8.0 || ^8.1 || ^8.2 || ^8.3
- friendsofphp/php-cs-fixer: ^3.52
- gordinskiy/line-length-checker: ^0.0.2
- pedrotroller/php-cs-custom-fixer: ^2.33
Requires (Dev)
- ergebnis/composer-normalize: ^2.42
- phpstan/extension-installer: ^1.1.0
- phpstan/phpstan-phpunit: ^1.3.16
- phpunit/phpunit: ^10.5
- roave/security-advisories: dev-master
README
Wrapper with pre-defined rules around the PHP-CS-Fixer package - A tool to automatically fix PHP Coding Standards issues.
Installation
Using Composer
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:
- Create a new tools/php-cs-fixer directory:
mkdir -p tools/php-cs-fixer
- Install via composer:
composer req --dev --working-dir=tools/php-cs-fixer sirix/php-cs-fixer-config
Configuration
-
Create PHP file and name it
.php-cs-fixer.dist.php
and place it inside root directory of project. It will be recognized by PHP CS Fixer automatically. -
Contents of file should look like this:
<?php declare(strict_types=1); use Sirix\CsFixerConfig\ConfigBuilder; return ConfigBuilder::create() ->inDir(__DIR__ . '/src') ->inDir(__DIR__ . '/test') ->getConfig() ;
or, you can add additional rules to the configuration file:
<?php declare(strict_types=1); use Sirix\CsFixerConfig\ConfigBuilder; return ConfigBuilder::create() ->inDir(__DIR__ . '/config') ->inDir(__DIR__ . '/src') ->inDir(__DIR__ . '/test') ->setRules([ 'Gordinskiy/line_length_limit' => ['max_length' => 150], '@PHP83Migration' => true, ]) ->getConfig() ;
- Place
.php-cs-fixer.cache
file into.gitignore
Usage/Examples
- Fix coding standards:
$ php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix -v
- Check coding standards without applying the fix:
$ php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run
- Examine the proposed changes:
$ php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --dry-run -v --diff
Documentation
-
Full documentation about all fixers are available here - PHP-CS-Fixer configuration UI
-
The official PHP-CS-Fixer documentation