|
| 1 | +# Upgrading from 4.x to 5.0 |
| 2 | + |
| 3 | +### 1. Update dependency in composer.json |
| 4 | +In the `require-dev` section of `composer.json` change the version constraint: |
| 5 | + |
| 6 | +```diff |
| 7 | +- "almacareer/coding-standard": "^4.2", |
| 8 | ++ "almacareer/coding-standard": "^5.0", |
| 9 | +``` |
| 10 | + |
| 11 | +Then run `composer update almacareer/coding-standard`. |
| 12 | + |
| 13 | +### 2. Update namespace imports |
| 14 | + |
| 15 | +**[BC break]** The namespace has been changed from `Lmc\CodingStandard` to `AlmaOss\CodingStandard`. |
| 16 | + |
| 17 | +Update your `ecs.php` file to use the new namespace: |
| 18 | + |
| 19 | +```diff |
| 20 | +<?php |
| 21 | + |
| 22 | +declare(strict_types=1); |
| 23 | + |
| 24 | +-use Lmc\CodingStandard\Set\SetList; |
| 25 | ++use AlmaOss\CodingStandard\Set\SetList; |
| 26 | + use Symplify\EasyCodingStandard\Config\ECSConfig; |
| 27 | + |
| 28 | +return ECSConfig::configure() |
| 29 | + ->withSets( |
| 30 | + [ |
| 31 | + SetList::ALMACAREER, |
| 32 | + ] |
| 33 | + ); |
| 34 | +``` |
| 35 | + |
| 36 | +If you are using any custom sniffs or fixers from this package in your configuration, update their namespace as well: |
| 37 | + |
| 38 | +```diff |
| 39 | +-use Lmc\CodingStandard\Fixer\SpecifyArgSeparatorFixer; |
| 40 | ++use AlmaOss\CodingStandard\Fixer\SpecifyArgSeparatorFixer; |
| 41 | + |
| 42 | +-use Lmc\CodingStandard\Sniffs\Naming\ClassNameSuffixByParentSniff; |
| 43 | ++use AlmaOss\CodingStandard\Sniffs\Naming\ClassNameSuffixByParentSniff; |
| 44 | +``` |
| 45 | + |
| 46 | +### 3. PSR-12 compliance change |
| 47 | + |
| 48 | +**[BC break]** The `BlankLineAfterOpeningTagFixer` is no longer skipped. This means that a blank line after the opening PHP tag (`<?php`) is now required to be PSR-12 compliant. |
| 49 | + |
| 50 | +Before (no longer valid): |
| 51 | +```php |
| 52 | +<?php |
| 53 | +declare(strict_types=1); |
| 54 | +``` |
| 55 | + |
| 56 | +After (PSR-12 compliant): |
| 57 | +```php |
| 58 | +<?php |
| 59 | + |
| 60 | +declare(strict_types=1); |
| 61 | +``` |
| 62 | + |
| 63 | +If your codebase does not follow this convention yet, running `vendor/bin/ecs check --fix` will automatically add the blank lines. |
| 64 | + |
| 65 | +If you want to keep the old behavior and skip this check, you can add it to your `ecs.php`: |
| 66 | + |
| 67 | +```php |
| 68 | +use PhpCsFixer\Fixer\Whitespace\BlankLineAfterOpeningTagFixer; |
| 69 | + |
| 70 | +return ECSConfig::configure() |
| 71 | + // ... |
| 72 | + ->withSkip([ |
| 73 | + BlankLineAfterOpeningTagFixer::class, |
| 74 | + ]); |
| 75 | +``` |
| 76 | + |
| 77 | +### 4. Run the code style checks |
| 78 | + |
| 79 | +After updating the namespace, run the code style checks to ensure everything is working correctly: |
| 80 | + |
| 81 | +```bash |
| 82 | +vendor/bin/ecs check |
| 83 | +``` |
| 84 | + |
| 85 | +To automatically fix the code style issues (including the blank line after opening tag): |
| 86 | + |
| 87 | +```bash |
| 88 | +vendor/bin/ecs check --fix |
| 89 | +``` |
| 90 | + |
| 91 | +### 5. Sanity check |
| 92 | + |
| 93 | +You can ensure all predefined checks are loaded by running: |
| 94 | + |
| 95 | +```sh |
| 96 | +vendor/bin/ecs list-checkers |
| 97 | +``` |
| 98 | + |
| 99 | +The output should show all the loaded checkers from both PHP-CS-Fixer and PHP_CodeSniffer. |
0 commit comments