Completed
Push — master ( ea0a23...156714 )
by Joachim
12s queued 11s
created

Configuration::addResourcesSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 42
nc 1
nop 1
dl 0
loc 44
rs 9.248
c 0
b 0
f 0
1
<?php
2
3
/** @noinspection PhpUnusedLocalVariableInspection */
4
5
declare(strict_types=1);
6
7
namespace Loevgaard\SyliusBrandPlugin\DependencyInjection;
8
9
use Loevgaard\SyliusBrandPlugin\Doctrine\ORM\BrandImageRepository;
10
use Loevgaard\SyliusBrandPlugin\Doctrine\ORM\BrandRepository;
11
use Loevgaard\SyliusBrandPlugin\Form\Type\BrandImageType;
12
use Loevgaard\SyliusBrandPlugin\Form\Type\BrandType;
13
use Loevgaard\SyliusBrandPlugin\Model\Brand;
14
use Loevgaard\SyliusBrandPlugin\Model\BrandImage;
15
use Loevgaard\SyliusBrandPlugin\Model\BrandImageInterface;
16
use Loevgaard\SyliusBrandPlugin\Model\BrandInterface;
17
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
18
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
19
use Sylius\Component\Resource\Factory\Factory;
20
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
21
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
22
use Symfony\Component\Config\Definition\ConfigurationInterface;
23
24
final class Configuration implements ConfigurationInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getConfigTreeBuilder(): TreeBuilder
30
    {
31
        if (method_exists(TreeBuilder::class, 'getRootNode')) {
32
            $treeBuilder = new TreeBuilder('loevgaard_sylius_brand');
33
            $rootNode = $treeBuilder->getRootNode();
34
        } else {
35
            // BC layer for symfony/config 4.1 and older
36
            $treeBuilder = new TreeBuilder();
37
            $rootNode = $treeBuilder->root('loevgaard_sylius_brand');
38
        }
39
40
        $rootNode
41
            ->addDefaultsIfNotSet()
0 ignored issues
show
Bug introduced by
The method addDefaultsIfNotSet() does not exist on Symfony\Component\Config...\Builder\NodeDefinition. It seems like you code against a sub-type of Symfony\Component\Config...\Builder\NodeDefinition such as Symfony\Component\Config...der\ArrayNodeDefinition. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
            ->/** @scrutinizer ignore-call */ 
42
              addDefaultsIfNotSet()
Loading history...
42
            ->children()
43
                ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
44
            ->end()
45
        ;
46
47
        $this->addResourcesSection($rootNode);
48
49
        return $treeBuilder;
50
    }
51
52
    /**
53
     * @param ArrayNodeDefinition $node
54
     */
55
    private function addResourcesSection(ArrayNodeDefinition $node): void
56
    {
57
        $node
58
            ->children()
59
                ->arrayNode('resources')
60
                    ->addDefaultsIfNotSet()
61
                    ->children()
62
                        ->arrayNode('brand')
63
                            ->addDefaultsIfNotSet()
64
                            ->children()
65
                                ->variableNode('options')->end()
66
                                ->arrayNode('classes')
0 ignored issues
show
Bug introduced by
The method arrayNode() does not exist on Symfony\Component\Config...der\NodeParentInterface. It seems like you code against a sub-type of Symfony\Component\Config...der\NodeParentInterface such as Symfony\Component\Config...ion\Builder\NodeBuilder. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

66
                                ->/** @scrutinizer ignore-call */ arrayNode('classes')
Loading history...
67
                                    ->addDefaultsIfNotSet()
68
                                    ->children()
69
                                        ->scalarNode('model')->defaultValue(Brand::class)->cannotBeEmpty()->end()
70
                                        ->scalarNode('interface')->defaultValue(BrandInterface::class)->cannotBeEmpty()->end()
71
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
72
                                        ->scalarNode('repository')->defaultValue(BrandRepository::class)->cannotBeEmpty()->end()
73
                                        ->scalarNode('factory')->defaultValue(Factory::class)->end()
74
                                        ->scalarNode('form')->defaultValue(BrandType::class)->cannotBeEmpty()->end()
75
                                    ->end()
76
                                ->end()
77
                            ->end()
78
                        ->end()
79
                        ->arrayNode('brand_image')
80
                            ->addDefaultsIfNotSet()
81
                            ->children()
82
                                ->variableNode('options')->end()
83
                                ->arrayNode('classes')
84
                                    ->addDefaultsIfNotSet()
85
                                    ->children()
86
                                        ->scalarNode('model')->defaultValue(BrandImage::class)->cannotBeEmpty()->end()
87
                                        ->scalarNode('interface')->defaultValue(BrandImageInterface::class)->cannotBeEmpty()->end()
88
                                        ->scalarNode('controller')->defaultValue(ResourceController::class)->cannotBeEmpty()->end()
89
                                        ->scalarNode('repository')->defaultValue(BrandImageRepository::class)->cannotBeEmpty()->end()
90
                                        ->scalarNode('factory')->defaultValue(Factory::class)->end()
91
                                        ->scalarNode('form')->defaultValue(BrandImageType::class)->cannotBeEmpty()->end()
92
                                    ->end()
93
                                ->end()
94
                            ->end()
95
                        ->end()
96
                    ->end()
97
                ->end()
98
            ->end()
99
        ;
100
    }
101
}
102