Skip to content

Commit 7d226ff

Browse files
committed
Docs: Extend UPGRADE-4.0.md with more examples and recommendations
1 parent 7e59eeb commit 7d226ff

File tree

1 file changed

+55
-10
lines changed

1 file changed

+55
-10
lines changed

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)