From cbce4cf403582efd81eaa0c11dd308108bd92bf5 Mon Sep 17 00:00:00 2001 From: core23 Date: Sun, 16 Jan 2022 21:52:26 +0100 Subject: [PATCH 1/5] Clean build matrix --- .github/workflows/continuous-integration.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index e1fc35d..ffb0603 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -12,7 +12,7 @@ jobs: run: uses: "nucleos/actions/.github/workflows/continuous-integration.yml@main" with: - PHP_EXTENSIONS: "mbstring, json, mongodb" - SYMFONY_KERNEL: "Nucleos\\SonataAutoConfigureBundle\\Tests\\App\\AppKernel" + PHP_EXTENSIONS: "mbstring" + SYMFONY_VERSIONS: "5.4" secrets: CODECOV_TOKEN: "${{ secrets.CODECOV_TOKEN }}" From 52cfdb94dc35efaa9fe6207df634ad6ab249c650 Mon Sep 17 00:00:00 2001 From: core23 Date: Sun, 16 Jan 2022 21:56:42 +0100 Subject: [PATCH 2/5] Add type hints --- phpstan-baseline.neon | 80 ++++++++++++++++ psalm-baseline.xml | 13 ++- psalm.xml | 1 + src/Annotation/Admin.php | 91 +++++-------------- src/Annotation/AdminExtension.php | 17 ++-- .../AutoConfigureAdminClassesCompilerPass.php | 46 ++++------ ...toConfigureAdminExtensionsCompilerPass.php | 7 +- .../SonataAutoConfigureExtension.php | 3 + src/Exception/EntityNotFound.php | 3 + ...oConfigureAdminClassesCompilerPassTest.php | 19 ++-- ...utoConfigureExtensionsCompilerPassTest.php | 18 ++-- tests/SonataAutoConfigureBundleTest.php | 11 +-- 12 files changed, 176 insertions(+), 133 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 364905f..375ae63 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,2 +1,82 @@ parameters: ignoreErrors: + - + message: "#^Implicit array creation is not allowed \\- variable \\$annotationDefaults does not exist\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php + + - + message: "#^Method Nucleos\\\\SonataAutoConfigureBundle\\\\DependencyInjection\\\\Compiler\\\\AutoConfigureAdminClassesCompilerPass\\:\\:findEntity\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php + + - + message: "#^Method Nucleos\\\\SonataAutoConfigureBundle\\\\DependencyInjection\\\\Compiler\\\\AutoConfigureAdminClassesCompilerPass\\:\\:setDefaultValuesForAnnotation\\(\\) has parameter \\$defaults with no value type specified in iterable type array\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php + + - + message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\\\|T of object, string\\|null given\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php + + - + message: "#^Parameter \\#2 \\$string of function explode expects string, string\\|null given\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php + + - + message: "#^Parameter \\#3 \\$name of method Nucleos\\\\SonataAutoConfigureBundle\\\\DependencyInjection\\\\Compiler\\\\AutoConfigureAdminClassesCompilerPass\\:\\:setDefaultValuesForAnnotation\\(\\) expects string, string\\|null given\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php + + - + message: "#^Part \\$adminSuffix \\(array\\|bool\\|float\\|int\\|string\\) of encapsed string cannot be cast to string\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php + + - + message: "#^Property Nucleos\\\\SonataAutoConfigureBundle\\\\DependencyInjection\\\\Compiler\\\\AutoConfigureAdminClassesCompilerPass\\:\\:\\$controllerNamespaces \\(array\\\\) does not accept array\\|bool\\|float\\|int\\|string\\|null\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php + + - + message: "#^Property Nucleos\\\\SonataAutoConfigureBundle\\\\DependencyInjection\\\\Compiler\\\\AutoConfigureAdminClassesCompilerPass\\:\\:\\$controllerSuffix \\(string\\) does not accept array\\|bool\\|float\\|int\\|string\\|null\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php + + - + message: "#^Property Nucleos\\\\SonataAutoConfigureBundle\\\\DependencyInjection\\\\Compiler\\\\AutoConfigureAdminClassesCompilerPass\\:\\:\\$entityNamespaces \\(array\\) does not accept array\\|bool\\|float\\|int\\|string\\|null\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php + + - + message: "#^Property Nucleos\\\\SonataAutoConfigureBundle\\\\DependencyInjection\\\\Compiler\\\\AutoConfigureAdminClassesCompilerPass\\:\\:\\$managerType \\(string\\) does not accept array\\|bool\\|float\\|int\\|string\\|null\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php + + - + message: "#^Argument of an invalid type array\\\\|null supplied for foreach, only iterables are supported\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminExtensionsCompilerPass.php + + - + message: "#^Implicit array creation is not allowed \\- variable \\$attributes does not exist\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminExtensionsCompilerPass.php + + - + message: "#^Parameter \\#1 \\$objectOrClass of class ReflectionClass constructor expects class\\-string\\\\|T of object, string\\|null given\\.$#" + count: 1 + path: src/DependencyInjection/Compiler/AutoConfigureAdminExtensionsCompilerPass.php + + - + message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\TreeBuilder\\:\\:root\\(\\)\\.$#" + count: 1 + path: src/DependencyInjection/Configuration.php + + - + message: "#^Call to function method_exists\\(\\) with Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\TreeBuilder and 'getRootNode' will always evaluate to true\\.$#" + count: 1 + path: src/DependencyInjection/Configuration.php + diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 4febd5d..57483f2 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,3 +1,14 @@ - + + + + $container->getParameter('sonata.auto_configure.admin.manager_type') + $container->getParameter('sonata.auto_configure.controller.suffix') + + + + + root + + diff --git a/psalm.xml b/psalm.xml index 7cd8dd2..aaebfaa 100644 --- a/psalm.xml +++ b/psalm.xml @@ -5,6 +5,7 @@ + diff --git a/src/Annotation/Admin.php b/src/Annotation/Admin.php index f1c9e42..5fa1799 100644 --- a/src/Annotation/Admin.php +++ b/src/Annotation/Admin.php @@ -19,96 +19,51 @@ */ final class Admin { - /** - * @var string - */ - public $label; + public ?string $label = null; - /** - * @var string - */ - public $managerType; + public ?string $managerType = null; - /** - * @var string - */ - public $group; + public ?string $group = null; - /** - * @var bool - */ - public $showInDashboard; + public ?bool $showInDashboard = null; - /** - * @var bool - */ - public $showMosaicButton; + public ?bool $showMosaicButton = null; - /** - * @var bool - */ - public $keepOpen; + public ?bool $keepOpen = null; - /** - * @var bool - */ - public $onTop; + public ?bool $onTop = null; - /** - * @var string - */ - public $icon; + public ?string $icon = null; - /** - * @var string - */ - public $labelTranslatorStrategy; + public ?string $labelTranslatorStrategy = null; - /** - * @var string - */ - public $labelCatalogue; + public ?string $labelCatalogue = null; - /** - * @var string - */ - public $translationDomain; + public ?string $translationDomain = null; - /** - * @var string - */ - public $pagerType; + public ?string $pagerType = null; - /** - * @var string - */ - public $adminCode; + public ?string $adminCode = null; - /** - * @var string - */ - public $entity; + public ?string $entity = null; - /** - * @var string - */ - public $controller; + public ?string $controller = null; + + public ?bool $autowireEntity = true; /** - * @var bool + * @var array|null */ - public $autowireEntity = true; + public ?array $templates = []; /** - * @var array + * @var string[]|null */ - public $templates = []; + public ?array $children = []; /** - * @var string[] + * @return array */ - public $children = []; - public function getOptions(): array { return array_filter( @@ -125,7 +80,7 @@ public function getOptions(): array 'label_catalogue' => $this->labelCatalogue, 'pager_type' => $this->pagerType, ], - static function ($value): bool { + static function (mixed $value): bool { return null !== $value; } ); diff --git a/src/Annotation/AdminExtension.php b/src/Annotation/AdminExtension.php index b67fc8a..805ff4b 100644 --- a/src/Annotation/AdminExtension.php +++ b/src/Annotation/AdminExtension.php @@ -19,21 +19,18 @@ */ final class AdminExtension { - /** - * @var bool - */ - public $global; + public ?bool $global = null; + + public ?int $priority = null; /** - * @var int + * @var string[]|null */ - public $priority; + public ?array $target = null; /** - * @var string[] + * @return array */ - public $target; - public function getOptions(): array { return array_filter( @@ -42,7 +39,7 @@ public function getOptions(): array 'priority' => $this->priority, 'target' => $this->target, ], - static function ($value): bool { + static function (mixed $value): bool { return null !== $value; } ); diff --git a/src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php b/src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php index 1e4e2b2..4795b38 100644 --- a/src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php +++ b/src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php @@ -27,24 +27,18 @@ final class AutoConfigureAdminClassesCompilerPass implements CompilerPassInterface { /** - * @var array + * @var mixed[] */ - private $entityNamespaces; + private array $entityNamespaces; /** - * @var array + * @var string[] */ - private $controllerNamespaces; + private array $controllerNamespaces; - /** - * @var string - */ - private $controllerSuffix; + private string $controllerSuffix; - /** - * @var string - */ - private $managerType; + private string $managerType; public function process(ContainerBuilder $container): void { @@ -83,7 +77,7 @@ public function process(ContainerBuilder $container): void $name = end($adminClassAsArray); - if ($adminSuffix) { + if (null !== $adminSuffix) { $name = preg_replace("/{$adminSuffix}$/", '', $name); } @@ -109,13 +103,13 @@ public function process(ContainerBuilder $container): void ->setAutowired(true) ); - if ($annotation->translationDomain) { + if (null !== $annotation->translationDomain) { $definition->addMethodCall('setTranslationDomain', [$annotation->translationDomain]); } if (\is_array($annotation->templates)) { - foreach ($annotation->templates as $name => $template) { - $definition->addMethodCall('setTemplate', [$name, $template]); + foreach ($annotation->templates as $key => $template) { + $definition->addMethodCall('setTemplate', [$key, $template]); } } @@ -129,43 +123,43 @@ public function process(ContainerBuilder $container): void private function setDefaultValuesForAnnotation(Inflector $inflector, Admin $annotation, string $name, array $defaults): void { - if (!$annotation->label) { + if (null === $annotation->label) { $annotation->label = $inflector->capitalize(str_replace('_', ' ', $inflector->tableize($name))); } - if (!$annotation->labelCatalogue) { + if (null === $annotation->labelCatalogue) { $annotation->labelCatalogue = $defaults['label_catalogue']; } - if (!$annotation->labelTranslatorStrategy) { + if (null === $annotation->labelTranslatorStrategy) { $annotation->labelTranslatorStrategy = $defaults['label_translator_strategy']; } - if (!$annotation->translationDomain) { + if (null === $annotation->translationDomain) { $annotation->translationDomain = $defaults['translation_domain']; } - if (!$annotation->group) { + if (null === $annotation->group) { $annotation->group = $defaults['group']; } - if (!$annotation->pagerType) { + if (null === $annotation->pagerType) { $annotation->pagerType = $defaults['pager_type']; } - if (!$annotation->entity && $annotation->autowireEntity) { + if (null === $annotation->entity && true === $annotation->autowireEntity) { [$annotation->entity, $managerType] = $this->findEntity($name); - if (!$annotation->managerType) { + if (null === $annotation->managerType) { $annotation->managerType = $managerType; } } - if (!$annotation->managerType) { + if (null === $annotation->managerType) { $annotation->managerType = $this->managerType; } - if (!$annotation->controller) { + if (null === $annotation->controller) { $annotation->controller = $this->findController($name.$this->controllerSuffix); } } diff --git a/src/DependencyInjection/Compiler/AutoConfigureAdminExtensionsCompilerPass.php b/src/DependencyInjection/Compiler/AutoConfigureAdminExtensionsCompilerPass.php index c30598e..74707e4 100644 --- a/src/DependencyInjection/Compiler/AutoConfigureAdminExtensionsCompilerPass.php +++ b/src/DependencyInjection/Compiler/AutoConfigureAdminExtensionsCompilerPass.php @@ -42,7 +42,7 @@ public function process(ContainerBuilder $container): void AdminExtension::class ); - if (!$annotation) { + if (null === $annotation) { continue; } @@ -75,11 +75,14 @@ private function hasTargets(AdminExtension $annotation): bool return \is_array($annotation->target) && \count($annotation->target) > 0; } + /** + * @return array + */ private function getTagAttributes(string $target, AdminExtension $annotation): array { $attributes['target'] = $target; - if ($annotation->priority) { + if (null !== $annotation->priority) { $attributes['priority'] = $annotation->priority; } diff --git a/src/DependencyInjection/SonataAutoConfigureExtension.php b/src/DependencyInjection/SonataAutoConfigureExtension.php index b5fd973..08c8c1b 100644 --- a/src/DependencyInjection/SonataAutoConfigureExtension.php +++ b/src/DependencyInjection/SonataAutoConfigureExtension.php @@ -20,6 +20,9 @@ final class SonataAutoConfigureExtension extends ConfigurableExtension { + /** + * @param mixed[] $mergedConfig + */ protected function loadInternal(array $mergedConfig, ContainerBuilder $container): void { $container->setParameter('sonata.auto_configure.admin.suffix', $mergedConfig['admin']['suffix']); diff --git a/src/Exception/EntityNotFound.php b/src/Exception/EntityNotFound.php index 070f657..7aa7ddd 100644 --- a/src/Exception/EntityNotFound.php +++ b/src/Exception/EntityNotFound.php @@ -17,6 +17,9 @@ final class EntityNotFound extends RuntimeException implements SonataAutoConfigureExceptionInterface { + /** + * @param mixed[] $namespaces + */ public function __construct(string $name, array $namespaces) { parent::__construct(sprintf( diff --git a/tests/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPassTest.php b/tests/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPassTest.php index d8d0756..d76fe55 100644 --- a/tests/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPassTest.php @@ -29,15 +29,9 @@ final class AutoConfigureAdminClassesCompilerPassTest extends TestCase { - /** - * @var AutoConfigureAdminClassesCompilerPass - */ - private $autoConfigureAdminClassesCompilerPass; + private AutoConfigureAdminClassesCompilerPass $autoConfigureAdminClassesCompilerPass; - /** - * @var ContainerBuilder - */ - private $containerBuilder; + private ContainerBuilder $containerBuilder; protected function setUp(): void { @@ -50,6 +44,9 @@ protected function setUp(): void /** * @dataProvider processData + * + * @param array $tagOptions + * @param string[] $methodCalls */ public function testProcess( string $admin, @@ -105,6 +102,9 @@ public function testProcess( } } + /** + * @return mixed[] + */ public function processData(): array { return [ @@ -176,6 +176,9 @@ public function testProcessEntityNotFound(): void $this->autoConfigureAdminClassesCompilerPass->process($this->containerBuilder); } + /** + * @param mixed[] $config + */ private function loadConfig(array $config = []): void { (new SonataAutoConfigureExtension())->load([ diff --git a/tests/DependencyInjection/Compiler/AutoConfigureExtensionsCompilerPassTest.php b/tests/DependencyInjection/Compiler/AutoConfigureExtensionsCompilerPassTest.php index aafc7ae..b21f7e5 100644 --- a/tests/DependencyInjection/Compiler/AutoConfigureExtensionsCompilerPassTest.php +++ b/tests/DependencyInjection/Compiler/AutoConfigureExtensionsCompilerPassTest.php @@ -26,15 +26,9 @@ final class AutoConfigureExtensionsCompilerPassTest extends TestCase { - /** - * @var AutoConfigureAdminExtensionsCompilerPass - */ - private $autoconfigureExtensionsCompilerPass; + private AutoConfigureAdminExtensionsCompilerPass $autoconfigureExtensionsCompilerPass; - /** - * @var ContainerBuilder - */ - private $containerBuilder; + private ContainerBuilder $containerBuilder; protected function setUp(): void { @@ -47,6 +41,8 @@ protected function setUp(): void /** * @dataProvider processData + * + * @param string[] $expectedTags */ public function testProcess(string $extensionServiceId, array $expectedTags = []): void { @@ -71,6 +67,9 @@ public function testProcess(string $extensionServiceId, array $expectedTags = [] } } + /** + * @return mixed[] + */ public function processData(): array { return [ @@ -138,6 +137,9 @@ public function testProcessSkipIfAnnotationMissing(): void static::assertEmpty(reset($tag)); } + /** + * @param mixed[] $config + */ private function loadConfig(array $config = []): void { (new SonataAutoConfigureExtension())->load([ diff --git a/tests/SonataAutoConfigureBundleTest.php b/tests/SonataAutoConfigureBundleTest.php index 778a258..5433b41 100644 --- a/tests/SonataAutoConfigureBundleTest.php +++ b/tests/SonataAutoConfigureBundleTest.php @@ -18,25 +18,16 @@ use Nucleos\SonataAutoConfigureBundle\SonataAutoConfigureBundle; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Symfony\Component\HttpKernel\Bundle\Bundle; final class SonataAutoConfigureBundleTest extends TestCase { - /** - * @var SonataAutoConfigureBundle - */ - private $bundle; + private SonataAutoConfigureBundle $bundle; protected function setUp(): void { $this->bundle = new SonataAutoConfigureBundle(); } - public function testBundle(): void - { - static::assertInstanceOf(Bundle::class, $this->bundle); - } - public function testCompilerPasses(): void { $containerBuilder = $this->createMock(ContainerBuilder::class); From 0438b0a5a8ef1bed5305e432d70e6ec23333d496 Mon Sep 17 00:00:00 2001 From: core23 Date: Sun, 16 Jan 2022 22:19:18 +0100 Subject: [PATCH 3/5] Clean Makefile --- Makefile | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/Makefile b/Makefile index 708d198..9808c83 100644 --- a/Makefile +++ b/Makefile @@ -5,32 +5,13 @@ default: lint fix: cs-fix lint-fix .PHONY: lint -lint: lint-composer lint-symfony +lint: lint-composer .PHONY: lint-composer lint-composer: composer validate --strict composer normalize --dry-run -.PHONY: lint-symfony -lint-symfony: lint-symfony-container lint-symfony-twig lint-symfony-xliff lint-symfony-yaml - -.PHONY: lint-symfony-container -lint-symfony-container: - tools/console lint:container - -.PHONY: lint-symfony-twig -lint-symfony-twig: - tools/console lint:twig src tests - -.PHONY: lint-symfony-xliff -lint-symfony-xliff: - tools/console lint:xliff src tests - -.PHONY: lint-symfony-yaml -lint-symfony-yaml: - tools/console lint:yaml src tests - .PHONY: test test: vendor-bin/tools/vendor vendor/bin/phpunit --colors=always From bf570949b5cb82a0d263f87d96f678986b042226 Mon Sep 17 00:00:00 2001 From: core23 Date: Sun, 16 Jan 2022 22:26:56 +0100 Subject: [PATCH 4/5] Refactor config --- phpstan-baseline.neon | 10 -- psalm-baseline.xml | 5 - src/DependencyInjection/Configuration.php | 139 +++++++++++++--------- 3 files changed, 82 insertions(+), 72 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 375ae63..eaf572d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -70,13 +70,3 @@ parameters: count: 1 path: src/DependencyInjection/Compiler/AutoConfigureAdminExtensionsCompilerPass.php - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\TreeBuilder\\:\\:root\\(\\)\\.$#" - count: 1 - path: src/DependencyInjection/Configuration.php - - - - message: "#^Call to function method_exists\\(\\) with Symfony\\\\Component\\\\Config\\\\Definition\\\\Builder\\\\TreeBuilder and 'getRootNode' will always evaluate to true\\.$#" - count: 1 - path: src/DependencyInjection/Configuration.php - diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 57483f2..950922e 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -6,9 +6,4 @@ $container->getParameter('sonata.auto_configure.controller.suffix') - - - root - - diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 2e6b012..17fdd7a 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -13,6 +13,7 @@ namespace Nucleos\SonataAutoConfigureBundle\DependencyInjection; +use Symfony\Component\Config\Definition\Builder\NodeDefinition; use Symfony\Component\Config\Definition\Builder\TreeBuilder; use Symfony\Component\Config\Definition\ConfigurationInterface; @@ -22,72 +23,96 @@ public function getConfigTreeBuilder(): TreeBuilder { $treeBuilder = new TreeBuilder('sonata_auto_configure'); - if (method_exists($treeBuilder, 'getRootNode')) { - $rootNode = $treeBuilder->getRootNode(); - } else { - // BC layer for symfony/config 4.1 and older - $rootNode = $treeBuilder->root('sonata_auto_configure'); - } + $rootNode = $treeBuilder->getRootNode(); - $rootNode + $rootNode->append($this->getAdminNode()); + $rootNode->append($this->getEntityNode()); + $rootNode->append($this->getControllerNode()); + + return $treeBuilder; + } + + private function getAdminNode(): NodeDefinition + { + $node = (new TreeBuilder('admin'))->getRootNode(); + + $node + ->addDefaultsIfNotSet() ->children() - ->arrayNode('admin') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('suffix') - ->defaultValue('Admin') - ->end() - ->scalarNode('manager_type') - ->defaultValue('orm') - ->cannotBeEmpty() - ->end() - ->scalarNode('label_catalogue') - ->defaultNull() - ->end() - ->scalarNode('label_translator_strategy') - ->defaultNull() - ->end() - ->scalarNode('translation_domain') - ->defaultNull() - ->end() - ->scalarNode('group') - ->defaultNull() - ->end() - ->scalarNode('pager_type') - ->defaultNull() - ->end() - ->end() + ->scalarNode('suffix') + ->defaultValue('Admin') ->end() - ->arrayNode('entity') - ->addDefaultsIfNotSet() - ->children() - ->arrayNode('namespaces') - ->defaultValue([['namespace' => 'App\Entity', 'manager_type' => 'orm']]) - ->arrayPrototype() - ->children() - ->scalarNode('namespace')->cannotBeEmpty()->end() - ->scalarNode('manager_type')->defaultValue('orm')->end() - ->end() - ->end() - ->end() - ->end() + ->scalarNode('manager_type') + ->defaultValue('orm') + ->cannotBeEmpty() ->end() - ->arrayNode('controller') - ->addDefaultsIfNotSet() - ->children() - ->scalarNode('suffix') - ->defaultValue('Controller') - ->end() - ->arrayNode('namespaces') - ->scalarPrototype()->end() - ->defaultValue(['App\Controller\Admin']) - ->requiresAtLeastOneElement() + ->scalarNode('label_catalogue') + ->defaultNull() + ->end() + ->scalarNode('label_translator_strategy') + ->defaultNull() + ->end() + ->scalarNode('translation_domain') + ->defaultNull() + ->end() + ->scalarNode('group') + ->defaultNull() + ->end() + ->scalarNode('pager_type') + ->defaultNull() + ->end() + ->end() + ->end() + ; + + return $node; + } + + private function getEntityNode(): NodeDefinition + { + $node = (new TreeBuilder('entity'))->getRootNode(); + + $node + ->addDefaultsIfNotSet() + ->children() + ->arrayNode('namespaces') + ->defaultValue([[ + 'namespace' => 'App\Entity', + 'manager_type' => 'orm', + ]]) + ->arrayPrototype() + ->children() + ->scalarNode('namespace')->cannotBeEmpty()->end() + ->scalarNode('manager_type')->defaultValue('orm')->end() ->end() ->end() ->end() ->end() + ->end() ; - return $treeBuilder; + return $node; + } + + private function getControllerNode(): NodeDefinition + { + $node = (new TreeBuilder('controller'))->getRootNode(); + + $node + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('suffix') + ->defaultValue('Controller') + ->end() + ->arrayNode('namespaces') + ->scalarPrototype()->end() + ->defaultValue(['App\Controller\Admin']) + ->requiresAtLeastOneElement() + ->end() + ->end() + ->end() + ; + + return $node; } } From 34e1fef89a09bdffd40eb2e93ce361898a55f690 Mon Sep 17 00:00:00 2001 From: core23 Date: Sun, 16 Jan 2022 22:31:39 +0100 Subject: [PATCH 5/5] Ignore code complexity in compiler pass --- .../Compiler/AutoConfigureAdminClassesCompilerPass.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php b/src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php index 4795b38..9017b3d 100644 --- a/src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php +++ b/src/DependencyInjection/Compiler/AutoConfigureAdminClassesCompilerPass.php @@ -40,6 +40,11 @@ final class AutoConfigureAdminClassesCompilerPass implements CompilerPassInterfa private string $managerType; + /** + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ public function process(ContainerBuilder $container): void { $annotationReader = $container->get('annotation_reader'); @@ -121,6 +126,10 @@ public function process(ContainerBuilder $container): void } } + /** + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.NPathComplexity) + */ private function setDefaultValuesForAnnotation(Inflector $inflector, Admin $annotation, string $name, array $defaults): void { if (null === $annotation->label) {