Skip to content

Commit 685b9f0

Browse files
authored
Merge pull request #59 from OndraM/feature/readme-update
Update README to reflect PHP configuration in ECS 9
2 parents 3be0b18 + 641ed60 commit 685b9f0

File tree

4 files changed

+96
-20
lines changed

4 files changed

+96
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<!-- There is always Unreleased section on the top. Subsections (Added, Changed, Fixed, Removed) should be added as needed. -->
66

77
## Unreleased
8+
- **[BC break]** Change YAML config to PHP. See [UPGRADE-3.0.md](UPGRADE-3.0.md) for step-by-step upgrade howto.
89
- Replace `Symplify\CodingStandard\Sniffs\Naming\[AbstractClassNameSniff, ClassNameSuffixByParentSniff, InterfaceNameSniff and TraitNameSniff]` with equivalent versions backported to this repository.
910
- Drop PHP 7.2 support.
10-
- **[BC break]** Change YAML config to PHP.
1111
- Upgrade to easy-coding-standard 9.
1212

1313
## 2.1.0 - 2020-11-25

README.md

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@ composer require --dev lmc/coding-standard
1717

1818
## Usage
1919

20-
1. Create `easy-coding-standard.yaml` file in root directory of your project and import the LMC code-style rules:
20+
1. Create `ecs.php` file in the root directory of your project and import the LMC code-style rules:
2121

22-
```yaml
23-
imports:
24-
- { resource: 'vendor/lmc/coding-standard/easy-coding-standard.yaml' }
22+
```php
23+
<?php declare(strict_types=1);
24+
25+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
26+
27+
return static function (ContainerConfigurator $containerConfigurator): void {
28+
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
29+
};
2530
```
2631

2732
2. Run the check command (for `src/` and `tests/` directories):
@@ -37,19 +42,88 @@ vendor/bin/ecs check src/ tests/
3742
"analyze": [
3843
"vendor/bin/ecs check src/ tests/ --ansi",
3944
"[... other scripts, like PHPStan etc.]"
40-
]
45+
],
46+
"fix": [
47+
"...",
48+
"vendor/bin/ecs check ./src/ ./tests/ --ansi --fix"
49+
],
4150
}
4251
```
4352

44-
### Exclude (skip) some checks or files
53+
Now you will be able to run the fix using `composer analyze` and execute automatic fixes with `composer fix`.
54+
55+
### Add custom checks or override default settings
56+
57+
On top of default code-style rules you are free to add any rules from [PHP-CS-Fixer] or [PHP_CodeSniffer].
58+
If needed, you can also override some default settings.
59+
60+
Be aware you must add these settings **after** import of the base LMC code-style:
61+
62+
```php
63+
<?php declare(strict_types=1);
64+
65+
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;
66+
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer;
67+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
68+
69+
return static function (ContainerConfigurator $containerConfigurator): void {
70+
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
71+
72+
$services = $containerConfigurator->services();
73+
74+
// Enforce line-length to 120 characters
75+
$services->set(LineLengthSniff::class)
76+
->property('absoluteLineLimit', 120);
77+
78+
// Tests must have @test annotation
79+
$services->set(PhpUnitTestAnnotationFixer::class)
80+
->call('configure', [['style' => 'annotation']]);
81+
};
82+
```
83+
84+
See [EasyCodingStandard docs](https://github.com/symplify/easy-coding-standard#configuration) for more configuration options.
85+
86+
87+
### Exclude (skip) checks or files
88+
89+
You can configure your `ecs.php` to entirely skip some files, disable specific checks of suppress specific errors.
90+
91+
Unlike adding/modifying checks, skips must be added **before** import of the base LMC code-style.
92+
93+
```php
94+
<?php declare(strict_types=1);
95+
96+
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
97+
use PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff;
98+
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
99+
use Symplify\EasyCodingStandard\ValueObject\Option;
100+
101+
return static function (ContainerConfigurator $containerConfigurator): void {
102+
$parameters = $containerConfigurator->parameters();
103+
104+
$parameters->set(
105+
Option::SKIP,
106+
[
107+
// Ignore specific check only in specific files
108+
ForbiddenFunctionsSniff::class => [__DIR__ . '/src-tests/bootstrap.php'],
109+
// Disable check entirely
110+
ArrayDeclarationSniff::class,
111+
// Skip one file
112+
__DIR__ . '/file/to/be/skipped.php',
113+
// Skip entire directory
114+
__DIR__ . '/ignored/directory/*',
115+
]
116+
);
117+
118+
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
119+
};
120+
```
45121

46-
You can configure EasyCodingStandard via `parameters` section of your `easy-coding-standard.yaml` to:
47-
- exclude a specific file from all checks (via [`exclude_files`](https://github.com/Symplify/EasyCodingStandard#ignore-what-you-cant-fix))
48-
- disable specific check completely or for some file(s) or directories (via [`skip`](https://github.com/Symplify/EasyCodingStandard#ignore-what-you-cant-fix))
122+
See [EasyCodingStandard docs](https://github.com/symplify/easy-coding-standard#configuration) for more configuration options.
49123

50124
### IDE integration
51125

52-
For integration with PHPStorm etc. follow instructions in EasyCodingStandard [README](https://github.com/Symplify/EasyCodingStandard#your-ide-integration).
126+
For integration with PHPStorm etc. follow instructions in EasyCodingStandard [README](https://github.com/symplify/easy-coding-standard#your-ide-integration).
53127

54128
## Changelog
55129
For latest changes see [CHANGELOG.md](CHANGELOG.md) file. We follow [Semantic Versioning](http://semver.org/).
@@ -59,5 +133,4 @@ This library is open source software licensed under the [MIT license](LICENCE.md
59133

60134
[PHP-CS-Fixer]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
61135
[PHP_CodeSniffer]: https://github.com/squizlabs/PHP_CodeSniffer
62-
[EasyCodingStandard]: https://github.com/Symplify/EasyCodingStandard
63-
[easy-coding-standard.yml]: https://github.com/lmc-eu/php-coding-standard/blob/main/easy-coding-standard.yml
136+
[EasyCodingStandard]: https://github.com/symplify/easy-coding-standard

UPGRADE-3.0.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ composer remove symplify/config-transformer --dev # the migration tool can now b
3535
Because of the nature of how ECS process the configuration (which is, in fact, the behavior of underlying
3636
symfony/dependency-injection), you must follow the order in which you add your customizations.
3737

38-
In your `ecs.php` add import of the lmc/coding-standard **after** you add `skip` parameter but **before** your custom code-style ajdustements:
38+
In your `ecs.php` add import of the lmc/coding-standard **after** you add `skip` parameter but **before** your custom
39+
code-style adjustments:
3940

4041
```diff
4142
// ...
@@ -46,7 +47,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
4647
$parameters = $containerConfigurator->parameters();
4748
$parameters->set(Option::SKIP, [__DIR__ . '/foo/bar']);
4849

49-
+ $containerConfigurator->import(__DIR__. '/vendor/lmc/coding-standard/ecs.php');
50+
+ $containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
5051

5152
// Your code style customizations and overrides of the default code-style must be placed AFTER the import
5253
$services->set(PhpUnitExpectationFixer::class)
@@ -66,16 +67,17 @@ return static function (ContainerConfigurator $containerConfigurator): void {
6667
$parameters = $containerConfigurator->parameters();
6768

6869
- $parameters->set('skip', [ForbiddenFunctionsSniff::class => ['src-tests/bootstrap.php']]);
69-
- $parameters->set('exclude_files', ['src/foo/bar.php']);
70-
+ $parameters->set(Option::SKIP, [
71-
+ ForbiddenFunctionsSniff::class => ['src-tests/bootstrap.php'],
72-
+ 'src/foo/bar.php',
70+
- $parameters->set('exclude_files', [__DIR__ . '/src/foo/bar.php']);
71+
+ $parameters->set(
72+
+ Option::SKIP,
73+
+ [
74+
+ ForbiddenFunctionsSniff::class => [__DIR__ . '/src-tests/bootstrap.php'],
75+
+ __DIR__ . '/src/foo/bar.php',
7376
+ ]
7477
+ );
7578

7679
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
7780
};
78-
7981
```
8082

8183
See [ECS documentation](https://github.com/symplify/easy-coding-standard/tree/master#configuration) for more configuration options.

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
],
4949
"analyze": [
5050
"vendor/bin/ecs check src/ tests/ ecs.php --ansi",
51+
"vendor/bin/ecs check-markdown README.md --ansi",
5152
"vendor/bin/phpstan analyze -c phpstan.neon --ansi"
5253
],
5354
"fix": [

0 commit comments

Comments
 (0)