PHP CS Fixer Config
Wrapper with pre-defined rules around the PHP-CS-Fixer package โ A tool to automatically fix PHP Coding Standards issues.
If you like/use this package, please consider starring it. Thanks!
๐ฟ Installation
โ Using composer
Require as dependency:
$ composer req wayofdev/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. -
Example contents of
.php-cs-fixer.dist.php
file:<?php declare(strict_types=1); use WayOfDev\PhpCsFixer\Config\ConfigBuilder; use WayOfDev\PhpCsFixer\Config\RuleSets\DefaultSet; require_once 'vendor/autoload.php'; return ConfigBuilder::createFromRuleSet(new DefaultSet()) ->inDir(__DIR__ . '/src') ->inDir(__DIR__ . '/tests') ->addFiles([__FILE__]) ->getConfig();
-
Place
.php-cs-fixer.cache
file into.gitignore
๐ป Usage
โ Running
Fix coding standards by simply running console command:
$ php vendor/bin/php-cs-fixer fix -v
โ Using Makefile
To use with our Makefile
:
-
Add
scripts
section tocomposer.json
:{ "scripts": { "cs-fix": "php vendor/bin/php-cs-fixer fix -v", "cs-diff": "php vendor/bin/php-cs-fixer fix --dry-run -v --diff" } }
-
Use
Makefile
code to run PHP-CS-Fixer tests:# Run inspections and fix code $ make cs-fix # Check coding standards without applying the fix $ make cs-diff
๐งช Running Tests
โ PHPUnit tests
To run tests, run the following command:
$ make test
โ Static Analysis
Code quality using PHPStan:
$ make stan
โ Coding Standards Fixing
Fix code using The PHP Coding Standards Fixer (PHP CS Fixer) to follow our standards:
$ make cs-fix
๐ค License
๐๐ผโโ๏ธ Author Information
Created in 2022 by lotyp / wayofdev
๐งฑ Resources
-
Full documentation about all fixers are available here - PHP-CS-Fixer configuration UI
-
The official PHP-CS-Fixer documentation