TaggedServicesCompilerPass::process()   C
last analyzed

Complexity

Conditions 15
Paths 32

Size

Total Lines 65
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 240

Importance

Changes 0
Metric Value
cc 15
eloc 37
nc 32
nop 1
dl 0
loc 65
ccs 0
cts 38
cp 0
crap 240
rs 5.9166
c 0
b 0
f 0

How to fix   Long Method    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
namespace Kaliop\eZMigrationBundle\DependencyInjection\CompilerPass;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class TaggedServicesCompilerPass implements CompilerPassInterface
10
{
11
    /**
12
     * @param ContainerBuilder $container
13
     */
14
    public function process(ContainerBuilder $container)
15
    {
16
        if ($container->has('ez_migration_bundle.migration_service')) {
17
            $migrationService = $container->findDefinition('ez_migration_bundle.migration_service');
18
19
            $DefinitionParsers = $container->findTaggedServiceIds('ez_migration_bundle.definition_parser');
20
            foreach ($DefinitionParsers as $id => $tags) {
21
                $migrationService->addMethodCall('addDefinitionParser', array(
22
                    new Reference($id)
23
                ));
24
            }
25
26
            $executors = $container->findTaggedServiceIds('ez_migration_bundle.executor');
27
            foreach ($executors as $id => $tags) {
28
                $migrationService->addMethodCall('addExecutor', array(
29
                    new Reference($id)
30
                ));
31
            }
32
        }
33
34
        if ($container->has('ez_migration_bundle.complex_field_manager')) {
35
            $migrationService = $container->findDefinition('ez_migration_bundle.complex_field_manager');
36
37
            $DefinitionParsers = $container->findTaggedServiceIds('ez_migration_bundle.complex_field');
38
39
            // allow for prioritization of tagged services
40
            $handlers = array();
41
            $priorities = array();
42
43
            foreach ($DefinitionParsers as $id => $tags) {
44
                foreach ($tags as $attributes) {
45
                    $priorities[] = isset($attributes['priority']) ? $attributes['priority'] : 0;
46
                    $handlers[] = array(
47
                        new Reference($id),
48
                        $attributes['fieldtype'],
49
                        isset($attributes['contenttype']) ? $attributes['contenttype'] : null
50
                    );
51
                }
52
            }
53
54
            asort($priorities);
55
56
            foreach ($priorities as $id => $priority) {
57
                $migrationService->addMethodCall('addFieldHandler', $handlers[$id]);
58
            }
59
        }
60
61
        if ($container->has('ez_migration_bundle.reference_resolver.customreference.flexible')) {
62
            $customReferenceResolver = $container->findDefinition('ez_migration_bundle.reference_resolver.customreference.flexible');
63
            $extraResolvers = $container->findTaggedServiceIds('ez_migration_bundle.reference_resolver.customreference');
64
65
            foreach ($extraResolvers as $id => $tags) {
66
                $customReferenceResolver->addMethodCall('addResolver', array(
67
                    new Reference($id)
68
                ));
69
            }
70
        }
71
72
        if ($container->has('ez_migration_bundle.context_handler')) {
73
            $contextHandlerService = $container->findDefinition('ez_migration_bundle.context_handler');
74
            $ContextProviders = $container->findTaggedServiceIds('ez_migration_bundle.context_provider');
75
76
            foreach ($ContextProviders as $id => $tags) {
77
                foreach ($tags as $attributes) {
78
                    $contextHandlerService->addMethodCall('addProvider', array(new Reference($id), $attributes['label']));
79
                }
80
            }
81
        }
82
    }
83
}
84