4
4
5
5
PHP coding standard used in [ LMC] ( https://www.lmc.eu/en/ ) projects.
6
6
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.
9
9
10
10
We use [ EasyCodingStandard] to define and execute checks created for both [ PHP-CS-Fixer] and [ PHP_CodeSniffer] .
11
11
@@ -22,18 +22,27 @@ composer require --dev lmc/coding-standard
22
22
``` php
23
23
<?php declare(strict_types=1);
24
24
25
- use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator ;
25
+ use Symplify\EasyCodingStandard\Config\ECSConfig ;
26
26
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
+ //);
37
46
```
38
47
39
48
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
71
80
72
81
use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;
73
82
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;
80
84
85
+ return ECSConfig::configure()
86
+ ->withSets(
87
+ [
88
+ __DIR__ . '/vendor/lmc/coding-standard/ecs.php',
89
+ ]
90
+ )
81
91
// Enforce line-length to 120 characters
82
- $services->set(LineLengthSniff::class)
83
- ->property('absoluteLineLimit', 120);
84
-
92
+ ->withConfiguredRule(LineLengthSniff::class, ['absoluteLineLimit' => 120])
85
93
// Tests must have @test annotation
86
- $services->set(PhpUnitTestAnnotationFixer::class)
87
- ->call('configure', [['style' => 'annotation']]);
88
- };
94
+ ->withConfiguredRule(PhpUnitTestAnnotationFixer::class, ['style' => 'annotation']);
89
95
```
90
96
91
97
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
102
108
103
109
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
104
110
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(
113
125
[
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',
122
127
]
123
128
);
124
-
125
- $containerConfigurator->import(__DIR__ . '/vendor/lmc/coding-standard/ecs.php');
126
- };
127
129
```
128
130
129
131
See [ EasyCodingStandard docs] ( https://github.com/symplify/easy-coding-standard#configuration ) for more configuration options.
0 commit comments