Completed
Push — master ( 91e054...12ace7 )
by Kamil
31:08 queued 26:39
created

SyliusTaxonomyExtension::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 55
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 55
rs 9.7692
cc 2
eloc 34
nc 2
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\TaxonomyBundle\DependencyInjection;
13
14
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension;
15
use Sylius\Component\Resource\Factory\Factory;
16
use Sylius\Component\Translation\Factory\TranslatableFactory;
17
use Symfony\Component\Config\FileLocator;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
use Symfony\Component\DependencyInjection\Definition;
20
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
21
use Symfony\Component\DependencyInjection\Parameter;
22
use Symfony\Component\DependencyInjection\Reference;
23
24
/**
25
 * @author Paweł Jędrzejewski <[email protected]>
26
 */
27
class SyliusTaxonomyExtension extends AbstractResourceExtension
28
{
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function load(array $config, ContainerBuilder $container)
33
    {
34
        $config = $this->processConfiguration(new Configuration(), $config);
35
        $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
36
37
        $loader->load(sprintf('driver/%s.xml', $config['driver']));
38
39
        $this->registerResources('sylius', $config['driver'], $config['resources'], $container);
40
41
        $configFiles = array(
42
            'services.xml',
43
        );
44
45
        foreach ($configFiles as $configFile) {
46
            $loader->load($configFile);
47
        }
48
49
        $factoryDefinition = new Definition(Factory::class);
50
        $factoryDefinition->setArguments(
51
            array(
52
                new Parameter('sylius.model.taxonomy.class')
53
            )
54
        );
55
56
        $translatableFactoryDefinition = $container->getDefinition('sylius.factory.taxonomy');
57
        $taxonomyFactoryClass = $translatableFactoryDefinition->getClass();
58
        $translatableFactoryDefinition->setClass(TranslatableFactory::class);
59
        $translatableFactoryDefinition->setArguments(
60
            array(
61
                $factoryDefinition,
62
                new Reference('sylius.translation.locale_provider')
63
            )
64
        );
65
66
        $decoratedTaxonomyFactoryDefinition = new Definition($taxonomyFactoryClass);
67
        $decoratedTaxonomyFactoryDefinition->setArguments(
68
            array(
69
                $translatableFactoryDefinition,
70
                new Reference('sylius.factory.taxon')
71
            )
72
        );
73
74
        $container->setDefinition('sylius.factory.taxonomy', $decoratedTaxonomyFactoryDefinition);
75
76
        $taxonFactoryDefinition = $container->getDefinition('sylius.factory.taxon');
77
        $taxonFactoryClass = $taxonFactoryDefinition->getClass();
78
        $taxonFactoryDefinition->setClass(TranslatableFactory::class);
79
80
        $decoratedTaxonFactoryDefinition = new Definition($taxonFactoryClass);
81
        $decoratedTaxonFactoryDefinition
82
            ->addArgument($taxonFactoryDefinition)
83
            ->addArgument(new Reference('sylius.repository.taxonomy'))
84
        ;
85
        $container->setDefinition('sylius.factory.taxon', $decoratedTaxonFactoryDefinition);
86
    }
87
}
88