|
1 | 1 | # LMC Coding Standard for PHP |
2 | 2 |
|
| 3 | +PHP coding standard used in [LMC](https://www.lmc.eu/en/) projects. |
| 4 | + |
| 5 | +Standard is based on [PSR-2](https://www.php-fig.org/psr/psr-2/) and adds various checks to make sure the code is readable, |
| 6 | +does follow the same conventions and does not contain common mistakes. |
| 7 | + |
| 8 | +We use [EasyCodingStandard] to define and execute checks created for both [PHP-CS-Fixer] and [PHP_CodeSniffer]. |
| 9 | + |
| 10 | +**🚧 Please be advised this package is currently under development and anything can change anytime.** |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +```bash |
| 15 | +composer require --dev lmc/coding-standard:dev-master symplify/easy-coding-standard:^4.0@alpha symplify/coding-standard:^4.0@alpha symplify/package-builder:^4.0@alpha symplify/token-runner:^4.0@alpha symplify/better-reflection-docblock:^4.0@alpha |
| 16 | +``` |
| 17 | + |
| 18 | +i️ Because we currently depend on `@alpha` version of [EasyCodingStandard], all of its `@alpha` dependencies must temporarily |
| 19 | +also be explicitly required with their stability flag. |
| 20 | + |
| 21 | +## Usage |
| 22 | + |
| 23 | +1. Create `easy-coding-standard.yml` file in root directory of your project and import the LMC code-style rules: |
| 24 | + |
| 25 | +```yaml |
| 26 | +imports: |
| 27 | + - { resource: 'vendor/lmc/coding-standard/easy-coding-standard.yml' } |
| 28 | +``` |
| 29 | + |
| 30 | +2. Run the check command (for `src/` and `tests/` directories): |
| 31 | + |
| 32 | +```bash |
| 33 | +vendor/bin/ecs check src/ tests/ |
| 34 | +``` |
| 35 | + |
| 36 | +3. Optionally we recommend adding this to `scripts` section of your `composer.json`: |
| 37 | + |
| 38 | +```json |
| 39 | + "scripts": { |
| 40 | + "analyze": [ |
| 41 | + "vendor/bin/ecs check src/ tests/ --ansi", |
| 42 | + "[... other scripts, like PHPStan etc.]" |
| 43 | + ] |
| 44 | + } |
| 45 | +``` |
| 46 | + |
| 47 | +### Exclude (skip) some checks or files |
| 48 | + |
| 49 | +If you need to exclude some specific check, please refer to the [EasyCodingStandard documentation](https://github.com/Symplify/EasyCodingStandard#exclude-checkers). |
| 50 | + |
| 51 | +If you want to exclude some specific file (or directory) from the checks, you can use `skip` parameter to do so (see [docs](https://github.com/Symplify/EasyCodingStandard#ignore-what-you-cant-fix)). |
| 52 | +⚠️ However **if you define custom `skip` section in your `parameters`, it will overwrite all `skip` rules** from the [imported standard][easy-coding-standard.yml] |
| 53 | +and re-enable various un-intended rules. Until this [ECS limitation](https://github.com/Symplify/Symplify/pull/697#issuecomment-373915457) |
| 54 | +is resolved, the workaround is to redeclare the whole content of the skip section of the main [`easy-coding-standard.yml`][easy-coding-standard.yml] file. |
| 55 | + |
3 | 56 | ## Changelog |
4 | 57 | For latest changes see [CHANGELOG.md](CHANGELOG.md) file. We follow [Semantic Versioning](http://semver.org/). |
5 | 58 |
|
6 | 59 | ## License |
7 | 60 | This library is open source software licensed under the [MIT license](LICENCE.md). |
| 61 | + |
| 62 | +[PHP-CS-Fixer]: https://github.com/FriendsOfPHP/PHP-CS-Fixer |
| 63 | +[PHP_CodeSniffer]: https://github.com/squizlabs/PHP_CodeSniffer |
| 64 | +[EasyCodingStandard]: https://github.com/Symplify/EasyCodingStandard |
| 65 | +[easy-coding-standard.yml]: https://github.com/lmc-eu/php-coding-standard/blob/master/easy-coding-standard.yml |
0 commit comments