processDataTypeHandlers()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 11
loc 11
ccs 7
cts 7
cp 1
rs 9.9
c 0
b 0
f 0
cc 2
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 4
    public function process(ContainerBuilder $container)
16
    {
17 4
        $this->processLinkRepositories($container);
18 4
        $this->processDataTypeHandlers($container);
19 4
    }
20
21
    /**
22
     * Process links repositories
23
     *
24
     * @param ContainerBuilder $container
25
     */
26 4
    protected function processLinkRepositories(ContainerBuilder $container)
27
    {
28 4
        $definition   = $container->findDefinition('mrtn_json_api.object_mapper.link_repository_provider');
29 4
        $repositories = $container->findTaggedServiceIds('mrtn_json_api.object_mapper.link_repository');
30
31 4 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 4
            foreach ($tags as $tag)
33
            {
34 4
                if (! isset($tag['alias'])) {
35
                    throw new \LogicException('Alias must be defined for a "link-repository" tag');
36
                }
37
38 4
                $definition->addMethodCall('registerRepository', [
39 4
                    trim($tag['alias']),
40 4
                    new Reference($id)
41
                ]);
42
            }
43
        }
44 4
    }
45
46 4 View Code Duplication
    protected function processDataTypeHandlers(ContainerBuilder $container)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
47
    {
48 4
        $definition = $container->findDefinition('mrtn_json_api.object_mapper.datatype_manager');
49 4
        $extensions = $container->findTaggedServiceIds('mrtn_json_api.object_mapper.datatype_handler');
50
51 4
        foreach ($extensions as $id => $tags) {
52 4
            $definition->addMethodCall('registerDataTypeHandler', [
53 4
                new Reference($id)
54
            ]);
55
        }
56
    }
57
}