Skip to content

Commit 0014a8c

Browse files
authored
Merge pull request #87 from lmc-eu/feature/readme-update
Extend upgrade guidance and readme
2 parents c99ff0f + 684591d commit 0014a8c

File tree

2 files changed

+68
-18
lines changed

2 files changed

+68
-18
lines changed

README.md

+13-8
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ composer require --dev lmc/coding-standard
2525
use Symplify\EasyCodingStandard\Config\ECSConfig;
2626

2727
return ECSConfig::configure()
28+
->withPaths([__DIR__ . '/src', __DIR__ . '/tests']) // optionally add 'config' or other directories with PHP files
29+
->withRootFiles() // to include ecs.php and all other php files in the root directory
2830
->withSets(
2931
[
3032
__DIR__ . '/vendor/lmc/coding-standard/ecs.php',
3133
]
3234
);
3335

3436
// Be default only checks compatible with PHP 8.0 are enabled.
35-
// Depending on the lowest PHP version your project need to support, you can enable additional checks for
36-
// PHP 8.1, 8.2 and 8.3.
37+
// Depending on the lowest PHP version your project needs to support, you can enable additional checks.
3738

38-
39-
// Import one of ecs-8.1.php, ecs-8.2.php or ecs-8.3.php. Use only one file (for the highest possible PHP version).
39+
// Import one of ecs-8.1.php, ecs-8.2.php or ecs-8.3.php. Use only one additional file (for the highest possible
40+
// PHP version), the configs for previous versions are automatically included.
4041
//->withSets(
4142
// [
4243
// __DIR__ . '/vendor/lmc/coding-standard/ecs.php',
@@ -45,23 +46,23 @@ return ECSConfig::configure()
4546
//);
4647
```
4748

48-
2. Run the check command (for `src/` and `tests/` directories):
49+
2. Run the check command
4950

5051
```bash
51-
vendor/bin/ecs check src/ tests/
52+
vendor/bin/ecs check
5253
```
5354

5455
3. Optionally we recommend adding this to `scripts` section of your `composer.json`:
5556

5657
```json
5758
"scripts": {
5859
"analyze": [
59-
"vendor/bin/ecs check src/ tests/ --ansi",
60+
"vendor/bin/ecs check --ansi",
6061
"[... other scripts, like PHPStan etc.]"
6162
],
6263
"fix": [
6364
"...",
64-
"vendor/bin/ecs check ./src/ ./tests/ --ansi --fix"
65+
"vendor/bin/ecs check --ansi --fix"
6566
],
6667
}
6768
```
@@ -83,6 +84,7 @@ use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer;
8384
use Symplify\EasyCodingStandard\Config\ECSConfig;
8485

8586
return ECSConfig::configure()
87+
/* (...) */
8688
->withSets(
8789
[
8890
__DIR__ . '/vendor/lmc/coding-standard/ecs.php',
@@ -92,6 +94,7 @@ return ECSConfig::configure()
9294
->withConfiguredRule(LineLengthSniff::class, ['absoluteLineLimit' => 120])
9395
// Tests must have @test annotation
9496
->withConfiguredRule(PhpUnitTestAnnotationFixer::class, ['style' => 'annotation']);
97+
/* (...) */
9598
```
9699

97100
See [EasyCodingStandard docs](https://github.com/symplify/easy-coding-standard#configuration) for more configuration options.
@@ -111,6 +114,7 @@ use PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff;
111114
use Symplify\EasyCodingStandard\Config\ECSConfig;
112115

113116
return ECSConfig::configure()
117+
/* (...) */
114118
->withSkip([
115119
// Ignore specific check only in specific files
116120
ForbiddenFunctionsSniff::class => [__DIR__ . '/src-tests/bootstrap.php'],
@@ -126,6 +130,7 @@ return ECSConfig::configure()
126130
__DIR__ . '/vendor/lmc/coding-standard/ecs.php',
127131
]
128132
);
133+
/* (...) */
129134
```
130135

131136
See [EasyCodingStandard docs](https://github.com/symplify/easy-coding-standard#configuration) for more configuration options.

UPGRADE-4.0.md

+55-10
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,34 @@ In require-dev section change the version constraint:
1111
Then run `composer update`.
1212

1313
### 2. Configuration updates
14+
Configuration now uses `ECSConfig` class instead of `ContainerConfigurator`.
1415

15-
Configuration now uses ECSConfig class instead of ContainerConfigurator. Update your `ecs.php` to use the new configuration style:
16+
Update your `ecs.php` to use the new configuration style:
1617

1718
```diff
1819
-use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
19-
-
20-
-return static function (ContainerConfigurator $containerConfigurator): void {
2120
+use Symplify\EasyCodingStandard\Config\ECSConfig;
22-
+
21+
22+
-return static function (ContainerConfigurator $containerConfigurator): void {
2323
+return ECSConfig::configure()
24+
+ ->withSets([
25+
+ __DIR__ . '/vendor/lmc/coding-standard/ecs.php',
26+
+ ]);
27+
// ...
2428
```
2529

26-
Rules are now set using `ECSConfig::configure()->withRules([])` or `ECSConfig::configure()->withConfiguredRule()` instead of `$services->set()`.
27-
Skiping tests is now done using `ECSConfig::configure()->withSkip()` instead of `$parameters->set(Option::SKIP, ...)`.
28-
Imports are now done using `ECSConfig::configure()->withSets()` instead of `$containerConfigurator->import()`.
30+
Now change the way you set rules, skip tests and import sets:
31+
32+
| Old Method | New Method |
33+
|---------------------------------------|-------------------------------------------------------------------------------------------|
34+
| `$services->set()` | `ECSConfig::configure()->withRules([])` or `ECSConfig::configure()->withConfiguredRule()` |
35+
| `$parameters->set(Option::SKIP, ...)` | `ECSConfig::configure()->withSkip()` |
36+
| `$containerConfigurator->import()` | `ECSConfig::configure()->withSets()` |
2937

30-
See [ECS documentation](https://github.com/easy-coding-standard/easy-coding-standard/tree/main?tab=readme-ov-file#configure) for more configuration options
31-
Examples of configurations can be seen [here](https://tomasvotruba.com/blog/new-in-ecs-simpler-config)
38+
See [examples in Usage section of our README](https://github.com/lmc-eu/php-coding-standard?tab=readme-ov-file#usage)
39+
or more configuration options in [ECS documentation](https://github.com/easy-coding-standard/easy-coding-standard/tree/main?tab=readme-ov-file#configure).
40+
41+
Some more reasoning and examples of configurations can also be seen [in ECS author blogpost](https://tomasvotruba.com/blog/new-in-ecs-simpler-config).
3242

3343
### 3. Remove imports of `ecs-7.4.php` and/or `ecs-8.0.php` from your `ecs.php`
3444
```diff
@@ -38,7 +48,42 @@ Examples of configurations can be seen [here](https://tomasvotruba.com/blog/new-
3848
->withSets(__DIR__ . '/vendor/lmc/coding-standard/ecs-8.1.php')
3949
```
4050

41-
### 4. Sanity check
51+
### 4. Configure paths directly in ecs.php
52+
53+
Paths definition could now be included directly in `ecs.php` instead of repeating them on command line.
54+
55+
In `ecs.php`:
56+
```php
57+
// ...
58+
return ECSConfig::configure()
59+
->withPaths([__DIR__ . '/src', __DIR__ . '/tests']) // optionally add 'config' or other directories with PHP files
60+
->withRootFiles() // to include ecs.php and all other php files in the root directory
61+
// ...
62+
```
63+
64+
Now you can remove the explicit paths definition from `composer.json`:
65+
```diff
66+
{
67+
"scripts": {
68+
"analyze": [
69+
- "vendor/bin/ecs check --ansi src/ tests/"
70+
+ "vendor/bin/ecs check --ansi"
71+
],
72+
"fix": [
73+
- "vendor/bin/ecs check --ansi --fix src/ tests/"
74+
+ "vendor/bin/ecs check --ansi --fix"
75+
]
76+
}
77+
}
78+
```
79+
80+
Or run directly from command line without a need of specifying them:
81+
```bash
82+
$ vendor/bin/ecs check --ansi src/ tests/ # old
83+
$ vendor/bin/ecs check --ansi # new
84+
```
85+
86+
### 5. Sanity check
4287
Besides running your code style checks, you can ensure all predefined LMC checks are loaded as well, by running:
4388

4489
```sh

0 commit comments

Comments
 (0)