44
55PHP 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
1010We 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
39482 . 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
7281use PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff;
7382use 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
9197See [ 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
103109use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
104110use 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
129131See [ EasyCodingStandard docs] ( https://github.com/symplify/easy-coding-standard#configuration ) for more configuration options.
0 commit comments