|
| 1 | +# Brick Coding Standard |
| 2 | + |
| 3 | +<img src="https://raw.githubusercontent.com/brick/brick/master/logo.png" alt="" align="left" height="64"> |
| 4 | + |
| 5 | +Coding standard for Brick libraries. |
| 6 | + |
| 7 | +[](https://github.com/brick/coding-standard/actions) |
| 8 | +[](https://packagist.org/packages/brick/coding-standard) |
| 9 | +[](https://packagist.org/packages/brick/coding-standard) |
| 10 | +[](http://opensource.org/licenses/MIT) |
| 11 | + |
| 12 | +## Overview |
| 13 | + |
| 14 | +This coding standard is used in Brick libraries, but can also be used in your own projects. |
| 15 | + |
| 16 | +It is based on [PSR-12](https://www.php-fig.org/psr/psr-12/) and uses |
| 17 | +[Easy Coding Standard](https://github.com/easy-coding-standard/easy-coding-standard) with |
| 18 | +rules cherry-picked from [PHP-CS-Fixer](https://github.com/PHP-CS-Fixer/PHP-CS-Fixer), |
| 19 | +[PHP_CodeSniffer](http://github.com/squizlabs/PHP_CodeSniffer), and the |
| 20 | +[Slevomat coding standard](https://github.com/slevomat/coding-standard). |
| 21 | + |
| 22 | +## Release process |
| 23 | + |
| 24 | +This project is released with sequential version numbers: `v1`, `v2`, etc. |
| 25 | + |
| 26 | +Each new version should be considered as breaking, as it may update dependency versions, add new rules, or modify |
| 27 | +existing ones. |
| 28 | + |
| 29 | +## Usage |
| 30 | + |
| 31 | +### Use locally |
| 32 | + |
| 33 | +To use `brick/coding-standard` locally, install it with Composer: |
| 34 | + |
| 35 | +```bash |
| 36 | +composer require --dev brick/coding-standard |
| 37 | +``` |
| 38 | + |
| 39 | +Then create an `ecs.php` file in the root of your project with the following content: |
| 40 | + |
| 41 | +```php |
| 42 | +<?php |
| 43 | + |
| 44 | +declare(strict_types=1); |
| 45 | + |
| 46 | +use Symplify\EasyCodingStandard\Config\ECSConfig; |
| 47 | + |
| 48 | +return static function (ECSConfig $ecsConfig): void { |
| 49 | + $ecsConfig->import(__DIR__ . '/vendor/brick/coding-standard/ecs.php'); |
| 50 | + |
| 51 | + $ecsConfig->paths( |
| 52 | + [ |
| 53 | + __DIR__ . '/src', |
| 54 | + __DIR__ . '/tests', |
| 55 | + __FILE__, |
| 56 | + ], |
| 57 | + ); |
| 58 | +}; |
| 59 | +``` |
| 60 | + |
| 61 | +You can then run Easy Coding Standard with: |
| 62 | + |
| 63 | +```bash |
| 64 | +vendor/bin/ecs |
| 65 | +``` |
| 66 | + |
| 67 | +or, to fix coding standard violations automatically: |
| 68 | + |
| 69 | +```bash |
| 70 | +vendor/bin/ecs --fix |
| 71 | +``` |
| 72 | + |
| 73 | +If you wish to avoid conflicts with your project dependencies, you may also install ECS in a `tools` directory with its |
| 74 | +own `composer.json` instead. Here is how your directory may look like: |
| 75 | + |
| 76 | +```tools |
| 77 | +tools/ |
| 78 | +└── ecs/ |
| 79 | + ├── composer.json |
| 80 | + ├── composer.lock |
| 81 | + └── ecs.php |
| 82 | + └── vendor/ |
| 83 | + └── ... |
| 84 | +``` |
| 85 | + |
| 86 | +### Use in GitHub Actions |
| 87 | + |
| 88 | +You can integrate `brick/coding-standard` in your GitHub Actions workflow as follows: |
| 89 | + |
| 90 | +```yaml |
| 91 | +name: Coding Standard |
| 92 | + |
| 93 | +on: |
| 94 | + pull_request: |
| 95 | + push: |
| 96 | + |
| 97 | +jobs: |
| 98 | + coding-standard: |
| 99 | + name: Coding Standard |
| 100 | + uses: brick/coding-standard/.github/workflows/coding-standard.yml@v1 |
| 101 | +``` |
| 102 | +
|
| 103 | +By default, this workflow will run on PHP 8.1. You can change the PHP version by adding: |
| 104 | +
|
| 105 | +```yaml |
| 106 | + with: |
| 107 | + php-version: 8.2 |
| 108 | +``` |
| 109 | +
|
| 110 | +Only versions >= `8.1` are supported. |
| 111 | + |
| 112 | +Other options available are: |
| 113 | + |
| 114 | +- `composer-options` |
| 115 | +- `working-directory` |
| 116 | +- `config-file` |
0 commit comments