Passed
Pull Request — master (#35)
by Igor
03:31
created

Configuration   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 52
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 15 1
A addResourcesSection() 0 44 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Loevgaard\SyliusBrandPlugin\DependencyInjection;
6
7
use Loevgaard\SyliusBrandPlugin\Doctrine\ORM\BrandImageRepository;
8
use Loevgaard\SyliusBrandPlugin\Doctrine\ORM\BrandRepository;
9
use Loevgaard\SyliusBrandPlugin\Entity\Brand;
10
use Loevgaard\SyliusBrandPlugin\Entity\BrandImage;
11
use Loevgaard\SyliusBrandPlugin\Entity\BrandImageInterface;
12
use Loevgaard\SyliusBrandPlugin\Entity\BrandInterface;
13
use Loevgaard\SyliusBrandPlugin\Form\Type\BrandImageType;
14
use Loevgaard\SyliusBrandPlugin\Form\Type\BrandType;
15
use Sylius\Bundle\ResourceBundle\Controller\ResourceController;
16
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
17
use Sylius\Component\Resource\Factory\Factory;
18
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
19
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
20
use Symfony\Component\Config\Definition\ConfigurationInterface;
21
22
final class Configuration implements ConfigurationInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getConfigTreeBuilder(): TreeBuilder
28
    {
29
        $treeBuilder = new TreeBuilder();
30
        $rootNode = $treeBuilder->root('loevgaard_sylius_brand');
31
32
        $rootNode
33
            ->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

33
            ->/** @scrutinizer ignore-call */ 
34
              addDefaultsIfNotSet()
Loading history...
34
            ->children()
35
                ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
36
            ->end()
37
        ;
38
39
        $this->addResourcesSection($rootNode);
40
41
        return $treeBuilder;
42
    }
43
44
    /**
45
     * @param ArrayNodeDefinition $node
46
     */
47
    private function addResourcesSection(ArrayNodeDefinition $node): void
48
    {
49
        $node
50
            ->children()
51
                ->arrayNode('resources')
52
                    ->addDefaultsIfNotSet()
53
                    ->children()
54
                        ->arrayNode('brand')
55
                            ->addDefaultsIfNotSet()
56
                            ->children()
57
                                ->variableNode('options')->end()
58
                                ->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

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