Configuration   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 1
lcom 1
cbo 4
dl 0
loc 48
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getConfigTreeBuilder() 0 32 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Marek\SiteAccessAwareDateFormatBundle\DependencyInjection;
6
7
use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\Configuration as SiteAccessConfiguration;
8
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
9
10
/**
11
 * This is the class that validates and merges configuration from your app/config files.
12
 *
13
 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
14
 */
15
class Configuration extends SiteAccessConfiguration
16
{
17
    /**
18
     * @var string
19
     */
20
    public const TREE_ROOT = 'marek_site_access_aware_date_format';
21
22
    /**
23
     * @var array
24
     */
25
    protected $validFormats = ['none', 'full', 'short', 'long', 'medium'];
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function getConfigTreeBuilder()
31
    {
32
        $treeBuilder = new TreeBuilder();
33
        $rootNode = $treeBuilder->root(self::TREE_ROOT);
34
35
        $nodeBuilder = $this->generateScopeBaseNode($rootNode);
36
37
        $nodeBuilder
38
            ->arrayNode('defaults')
39
                ->addDefaultsIfNotSet()
40
                ->children()
41
                    ->scalarNode('format')
42
                        ->defaultValue('short')
43
                        ->cannotBeEmpty()
44
                        ->validate()
45
                            ->ifNotInArray($this->validFormats)
46
                            ->thenInvalid('Invalid default date format value provided.')
47
                        ->end()
48
                    ->end()
49
                ->end()
50
            ->end()
51
            ->arrayNode('formats')
52
                ->requiresAtLeastOneElement()
53
                ->useAttributeAsKey('format')
54
                    ->prototype('scalar')
55
                    ->end()
56
            ->end();
57
58
        $nodeBuilder->end();
59
60
        return $treeBuilder;
61
    }
62
}
63