Completed
Push — master ( 0edd79...db2c21 )
by Paweł
17:32
created

Configuration::getConfigTreeBuilder()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 26
rs 8.8571
cc 1
eloc 20
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Bundle\ThemeBundle\DependencyInjection;
13
14
use Sylius\Bundle\ThemeBundle\Configuration\ConfigurationSourceFactoryInterface;
15
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
16
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
17
use Symfony\Component\Config\Definition\ConfigurationInterface;
18
19
/**
20
 * @author Kamil Kokot <[email protected]>
21
 */
22
final class Configuration implements ConfigurationInterface
23
{
24
    /**
25
     * @var ConfigurationSourceFactoryInterface[]
26
     */
27
    private $configurationSourceFactories;
28
29
    /**
30
     * @param ConfigurationSourceFactoryInterface[] $configurationSourceFactories
31
     */
32
    public function __construct(array $configurationSourceFactories = [])
33
    {
34
        $this->configurationSourceFactories = $configurationSourceFactories;
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function getConfigTreeBuilder()
41
    {
42
        $treeBuilder = new TreeBuilder();
43
        $rootNode = $treeBuilder->root('sylius_theme');
44
45
        $this->addSourcesConfiguration($rootNode);
46
47
        $rootNode
0 ignored issues
show
Unused Code introduced by
The call to the method Symfony\Component\Config...r\NodeDefinition::end() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
48
            ->children()
49
                ->arrayNode('assets')
50
                    ->canBeDisabled()
51
                ->end()
52
                ->arrayNode('templating')
53
                    ->canBeDisabled()
54
                ->end()
55
                ->arrayNode('translations')
56
                    ->canBeDisabled()
57
                ->end()
58
                ->scalarNode('context')
59
                    ->defaultValue('sylius.theme.context.settable')
60
                    ->cannotBeEmpty()
61
                ->end()
62
        ;
63
64
        return $treeBuilder;
65
    }
66
67
    /**
68
     * @param ArrayNodeDefinition $rootNode
69
     */
70
    private function addSourcesConfiguration(ArrayNodeDefinition $rootNode)
71
    {
72
        $sourcesNodeBuilder = $rootNode
73
            ->fixXmlConfig('source')
74
                ->children()
75
                    ->arrayNode('sources')
76
                            ->children()
77
        ;
78
79
        foreach ($this->configurationSourceFactories as $sourceFactory) {
80
            $sourceNode = $sourcesNodeBuilder
81
                ->arrayNode($sourceFactory->getName())
82
                ->canBeEnabled()
83
            ;
84
85
            $sourceFactory->buildConfiguration($sourceNode);
86
        }
87
    }
88
}
89