Susina Coding Standard library is a set of php-cs-fixer rules for Susina project repository. It's based on PSR1 and PSR12, with the following differences:
- always use declare(strict_types=1) and put it at the beginning of the file, one space after
<?phpstatement. I.e.:<?php declare(strict_types=1); - always use short array syntax
- always put one space around string concatenation operator:
'string1' . 'string2'
Run
$ composer require --dev susina/coding-standard
Create a .php-cs-fixer.php file in the root of your project:
<?php declare(strict_types=1);
$config = new Susina\CodingStandard\Config();
$config->getFinder()
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->excludes(['fixtures'])
;
return $config;See php-cs-fixer documentation for further information.
Add to your composer.json file the following lines:
"scripts" : {
"cs" : "php-cs-fixer fix -v --diff --dry-run",
"cs-fix" : "php-cs-fixer fix -v --diff"
}Now you can check your code style by running:
composer cs
and you can fix it by:
composer cs-fix
We suggest adding .php-cs-fixer.cache to .gitignore:
vendor/
.php-cs-fixer.cache
You can configure Travis to cache the .php-cs-fixer.cache file. Update your .travis.yml:
cache:
directories:
- $HOME/.php-cs-fixerThen run php-cs-fixer in the script section:
script:
- composer csYou can configure Github actions to cache .php-cs-fixer.cache file. In your workflow,
into the Cache configuration step, simply add ~/.php-cs-fixer.cache under the path key:
- name: Cache multiple paths
uses: actions/cache@v2
with:
path: |
~/.php-cs-fixer.cache
key: your-awesome-cache-keyThis package is licensed under the Apache2 License. For full copyright information, please see LICENSE file, in this repository.