Completed
Push — 2.x ( dc834d...91b37b )
by
unknown
02:07
created

AddMapperInformationCompilerPass::process()   F

Complexity

Conditions 12
Paths 325

Size

Total Lines 42
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 6
Bugs 0 Features 3
Metric Value
c 6
b 0
f 3
dl 0
loc 42
rs 3.7956
cc 12
eloc 21
nc 325
nop 1

How to fix   Complexity   

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 Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
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 Sonata\EasyExtendsBundle\DependencyInjection\Compiler;
13
14
use Sonata\EasyExtendsBundle\Mapper\DoctrineCollector;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
18
/**
19
 * @author Thomas Rabaix <[email protected]>
20
 */
21
class AddMapperInformationCompilerPass implements CompilerPassInterface
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function process(ContainerBuilder $container)
27
    {
28
        if (!$container->hasDefinition('doctrine')) {
29
            $container->removeDefinition('sonata.easy_extends.doctrine.mapper');
30
31
            return;
32
        }
33
34
        $mapper = $container->getDefinition('sonata.easy_extends.doctrine.mapper');
35
36
        foreach (DoctrineCollector::getInstance()->getAssociations() as $class => $associations) {
37
            foreach ($associations as $field => $options) {
38
                $mapper->addMethodCall('addAssociation', array($class, $field, $options));
39
            }
40
        }
41
42
        foreach (DoctrineCollector::getInstance()->getDiscriminatorColumns() as $class => $columnDefinition) {
43
            $mapper->addMethodCall('addDiscriminatorColumn', array($class, $columnDefinition));
44
        }
45
46
        foreach (DoctrineCollector::getInstance()->getDiscriminators() as $class => $discriminators) {
47
            foreach ($discriminators as $key => $discriminatorClass) {
48
                $mapper->addMethodCall('addDiscriminator', array($class, $key, $discriminatorClass));
49
            }
50
        }
51
52
        foreach (DoctrineCollector::getInstance()->getInheritanceTypes() as $class => $type) {
53
            $mapper->addMethodCall('addInheritanceType', array($class, $type));
54
        }
55
56
        foreach (DoctrineCollector::getInstance()->getIndexes() as $class => $indexes) {
57
            foreach ($indexes as $field => $options) {
58
                $mapper->addMethodCall('addIndex', array($class, $field, $options));
59
            }
60
        }
61
62
        foreach (DoctrineCollector::getInstance()->getUniques() as $class => $uniques) {
63
            foreach ($uniques as $field => $options) {
64
                $mapper->addMethodCall('addUnique', array($class, $field, $options));
65
            }
66
        }
67
    }
68
}
69