Configuration::getConfigTreeBuilder()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 21
rs 9.8333
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\Form\Type\BrandImageType;
10
use Loevgaard\SyliusBrandPlugin\Form\Type\BrandType;
11
use Loevgaard\SyliusBrandPlugin\Model\Brand;
12
use Loevgaard\SyliusBrandPlugin\Model\BrandImage;
13
use Loevgaard\SyliusBrandPlugin\Model\BrandImageInterface;
14
use Loevgaard\SyliusBrandPlugin\Model\BrandInterface;
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
        if (method_exists(TreeBuilder::class, 'getRootNode')) {
30
            $treeBuilder = new TreeBuilder('loevgaard_sylius_brand');
31
            $rootNode = $treeBuilder->getRootNode();
32
        } else {
33
            // BC layer for symfony/config 4.1 and older
34
            $treeBuilder = new TreeBuilder();
35
            $rootNode = $treeBuilder->root('loevgaard_sylius_brand');
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\Config...der\TreeBuilder::root() has been deprecated: since Symfony 4.3, pass the root name to the constructor instead ( Ignorable by Annotation )

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

35
            $rootNode = /** @scrutinizer ignore-deprecated */ $treeBuilder->root('loevgaard_sylius_brand');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
36
        }
37
38
        $rootNode
39
            ->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

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

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