Skip to content

Commit 9f52274

Browse files
author
Martin Guth
committed
fixup! Upgrade everything to its newest version, use PSR-12
1 parent f8c1b3a commit 9f52274

File tree

5 files changed

+47
-46
lines changed

5 files changed

+47
-46
lines changed

CHANGELOG.md

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

77
## Unreleased
8-
- Lock PHP support to 8.0+
8+
- Require PHP ^8.0
99
- Update to slevomat/coding-standard ^8.0
1010
- Update to squizlabs/php_codesniffer ^3.9
1111
- Update to symplify/easy-coding-standard ^12.1
1212
- Move coding standard declarations from `ecs-7.4.php` and `ecs-8.0.php` to `ecs.php` and remove the former files
1313
- Change deprecated rules to new ones
14-
- Add new `ecs-8.2.php` coding standard declaration file for PHP 8.2+.
15-
- Add new `ecs-8.3.php` coding standard declaration file for PHP 8.3+.
14+
- Add new `ecs-8.2.php` coding standard declaration file for PHP 8.2+
15+
- Add new `ecs-8.3.php` coding standard declaration file for PHP 8.3+
1616

1717
## 3.3.1 - 2022-05-23
1818
- Lock `symplify/easy-coding-standard` to <10.2.4 because of backward incompatibilities introduced in its bugfix releases.

README.md

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
PHP coding standard used in [LMC](https://www.lmc.eu/en/) projects.
66

7-
Standard is based on [PSR-12](https://www.php-fig.org/psr/psr-12/) (from version 4.0, before it was PSR-2) and adds
7+
Standard is based on [PSR-12](https://www.php-fig.org/psr/psr-12/) and adds
88
various checks to make sure the code is readable, does follow the same conventions and does not contain common mistakes.
99

1010
We use [EasyCodingStandard] to define and execute checks created for both [PHP-CS-Fixer] and [PHP_CodeSniffer].
@@ -22,18 +22,27 @@ composer require --dev lmc/coding-standard
2222
```php
2323
<?php declare(strict_types=1);
2424

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');
25+
use Symplify\EasyCodingStandard\Config\ECSConfig;
2926

27+
return ECSConfig::configure()
28+
->withSets(
29+
[
30+
__DIR__ . '/vendor/lmc/coding-standard/ecs.php',
31+
]
32+
);
33+
3034
// Be default only checks compatible with PHP 8.0 are enabled.
31-
// Depending on the lowest PHP version your project need to support, you can enable additional checks for PHP 7.4, 8.0 or 8.1.
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.
3237

3338

3439
// 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).
35-
//$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs-8.3.php');
36-
};
40+
//->withSets(
41+
// [
42+
// __DIR__ . '/vendor/lmc/coding-standard/ecs.php',
43+
// __DIR__ . '/vendor/lmc/coding-standard/ecs-8.3.php',
44+
// ]
45+
//);
3746
```
3847

3948
2. Run the check command (for `src/` and `tests/` directories):
@@ -71,21 +80,18 @@ Be aware you must add these settings **after** import of the base LMC code-style
7180

7281
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;
7382
use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestAnnotationFixer;
74-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
75-
76-
return static function (ContainerConfigurator $containerConfigurator): void {
77-
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
78-
79-
$services = $containerConfigurator->services();
83+
use Symplify\EasyCodingStandard\Config\ECSConfig;
8084

85+
return ECSConfig::configure()
86+
->withSets(
87+
[
88+
__DIR__ . '/vendor/lmc/coding-standard/ecs.php',
89+
]
90+
)
8191
// Enforce line-length to 120 characters
82-
$services->set(LineLengthSniff::class)
83-
->property('absoluteLineLimit', 120);
84-
92+
->withConfiguredRule(LineLengthSniff::class, ['absoluteLineLimit' => 120])
8593
// Tests must have @test annotation
86-
$services->set(PhpUnitTestAnnotationFixer::class)
87-
->call('configure', [['style' => 'annotation']]);
88-
};
94+
->withConfiguredRule(PhpUnitTestAnnotationFixer::class, ['style' => 'annotation']);
8995
```
9096

9197
See [EasyCodingStandard docs](https://github.com/symplify/easy-coding-standard#configuration) for more configuration options.
@@ -102,28 +108,24 @@ Unlike adding/modifying checks, skips must be added **before** import of the bas
102108

103109
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
104110
use PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff;
105-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
106-
use Symplify\EasyCodingStandard\ValueObject\Option;
107-
108-
return static function (ContainerConfigurator $containerConfigurator): void {
109-
$parameters = $containerConfigurator->parameters();
110-
111-
$parameters->set(
112-
Option::SKIP,
111+
use Symplify\EasyCodingStandard\Config\ECSConfig;
112+
113+
return ECSConfig::configure()
114+
->withSkip([
115+
// Ignore specific check only in specific files
116+
ForbiddenFunctionsSniff::class => [__DIR__ . '/src-tests/bootstrap.php'],
117+
// Disable check entirely
118+
ArrayDeclarationSniff::class,
119+
// Skip one file
120+
__DIR__ . '/file/to/be/skipped.php',
121+
// Skip entire directory
122+
__DIR__ . '/ignored/directory/*',
123+
])
124+
->withSets(
113125
[
114-
// Ignore specific check only in specific files
115-
ForbiddenFunctionsSniff::class => [__DIR__ . '/src-tests/bootstrap.php'],
116-
// Disable check entirely
117-
ArrayDeclarationSniff::class,
118-
// Skip one file
119-
__DIR__ . '/file/to/be/skipped.php',
120-
// Skip entire directory
121-
__DIR__ . '/ignored/directory/*',
126+
__DIR__ . '/vendor/lmc/coding-standard/ecs.php',
122127
]
123128
);
124-
125-
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
126-
};
127129
```
128130

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

UPGRADE-4.0.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ Rules are now set using `ECSConfig::configure()->withRules([])` or `ECSConfig::c
2727
Skiping tests is now done using `ECSConfig::configure()->withSkip()` instead of `$parameters->set(Option::SKIP, ...)`.
2828
Imports are now done using `ECSConfig::configure()->withSets()` instead of `$containerConfigurator->import()`.
2929

30-
See [ECS documentation](https://github.com/easy-coding-standard/easy-coding-standard/tree/main?tab=readme-ov-file#configure) for more configuration options and examples.
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)
3132

3233
### 3. Remove imports of `ecs-7.4.php` and/or `ecs-8.0.php` from your `ecs.php`
3334
```diff

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"nette/utils": "^3.2",
1616
"slevomat/coding-standard": "^8.0",
1717
"squizlabs/php_codesniffer": "^3.9",
18-
"symplify/easy-coding-standard": "^12.1"
18+
"symplify/easy-coding-standard": "^12.1.4"
1919
},
2020
"require-dev": {
2121
"ergebnis/composer-normalize": "^2.13.2",

ecs.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,6 @@
459459
->withConfiguredRule(OperatorSpacingSniff::class, ['ignoreNewlines' => true])
460460
// PHP arrays should be declared using the configured syntax
461461
->withConfiguredRule(ArraySyntaxFixer::class, ['syntax' => 'short'])
462-
// The body of each structure MUST be enclosed by braces. Braces should be properly placed
463-
->withConfiguredRule(BracesFixer::class, ['allow_single_line_closure' => true, 'allow_single_line_anonymous_class_with_empty_body' => true])
464462
// Class, trait and interface elements must be separated with one or none blank line
465463
->withConfiguredRule(ClassAttributesSeparationFixer::class, ['elements' => ['method' => 'one']])
466464
// Visibility MUST be declared on all properties, methods and class constants

0 commit comments

Comments
 (0)