update ecs config to newer version in devhelper chapter

This commit is contained in:
lubiana 2022-05-18 08:32:23 +02:00 committed by Andre Lubian
parent 63a5ae837c
commit 3f832d7c94

View file

@ -135,8 +135,10 @@ prepared one:
<?php declare(strict_types=1); <?php declare(strict_types=1);
use PhpCsFixer\Fixer\Import\OrderedImportsFixer; use PhpCsFixer\Fixer\Import\OrderedImportsFixer;
use PhpCsFixer\Fixer\Operator\NewWithBracesFixer;
use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer; use PhpCsFixer\Fixer\PhpTag\BlankLineAfterOpeningTagFixer;
use SlevomatCodingStandard\Sniffs\Classes\ClassConstantVisibilitySniff; use SlevomatCodingStandard\Sniffs\Classes\ClassConstantVisibilitySniff;
use SlevomatCodingStandard\Sniffs\ControlStructures\NewWithoutParenthesesSniff;
use SlevomatCodingStandard\Sniffs\Namespaces\AlphabeticallySortedUsesSniff; use SlevomatCodingStandard\Sniffs\Namespaces\AlphabeticallySortedUsesSniff;
use SlevomatCodingStandard\Sniffs\Namespaces\DisallowGroupUseSniff; use SlevomatCodingStandard\Sniffs\Namespaces\DisallowGroupUseSniff;
use SlevomatCodingStandard\Sniffs\Namespaces\MultipleUsesPerLineSniff; use SlevomatCodingStandard\Sniffs\Namespaces\MultipleUsesPerLineSniff;
@ -145,37 +147,41 @@ use SlevomatCodingStandard\Sniffs\Namespaces\ReferenceUsedNamesOnlySniff;
use SlevomatCodingStandard\Sniffs\Namespaces\UseSpacingSniff; use SlevomatCodingStandard\Sniffs\Namespaces\UseSpacingSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff; use SlevomatCodingStandard\Sniffs\TypeHints\DeclareStrictTypesSniff;
use SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff; use SlevomatCodingStandard\Sniffs\TypeHints\UnionTypeHintFormatSniff;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symplify\EasyCodingStandard\Config\ECSConfig;
use Symplify\EasyCodingStandard\ValueObject\Option; use Symplify\EasyCodingStandard\ValueObject\Option;
use Symplify\EasyCodingStandard\ValueObject\Set\SetList; use Symplify\EasyCodingStandard\ValueObject\Set\SetList;
return static function (ContainerConfigurator $containerConfigurator): void { return static function (ECSConfig $config): void {
$parameters = $containerConfigurator->parameters(); $parameters = $config->parameters();
$parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/ecs.php']); $parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/ecs.php']);
$parameters->set(Option::PARALLEL, true); $parameters->set(Option::PARALLEL, true);
$parameters->set(Option::SKIP, [BlankLineAfterOpeningTagFixer::class, OrderedImportsFixer::class]); $parameters->set(
Option::SKIP,
[BlankLineAfterOpeningTagFixer::class, OrderedImportsFixer::class, NewWithBracesFixer::class]
);
$containerConfigurator->import(SetList::PSR_12); $config->sets([
$containerConfigurator->import(SetList::STRICT); SetList::PSR_12,
$containerConfigurator->import(SetList::ARRAY); SetList::STRICT,
$containerConfigurator->import(SetList::SPACES); SetList::ARRAY,
$containerConfigurator->import(SetList::DOCBLOCK); SetList::SPACES,
$containerConfigurator->import(SetList::CLEAN_CODE); SetList::DOCBLOCK,
$containerConfigurator->import(SetList::COMMON); SetList::CLEAN_CODE,
$containerConfigurator->import(SetList::COMMENTS); SetList::COMMON,
$containerConfigurator->import(SetList::NAMESPACES); SetList::COMMENTS,
$containerConfigurator->import(SetList::SYMPLIFY); SetList::NAMESPACES,
$containerConfigurator->import(SetList::CONTROL_STRUCTURES); SetList::SYMPLIFY,
SetList::CONTROL_STRUCTURES,
]);
$services = $containerConfigurator->services(); $services = $config->services();
// force visibitily declaration on class constants // force visibility declaration on class constants
$services->set(ClassConstantVisibilitySniff::class) $services->set(ClassConstantVisibilitySniff::class)
->property('fixable', true); ->property('fixable', true);
// sort all use statements // sort all use statements
$services->set(AlphabeticallySortedUsesSniff::class); $services->set(AlphabeticallySortedUsesSniff::class);
$services->set(DisallowGroupUseSniff::class); $services->set(DisallowGroupUseSniff::class);
$services->set(MultipleUsesPerLineSniff::class); $services->set(MultipleUsesPerLineSniff::class);
$services->set(NamespaceSpacingSniff::class); $services->set(NamespaceSpacingSniff::class);
@ -209,8 +215,12 @@ return static function (ContainerConfigurator $containerConfigurator): void {
->property('withSpaces', 'no') ->property('withSpaces', 'no')
->property('shortNullable', 'no') ->property('shortNullable', 'no')
->property('nullPosition', 'last'); ->property('nullPosition', 'last');
// Remove useless parantheses in new statements
$services->set(NewWithoutParenthesesSniff::class);
}; };
``` ```
You can now use `./vendor/bin/ecs` to list all violations of the defined standard and `./vendor/bin/ecs --fix` to You can now use `./vendor/bin/ecs` to list all violations of the defined standard and `./vendor/bin/ecs --fix` to
automatically fix them. automatically fix them.