Completed
Branch resource-configuration-builder (c854d7)
by Kamil
13:53
created

Configuration::addResourcesSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 15
rs 9.4286
cc 1
eloc 10
nc 1
nop 1
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\LocaleBundle\DependencyInjection;
13
14
use Sylius\Bundle\LocaleBundle\Controller\LocaleController;
15
use Sylius\Bundle\LocaleBundle\Form\Type\LocaleChoiceType;
16
use Sylius\Bundle\LocaleBundle\Form\Type\LocaleType;
17
use Sylius\Bundle\ResourceBundle\DependencyInjection\Configuration\ResourceConfigurationGenerator;
18
use Sylius\Bundle\ResourceBundle\DependencyInjection\Configuration\SyliusResource;
19
use Sylius\Bundle\ResourceBundle\SyliusResourceBundle;
20
use Sylius\Component\Locale\Model\Locale;
21
use Sylius\Component\Locale\Model\LocaleInterface;
22
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
23
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
24
use Symfony\Component\Config\Definition\ConfigurationInterface;
25
26
/**
27
 * This class contains the configuration information for the bundle.
28
 *
29
 * This information is solely responsible for how the different configuration
30
 * sections are normalized, and merged.
31
 *
32
 * @author Paweł Jędrzejewski <[email protected]>
33
 */
34
class Configuration implements ConfigurationInterface
35
{
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getConfigTreeBuilder()
40
    {
41
        $treeBuilder = new TreeBuilder();
42
        $rootNode = $treeBuilder->root('sylius_locale');
43
44
        $rootNode
45
            ->children()
46
                ->scalarNode('driver')->defaultValue(SyliusResourceBundle::DRIVER_DOCTRINE_ORM)->end()
47
                ->scalarNode('storage')->defaultValue('sylius.storage.session')->end()
48
            ->end()
49
        ;
50
51
        $this->addResourcesSection($rootNode);
52
53
        return $treeBuilder;
54
    }
55
56
    /**
57
     * @param ArrayNodeDefinition $rootDefinition
58
     */
59
    private function addResourcesSection(ArrayNodeDefinition $rootDefinition)
60
    {
61
        $resourceConfigurationGenerator = new ResourceConfigurationGenerator();
62
63
        $resourcesDefinition = $resourceConfigurationGenerator->initResourcesConfiguration($rootDefinition);
64
65
        $localeResource = new SyliusResource('locale', Locale::class, LocaleInterface::class);
66
        $localeResource->useController(LocaleController::class);
67
        $localeResource->useDefaultRepository();
0 ignored issues
show
Unused Code introduced by
The call to the method Sylius\Bundle\ResourceBu...:useDefaultRepository() 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...
68
        $localeResource->useDefaultFactory();
69
        $localeResource->addForm('default', LocaleType::class, ['sylius']);
70
        $localeResource->addForm('choice', LocaleChoiceType::class);
71
72
        $resourceConfigurationGenerator->addSyliusResource($resourcesDefinition, $localeResource);
73
    }
74
}
75