|
| 1 | +# Upgrading from 2.x to 3.0 |
| 2 | + |
| 3 | +The main backward compatibility break in lmc/coding-standard version 3.0 is new PHP format used for |
| 4 | +code-style configuration. However, the changes are mostly "mechanical" and most of them can be automated. |
| 5 | + |
| 6 | +### 1. Update dependency in composer.json |
| 7 | +In require-dev section change the version constraint: |
| 8 | + |
| 9 | +```diff |
| 10 | +- "lmc/coding-standard": "^2.1", |
| 11 | ++ "lmc/coding-standard": "^3.0", |
| 12 | +``` |
| 13 | + |
| 14 | +Then run `composer update`. |
| 15 | + |
| 16 | +### 2. Change your easy-coding-standard.yaml |
| 17 | +Remove import section (otherwise the migration in step 3. won't work): |
| 18 | +```diff |
| 19 | +-imports: |
| 20 | +- - { resource: 'vendor/lmc/coding-standard/easy-coding-standard.yaml' } |
| 21 | +``` |
| 22 | + |
| 23 | +### 3. Automatically migrate config from `easy-coding-standard.yaml` to `ecs.php` |
| 24 | +Run following commands: |
| 25 | + |
| 26 | +```sh |
| 27 | +composer require symplify/config-transformer --dev |
| 28 | +vendor/bin/config-transformer switch-format easy-coding-standard.yaml --input-format yaml --output-format php |
| 29 | +mv easy-coding-standard.php ecs.php # rename to ecs.php |
| 30 | +composer remove symplify/config-transformer --dev # the migration tool can now be removed again |
| 31 | +``` |
| 32 | + |
| 33 | +### 4. Add import of the base `ecs.php` from lmc/coding-standard |
| 34 | + |
| 35 | +Because of the nature of how ECS process the configuration (which is, in fact, the behavior of underlying |
| 36 | +symfony/dependency-injection), you must follow the order in which you add your customizations. |
| 37 | + |
| 38 | +In your `ecs.php` add import of the lmc/coding-standard **after** you add `skip` parameter but **before** your custom code-style ajdustements: |
| 39 | + |
| 40 | +```diff |
| 41 | +// ... |
| 42 | +return static function (ContainerConfigurator $containerConfigurator): void { |
| 43 | + $parameters = $containerConfigurator->parameters(); |
| 44 | + |
| 45 | + // Your skips - excluding fixers of paths must be placed BEFORE the import |
| 46 | + $parameters = $containerConfigurator->parameters(); |
| 47 | + $parameters->set(Option::SKIP, [__DIR__ . '/foo/bar']); |
| 48 | + |
| 49 | ++ $containerConfigurator->import(__DIR__. '/vendor/lmc/coding-standard/ecs.php'); |
| 50 | + |
| 51 | + // Your code style customizations and overrides of the default code-style must be placed AFTER the import |
| 52 | + $services->set(PhpUnitExpectationFixer::class) |
| 53 | + ->call('configure', [['target' => '5.6']]); |
| 54 | +}; |
| 55 | +``` |
| 56 | + |
| 57 | +### 5. Configuration updates |
| 58 | + |
| 59 | +There are also few changes in configuration properties. The most notable is `skip` parameter, |
| 60 | +which is used for all path and sniff exclusions. So values from previous `skip`, `exclude_files` should all be merged into `skip`. |
| 61 | + |
| 62 | +```diff |
| 63 | ++use Symplify\EasyCodingStandard\ValueObject\Option; |
| 64 | + |
| 65 | +return static function (ContainerConfigurator $containerConfigurator): void { |
| 66 | + $parameters = $containerConfigurator->parameters(); |
| 67 | + |
| 68 | +- $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', |
| 73 | ++ ] |
| 74 | ++ ); |
| 75 | + |
| 76 | + $containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php'); |
| 77 | +}; |
| 78 | + |
| 79 | +``` |
| 80 | + |
| 81 | +See [ECS documentation](https://github.com/symplify/easy-coding-standard/tree/master#configuration) for more configuration options. |
| 82 | + |
| 83 | +### 6. Sanity check |
| 84 | +Besides running your code style checks, you can ensure all predefined LMC checks are loaded as well, by running: |
| 85 | + |
| 86 | +```sh |
| 87 | +vendor/bin/ecs show |
| 88 | +``` |
| 89 | + |
| 90 | +The result should end with something like: |
| 91 | +``` |
| 92 | + [OK] Loaded 164 checkers in total |
| 93 | +``` |
| 94 | + |
| 95 | +(or some close number, depending on your custom code-style settings). |
0 commit comments