AddMapperInformationCompilerPass::process()   F
last analyzed

Complexity

Conditions 14
Paths 973

Size

Total Lines 50

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 2.1375
c 0
b 0
f 0
cc 14
nc 973
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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\EasyExtendsBundle\DependencyInjection\Compiler;
15
16
use Sonata\EasyExtendsBundle\Mapper\DoctrineCollector;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
20
/**
21
 * @author Thomas Rabaix <[email protected]>
22
 */
23
class AddMapperInformationCompilerPass implements CompilerPassInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function process(ContainerBuilder $container): void
29
    {
30
        if (!$container->hasDefinition('doctrine')) {
31
            $container->removeDefinition('sonata.easy_extends.doctrine.mapper');
32
33
            return;
34
        }
35
36
        $mapper = $container->getDefinition('sonata.easy_extends.doctrine.mapper');
37
38
        foreach (DoctrineCollector::getInstance()->getAssociations() as $class => $associations) {
39
            foreach ($associations as $field => $options) {
40
                $mapper->addMethodCall('addAssociation', [$class, $field, $options]);
41
            }
42
        }
43
44
        foreach (DoctrineCollector::getInstance()->getDiscriminatorColumns() as $class => $columnDefinition) {
45
            $mapper->addMethodCall('addDiscriminatorColumn', [$class, $columnDefinition]);
46
        }
47
48
        foreach (DoctrineCollector::getInstance()->getDiscriminators() as $class => $discriminators) {
49
            foreach ($discriminators as $key => $discriminatorClass) {
50
                $mapper->addMethodCall('addDiscriminator', [$class, $key, $discriminatorClass]);
51
            }
52
        }
53
54
        foreach (DoctrineCollector::getInstance()->getInheritanceTypes() as $class => $type) {
55
            $mapper->addMethodCall('addInheritanceType', [$class, $type]);
56
        }
57
58
        foreach (DoctrineCollector::getInstance()->getIndexes() as $class => $indexes) {
59
            foreach ($indexes as $field => $options) {
60
                $mapper->addMethodCall('addIndex', [$class, $field, $options]);
61
            }
62
        }
63
64
        foreach (DoctrineCollector::getInstance()->getUniques() as $class => $uniques) {
65
            foreach ($uniques as $field => $options) {
66
                $mapper->addMethodCall('addUnique', [$class, $field, $options]);
67
            }
68
        }
69
70
        foreach (DoctrineCollector::getInstance()->getOverrides() as $class => $overrides) {
71
            foreach ($overrides as $type => $options) {
72
                $mapper->addMethodCall('addOverride', [$class, $type, $options]);
73
            }
74
        }
75
76
        DoctrineCollector::getInstance()->clear();
77
    }
78
}
79