susina/coding-standard

Shared config for php-cs-fixer, based on PSR1 and PSR2

v2.3 2021-07-27 05:46 UTC

This package is auto-updated.

Last update: 2024-10-27 13:22:54 UTC


README

Test Installation

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 <?php statement. I.e.: <?php declare(strict_types=1);
  • always use short array syntax
  • always put one space around string concatenation operator: 'string1' . 'string2'

Installation

Run

$ composer require --dev susina/coding-standard

Configuration

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.

Composer Scripts

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

Git

We suggest adding .php-cs-fixer.cache to .gitignore:

vendor/
.php-cs-fixer.cache

Travis

You can configure Travis to cache the .php-cs-fixer.cache file. Update your .travis.yml:

cache:
  directories:
    - $HOME/.php-cs-fixer

Then run php-cs-fixer in the script section:

script:
  - composer cs

Github Actions

You 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-key

License

This package is licensed under the Apache2 License. For full copyright information, please see LICENSE file, in this repository.