|  | 
| 1 | 1 | # php-cs-fixer-config | 
| 2 | 2 | 
 | 
| 3 |  | -[](https://github.com/ergebnis/php-cs-fixer-config/actions) | 
| 4 |  | -[](https://github.com/ergebnis/php-cs-fixer-config/actions) | 
| 5 |  | -[](https://github.com/ergebnis/php-cs-fixer-config/actions) | 
| 6 |  | -[](https://github.com/ergebnis/php-cs-fixer-config/actions) | 
| 7 |  | - | 
| 8 |  | -[](https://codecov.io/gh/ergebnis/php-cs-fixer-config) | 
| 9 |  | -[](https://shepherd.dev/github/ergebnis/php-cs-fixer-config) | 
| 10 |  | - | 
| 11 |  | -[](https://packagist.org/packages/ergebnis/php-cs-fixer-config) | 
| 12 |  | -[](https://packagist.org/packages/ergebnis/php-cs-fixer-config) | 
| 13 |  | - | 
| 14 |  | -Provides a configuration factory and multiple rule sets for [`friendsofphp/php-cs-fixer`](http://github.com/FriendsOfPHP/PHP-CS-Fixer). | 
| 15 |  | - | 
| 16 | 3 | ## Installation | 
| 17 | 4 | 
 | 
| 18 | 5 | Run | 
| 19 | 6 | 
 | 
| 20 | 7 | ```sh | 
| 21 |  | -$ composer require --dev ergebnis/php-cs-fixer-config | 
|  | 8 | +composer require --dev szepeviktor/php-cs-fixer-laravel-ruleset | 
| 22 | 9 | ``` | 
| 23 | 10 | 
 | 
| 24 | 11 | ## Usage | 
| 25 | 12 | 
 | 
| 26 | 13 | ### Configuration | 
| 27 | 14 | 
 | 
| 28 |  | -Pick one of the rule sets: | 
| 29 |  | - | 
| 30 |  | -- [`Ergebnis\PhpCsFixer\RuleSet\Php74`](src/RuleSet/Php74.php) | 
| 31 |  | -- [`Ergebnis\PhpCsFixer\RuleSet\Php80`](src/RuleSet/Php80.php) | 
| 32 |  | -- [`Ergebnis\PhpCsFixer\RuleSet\Php81`](src/RuleSet/Php81.php) | 
| 33 |  | - | 
| 34 | 15 | Create a configuration file `.php-cs-fixer.php` in the root of your project: | 
| 35 | 16 | 
 | 
| 36 | 17 | ```php | 
| 37 |  | -<?php | 
| 38 |  | - | 
| 39 |  | -use Ergebnis\PhpCsFixer\Config; | 
|  | 18 | +use SzepeViktor\PhpCsFixer\Laravel\Factory; | 
| 40 | 19 | 
 | 
| 41 |  | -$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php74()); | 
|  | 20 | +$config = Factory::fromLaravelRuleSet(); | 
| 42 | 21 | 
 | 
| 43 |  | -$config->getFinder()->in(__DIR__); | 
| 44 |  | -$config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache'); | 
|  | 22 | +$config->getFinder() | 
|  | 23 | + ->in([ | 
|  | 24 | + __DIR__ . '/app', | 
|  | 25 | + __DIR__ . '/config', | 
|  | 26 | + __DIR__ . '/database', | 
|  | 27 | + __DIR__ . '/routes', | 
|  | 28 | + __DIR__ . '/tests', | 
|  | 29 | + ]) | 
|  | 30 | +; | 
| 45 | 31 | 
 | 
| 46 | 32 | return $config; | 
| 47 | 33 | ``` | 
| 48 |  | - | 
| 49 |  | -### Git | 
| 50 |  | - | 
| 51 |  | -All configuration examples use the caching feature, and if you want to use it as well, you should add the cache directory to `.gitignore`: | 
| 52 |  | - | 
| 53 |  | -```diff | 
| 54 |  | -+ /.build/ | 
| 55 |  | - /vendor/ | 
| 56 |  | -``` | 
| 57 |  | - | 
| 58 |  | -:bulb: Personally, I prefer to use a `.build` directory for storing build artifacts. | 
| 59 |  | - | 
| 60 |  | -### Configuration with header | 
| 61 |  | - | 
| 62 |  | -:bulb: Optionally specify a header: | 
| 63 |  | - | 
| 64 |  | -```diff | 
| 65 |  | - <?php | 
| 66 |  | - | 
| 67 |  | - use Ergebnis\PhpCsFixer\Config; | 
| 68 |  | - | 
| 69 |  | -+$header = <<<EOF | 
| 70 |  | -+Copyright (c) 2020 Andreas Möller | 
| 71 |  | -+ | 
| 72 |  | -+For the full copyright and license information, please view | 
| 73 |  | -+the LICENSE file that was distributed with this source code. | 
| 74 |  | -+ | 
| 75 |  | -+@see https://github.com/ergebnis/php-cs-fixer-config | 
| 76 |  | -+EOF; | 
| 77 |  | - | 
| 78 |  | --$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php74()); | 
| 79 |  | -+$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php74($header)); | 
| 80 |  | - | 
| 81 |  | - $config->getFinder()->in(__DIR__); | 
| 82 |  | - $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache'); | 
| 83 |  | - | 
| 84 |  | - return $config; | 
| 85 |  | -``` | 
| 86 |  | - | 
| 87 |  | -This will enable and configure the [`HeaderCommentFixer`](https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.1.1/src/Fixer/Comment/HeaderCommentFixer.php), so that | 
| 88 |  | -file headers will be added to PHP files, for example: | 
| 89 |  | - | 
| 90 |  | -```php | 
| 91 |  | -<?php | 
| 92 |  | - | 
| 93 |  | -/** | 
| 94 |  | - * Copyright (c) 2020 Andreas Möller | 
| 95 |  | - * | 
| 96 |  | - * For the full copyright and license information, please view | 
| 97 |  | - * the LICENSE file that was distributed with this source code. | 
| 98 |  | - * | 
| 99 |  | - * @see https://github.com/ergebnis/php-cs-fixer-config | 
| 100 |  | - */ | 
| 101 |  | -``` | 
| 102 |  | - | 
| 103 |  | -### Configuration with override rules | 
| 104 |  | - | 
| 105 |  | -:bulb: Optionally override rules from a rule set by passing in an array of rules to be merged in: | 
| 106 |  | - | 
| 107 |  | -```diff | 
| 108 |  | - <?php | 
| 109 |  | - | 
| 110 |  | - use Ergebnis\PhpCsFixer\Config; | 
| 111 |  | - | 
| 112 |  | --$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php74()); | 
| 113 |  | -+$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php74(), [ | 
| 114 |  | -+ 'mb_str_functions' => false, | 
| 115 |  | -+ 'strict_comparison' => false, | 
| 116 |  | -+]); | 
| 117 |  | - | 
| 118 |  | - $config->getFinder()->in(__DIR__); | 
| 119 |  | - $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache'); | 
| 120 |  | - | 
| 121 |  | - return $config; | 
| 122 |  | -``` | 
| 123 |  | - | 
| 124 |  | -### Makefile | 
| 125 |  | - | 
| 126 |  | -If you like [`Makefile`](https://www.gnu.org/software/make/manual/make.html#Introduction)s, create a `Makefile` with a `coding-standards` target: | 
| 127 |  | - | 
| 128 |  | -```diff | 
| 129 |  | -+.PHONY: coding-standards | 
| 130 |  | -+coding-standards: vendor | 
| 131 |  | -+	 mkdir -p .build/php-cs-fixer | 
| 132 |  | -+ vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --verbose | 
| 133 |  | - | 
| 134 |  | - vendor: composer.json composer.lock | 
| 135 |  | - composer validate | 
| 136 |  | - composer install | 
| 137 |  | -``` | 
| 138 |  | - | 
| 139 |  | -Run | 
| 140 |  | - | 
| 141 |  | -``` | 
| 142 |  | -$ make coding-standards | 
| 143 |  | -``` | 
| 144 |  | - | 
| 145 |  | -to automatically fix coding standard violations. | 
| 146 |  | - | 
| 147 |  | -### Composer script | 
| 148 |  | - | 
| 149 |  | -If you like [`composer` scripts](https://getcomposer.org/doc/articles/scripts.md), add a `coding-standards` script to `composer.json`: | 
| 150 |  | - | 
| 151 |  | -```diff | 
| 152 |  | - { | 
| 153 |  | - "name": "foo/bar", | 
| 154 |  | - "require": { | 
| 155 |  | - "php": "^7.3", | 
| 156 |  | - }, | 
| 157 |  | - "require-dev": { | 
| 158 |  | - "ergebnis/php-cs-fixer-config": "~1.0.0" | 
| 159 |  | -+ }, | 
| 160 |  | -+ "scripts": { | 
| 161 |  | -+ "coding-standards": [ | 
| 162 |  | -+ "mkdir -p .build/php-cs-fixer", | 
| 163 |  | -+ "php-cs-fixer fix --diff --verbose" | 
| 164 |  | -+ ] | 
| 165 |  | - } | 
| 166 |  | - } | 
| 167 |  | -``` | 
| 168 |  | - | 
| 169 |  | -Run | 
| 170 |  | - | 
| 171 |  | -``` | 
| 172 |  | -$ composer coding-standards | 
| 173 |  | -``` | 
| 174 |  | - | 
| 175 |  | -to automatically fix coding standard violations. | 
| 176 |  | - | 
| 177 |  | -### GitHub Actions | 
| 178 |  | - | 
| 179 |  | -If you like [GitHub Actions](https://github.com/features/actions), add a `coding-standards` job to your workflow: | 
| 180 |  | - | 
| 181 |  | -```diff | 
| 182 |  | - on: | 
| 183 |  | - pull_request: null | 
| 184 |  | - push: | 
| 185 |  | - branches: | 
| 186 |  | - - main | 
| 187 |  | - | 
| 188 |  | - name: "Integrate" | 
| 189 |  | - | 
| 190 |  | - jobs: | 
| 191 |  | -+ coding-standards: | 
| 192 |  | -+ name: "Coding Standards" | 
| 193 |  | -+ | 
| 194 |  | -+ runs-on: ubuntu-latest | 
| 195 |  | -+ | 
| 196 |  | -+ strategy: | 
| 197 |  | -+ matrix: | 
| 198 |  | -+ php-version: | 
| 199 |  | -+ - "7.3" | 
| 200 |  | -+ | 
| 201 |  | -+ steps: | 
| 202 |  | -+ - name: "Checkout" | 
| 203 |  | -+ uses: "actions/checkout@v2" | 
| 204 |  | -+ | 
| 205 |  | -+ - name: "Install PHP with extensions" | 
| 206 |  | -+ uses: "shivammathur/setup-php@v2" | 
| 207 |  | -+ with: | 
| 208 |  | -+ coverage: "none" | 
| 209 |  | -+ php-version: "${{ matrix.php-version }}" | 
| 210 |  | -+ | 
| 211 |  | -+ - name: "Cache dependencies installed with composer" | 
| 212 |  | -+ uses: "actions/cache@v2" | 
| 213 |  | -+ with: | 
| 214 |  | -+ path: "~/.composer/cache" | 
| 215 |  | -+ key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}" | 
| 216 |  | -+ restore-keys: "php-${{ matrix.php-version }}-composer-" | 
| 217 |  | -+ | 
| 218 |  | -+ - name: "Install locked dependencies with composer" | 
| 219 |  | -+ run: "composer install --no-interaction --no-progress --no-suggest" | 
| 220 |  | -+ | 
| 221 |  | -+ - name: "Create cache directory for friendsofphp/php-cs-fixer" | 
| 222 |  | -+ run: mkdir -p .build/php-cs-fixer | 
| 223 |  | -+ | 
| 224 |  | -+ - name: "Cache cache directory for friendsofphp/php-cs-fixer" | 
| 225 |  | -+ uses: "actions/cache@v2" | 
| 226 |  | -+ with: | 
| 227 |  | -+ path: "~/.build/php-cs-fixer" | 
| 228 |  | -+ key: "php-${{ matrix.php-version }}-php-cs-fixer-${{ github.sha }}" | 
| 229 |  | -+ restore-keys: "php-${{ matrix.php-version }}-php-cs-fixer-" | 
| 230 |  | -+ | 
| 231 |  | -+ - name: "Run friendsofphp/php-cs-fixer" | 
| 232 |  | -+ run: "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --dry-run --verbose" | 
| 233 |  | -``` | 
| 234 |  | - | 
| 235 |  | -## Changelog | 
| 236 |  | - | 
| 237 |  | -Please have a look at [`CHANGELOG.md`](CHANGELOG.md). | 
| 238 |  | - | 
| 239 |  | -## Contributing | 
| 240 |  | - | 
| 241 |  | -Please have a look at [`CONTRIBUTING.md`](.github/CONTRIBUTING.md). | 
| 242 |  | - | 
| 243 |  | -:bulb: Do you want to add a rule for personal use or use in your organization? Instead of opening a pull request here, perhaps consider creating a new package based on [`ergebnis/php-cs-fixer-config-template`](https://github.com/ergebnis/php-cs-fixer-config-template), a GitHub repository template that provides a good starting point for creating and sharing your own rule sets. | 
| 244 |  | - | 
| 245 |  | -## Code of Conduct | 
| 246 |  | - | 
| 247 |  | -Please have a look at [`CODE_OF_CONDUCT.md`](https://github.com/ergebnis/.github/blob/main/CODE_OF_CONDUCT.md). | 
| 248 |  | - | 
| 249 |  | -## License | 
| 250 |  | - | 
| 251 |  | -This package is licensed using the MIT License. | 
| 252 |  | - | 
| 253 |  | -Please have a look at [`LICENSE.md`](LICENSE.md). | 
| 254 |  | - | 
| 255 |  | -## Credits | 
| 256 |  | - | 
| 257 |  | -This project is inspired by and also replaces [`localheinz/php-cs-fixer-config`](https://github.com/localheinz/php-cs-fixer-config). | 
| 258 |  | - | 
| 259 |  | -## Curious what I am building? | 
| 260 |  | - | 
| 261 |  | -:mailbox_with_mail: [Subscribe to my list](https://localheinz.com/projects/), and I will occasionally send you an email to let you know what I am working on. | 
0 commit comments