Skip to content

Commit afa1274

Browse files
author
Martin Guth
committed
Upgrade everything to its newest version, use PSR-12
1 parent bd166ab commit afa1274

19 files changed

+562
-638
lines changed

.github/workflows/tests.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ jobs:
1515

1616
strategy:
1717
matrix:
18-
php-version: ['7.3', '7.4', '8.0', '8.1']
18+
php-version: ['8.0', '8.1', '8.2', '8.3']
1919
dependencies: ['']
2020
include:
21-
- { php-version: '7.3', dependencies: '--prefer-lowest --prefer-stable' }
21+
- { php-version: '8.0', dependencies: '--prefer-lowest --prefer-stable' }
2222

2323
name: PHP ${{ matrix.php-version }} ${{ matrix.dependencies }}
2424

@@ -55,7 +55,7 @@ jobs:
5555
- name: Setup PHP
5656
uses: shivammathur/setup-php@v2
5757
with:
58-
php-version: '8.1'
58+
php-version: '8.3'
5959
extensions: mbstring, intl
6060
tools: composer:v2
6161

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -5,6 +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+
- Require PHP ^8.0
9+
- Update to slevomat/coding-standard ^8.0
10+
- Update to squizlabs/php_codesniffer ^3.9
11+
- Update to symplify/easy-coding-standard ^12.1
12+
- Move coding standard declarations from `ecs-7.4.php` and `ecs-8.0.php` to `ecs.php` and remove the former files
13+
- 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+
816

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

README.md

+46-44
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

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

7-
Standard is based on [PSR-2](https://www.php-fig.org/psr/psr-2/) and adds various checks to make sure the code is readable,
8-
does follow the same conventions and does not contain common mistakes.
7+
Standard is based on [PSR-12](https://www.php-fig.org/psr/psr-12/) and adds
8+
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].
1111

@@ -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;
25+
use Symplify\EasyCodingStandard\Config\ECSConfig;
2626

27-
return static function (ContainerConfigurator $containerConfigurator): void {
28-
$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
29-
30-
// Be default only checks compatible with PHP 7.3 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.
32-
33-
34-
// Import one of ecs-7.4.php, ecs-8.0.php or ecs-8.1.php. Use only one file (for the highest possible PHP version).
35-
//$containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs-7.4.php');
36-
};
27+
return ECSConfig::configure()
28+
->withSets(
29+
[
30+
__DIR__ . '/vendor/lmc/coding-standard/ecs.php',
31+
]
32+
);
33+
34+
// 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+
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).
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

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Upgrading from 3.x to 4.0
2+
3+
### 1. Update dependency in composer.json
4+
In require-dev section change the version constraint:
5+
6+
```diff
7+
- "lmc/coding-standard": "^3.3",
8+
+ "lmc/coding-standard": "^4.0",
9+
```
10+
11+
Then run `composer update`.
12+
13+
### 2. Configuration updates
14+
15+
Configuration now uses ECSConfig class instead of ContainerConfigurator. Update your `ecs.php` to use the new configuration style:
16+
17+
```diff
18+
-use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
19+
-
20+
-return static function (ContainerConfigurator $containerConfigurator): void {
21+
+use Symplify\EasyCodingStandard\Config\ECSConfig;
22+
+
23+
+return ECSConfig::configure()
24+
```
25+
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()`.
29+
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)
32+
33+
### 3. Remove imports of `ecs-7.4.php` and/or `ecs-8.0.php` from your `ecs.php`
34+
```diff
35+
->withSets(__DIR__ . '/vendor/lmc/coding-standard/ecs.php')
36+
- ->withSets(__DIR__ . '/vendor/lmc/coding-standard/ecs-7.4.php')
37+
- ->withSets(__DIR__ . '/vendor/lmc/coding-standard/ecs-8.0.php')
38+
->withSets(__DIR__ . '/vendor/lmc/coding-standard/ecs-8.1.php')
39+
```
40+
41+
### 4. Sanity check
42+
Besides running your code style checks, you can ensure all predefined LMC checks are loaded as well, by running:
43+
44+
```sh
45+
vendor/bin/ecs list-checkers
46+
```
47+
48+
The result should end with something like:
49+
```
50+
41 checkers from PHP_CodeSniffer:
51+
...
52+
147 checkers from PHP-CS-Fixer:
53+
...
54+
2 checkers are skipped:
55+
...
56+
```
57+
58+
(or some close number, depending on your custom code-style settings).

composer.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.3 || ^8.0",
13+
"php": "^8.0",
1414
"friendsofphp/php-cs-fixer": "^3.0",
1515
"nette/utils": "^3.2",
16-
"slevomat/coding-standard": "^6.4.1 || ^7.0",
17-
"squizlabs/php_codesniffer": "^3.6",
18-
"symplify/easy-coding-standard": "^10.0 <10.2.4"
16+
"slevomat/coding-standard": "^8.0",
17+
"squizlabs/php_codesniffer": "^3.9",
18+
"symplify/easy-coding-standard": "^12.1.4"
1919
},
2020
"require-dev": {
2121
"ergebnis/composer-normalize": "^2.13.2",
@@ -24,7 +24,7 @@
2424
"phpstan/extension-installer": "^1.1",
2525
"phpstan/phpstan": "^1.3.0",
2626
"phpstan/phpstan-phpunit": "^1.0.0",
27-
"phpunit/phpunit": "^9.5.2"
27+
"phpunit/phpunit": "^9.6.19"
2828
},
2929
"prefer-stable": true,
3030
"autoload": {
@@ -55,16 +55,16 @@
5555
"@test"
5656
],
5757
"analyze": [
58-
"vendor/bin/ecs check src/ tests/ ecs.php ecs-7.4.php ecs-8.0.php ecs-8.1.php --ansi",
59-
"vendor/bin/ecs check-markdown README.md --ansi",
58+
"vendor/bin/ecs check src/ tests/ ecs.php ecs-8.1.php ecs-8.2.php ecs-8.3.php --ansi",
59+
"vendor/bin/ecs check README.md --ansi",
6060
"vendor/bin/phpstan analyze -c phpstan.neon --ansi"
6161
],
6262
"fix": [
6363
"@composer normalize",
64-
"vendor/bin/ecs check ./src/ ./tests/ ecs.php ecs-7.4.php ecs-8.0.php ecs-8.1.php --ansi --fix"
64+
"vendor/bin/ecs check ./src/ ./tests/ ecs.php ecs-8.1.php ecs-8.2.php ecs-8.3.php --ansi --fix"
6565
],
6666
"lint": [
67-
"vendor/bin/parallel-lint -j 10 -e php ./src ./tests ecs.php ecs-7.4.php ecs-8.0.php ecs-8.1.php",
67+
"vendor/bin/parallel-lint -j 10 -e php ./src ./tests ecs.php ecs-8.1.php ecs-8.2.php ecs-8.3.php",
6868
"@composer validate",
6969
"@composer normalize --dry-run"
7070
],

ecs-7.4.php

-17
This file was deleted.

ecs-8.0.php

-93
This file was deleted.

ecs-8.1.php

+2-13
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
11
<?php declare(strict_types=1);
22

3-
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
3+
use Symplify\EasyCodingStandard\Config\ECSConfig;
44

5-
return static function (ContainerConfigurator $containerConfigurator): void {
6-
$containerConfigurator->import(__DIR__ . '/ecs-8.0.php');
7-
8-
// class with constants only -> enum
9-
// @see https://www.php.net/releases/8.1/en.php#enumerations
10-
11-
// readonly properties
12-
// @see https://www.php.net/releases/8.1/en.php#readonly_properties
13-
14-
// first-class callable
15-
// @see https://www.php.net/releases/8.1/en.php#first_class_callable_syntax
16-
};
5+
return ECSConfig::configure();

0 commit comments

Comments
 (0)