Passed
Push — master ( 6ba977...0a48c5 )
by Michael
07:39
created

ObjectMapperCompilerPass::processMappingHandlers()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Bundle\JsonApiBundle\DependencyInjection\Compiler;
5
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class ObjectMapperCompilerPass implements CompilerPassInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 1
    public function process(ContainerBuilder $container)
16
    {
17 1
        $this->processLinkRepositories($container);
18 1
        $this->processDataTypeHandlers($container);
19 1
    }
20
21
    /**
22
     * Process links repositories
23
     *
24
     * @param ContainerBuilder $container
25
     */
26 1
    protected function processLinkRepositories(ContainerBuilder $container)
27
    {
28 1
        $definition   = $container->findDefinition('mrtn_json_api.object_mapper.link_repository_provider');
29 1
        $repositories = $container->findTaggedServiceIds('mrtn_json_api.object_mapper.link_repository');
30
31 1 View Code Duplication
        foreach ($repositories as $id => $tags) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
32 1
            foreach ($tags as $tag)
33
            {
34 1
                if (! isset($tag['alias'])) {
35
                    throw new \LogicException('Alias must be defined for a "link-repository" tag');
36
                }
37
38 1
                $definition->addMethodCall('registerRepository', [
39 1
                    trim($tag['alias']),
40 1
                    new Reference($id)
41
                ]);
42
            }
43
        }
44 1
    }
45
46 1
    protected function processDataTypeHandlers(ContainerBuilder $container)
47
    {
48 1
        $definition = $container->findDefinition('mrtn_json_api.object_mapper.handler.attribute');
49 1
        $extensions = $container->findTaggedServiceIds('mrtn_json_api.object_mapper.datatype_handler');
50
51 1
        foreach ($extensions as $id => $tags) {
52 1
            $definition->addMethodCall('registerDataTypeHandler', [
53 1
                new Reference($id)
54
            ]);
55
        }
56
    }
57
}