From 3f832d7c9421e46ac078cbad424b89dc84ee3d96 Mon Sep 17 00:00:00 2001 From: lubiana Date: Wed, 18 May 2022 08:32:23 +0200 Subject: [PATCH] update ecs config to newer version in devhelper chapter --- 04-development-helpers.md | 46 ++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/04-development-helpers.md b/04-development-helpers.md index bde29e0..b2aece8 100644 --- a/04-development-helpers.md +++ b/04-development-helpers.md @@ -135,8 +135,10 @@ prepared one: parameters(); +return static function (ECSConfig $config): void { + $parameters = $config->parameters(); $parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/ecs.php']); $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); - $containerConfigurator->import(SetList::STRICT); - $containerConfigurator->import(SetList::ARRAY); - $containerConfigurator->import(SetList::SPACES); - $containerConfigurator->import(SetList::DOCBLOCK); - $containerConfigurator->import(SetList::CLEAN_CODE); - $containerConfigurator->import(SetList::COMMON); - $containerConfigurator->import(SetList::COMMENTS); - $containerConfigurator->import(SetList::NAMESPACES); - $containerConfigurator->import(SetList::SYMPLIFY); - $containerConfigurator->import(SetList::CONTROL_STRUCTURES); + $config->sets([ + SetList::PSR_12, + SetList::STRICT, + SetList::ARRAY, + SetList::SPACES, + SetList::DOCBLOCK, + SetList::CLEAN_CODE, + SetList::COMMON, + SetList::COMMENTS, + SetList::NAMESPACES, + 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) ->property('fixable', true); // sort all use statements $services->set(AlphabeticallySortedUsesSniff::class); - $services->set(DisallowGroupUseSniff::class); $services->set(MultipleUsesPerLineSniff::class); $services->set(NamespaceSpacingSniff::class); @@ -209,8 +215,12 @@ return static function (ContainerConfigurator $containerConfigurator): void { ->property('withSpaces', 'no') ->property('shortNullable', 'no') ->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 automatically fix them.