Configuration   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 44
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 12 2
A addMainConfig() 0 6 1
A addUnitMappingConfig() 0 21 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecocode\SyliusBasePricePlugin\DependencyInjection;
6
7
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
8
use Symfony\Component\Config\Definition\ConfigurationInterface;
9
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
10
11
/**
12
 * Class Configuration
13
 * @package Ecocode\SyliusBasePricePlugin\DependencyInjection
14
 */
15
final class Configuration implements ConfigurationInterface
16
{
17 8
    public function getConfigTreeBuilder(): TreeBuilder
18
    {
19 8
        $treeBuilder = new TreeBuilder('ecocode_sylius_base_price');
20 8
        $rootNode    = $treeBuilder->getRootNode();
21
22 8
        if ($rootNode instanceof ArrayNodeDefinition) {
23 8
            $this->addMainConfig($rootNode);
24 8
            $this->addUnitMappingConfig($rootNode);
25
        }
26
27 8
        return $treeBuilder;
28
    }
29
30 8
    protected function addMainConfig(ArrayNodeDefinition $rootNode): self
31
    {
32 8
        $rootNode->children()->booleanNode('use_short_unit_name')->defaultTrue()->end();
33
34 8
        return $this;
35
    }
36
37 8
    protected function addUnitMappingConfig(ArrayNodeDefinition $rootNode): self
38
    {
39
        // @phpstan-ignore-next-line
40
        $rootNode
41 8
            ->children()
42 8
                ->arrayNode('mapping')
43 8
                    ->useAttributeAsKey('key')->cannotBeEmpty()
44 8
                    ->arrayPrototype()
45 8
                        ->arrayPrototype()
46 8
                            ->children()
47 8
                                ->scalarNode('unit')->cannotBeEmpty()->isRequired()->end()
48 8
                                ->floatNode('ifMoreThan')->defaultValue(0)->end()
49 8
                                ->floatNode('mod')->defaultValue(1)->end()
50 8
                            ->end()
51 8
                        ->end()
52 8
                    ->end()
53 8
                ->end()
54 8
            ->end();
55
56 8
        return $this;
57
    }
58
}
59
60