Completed
Push — master ( 98c39c...c8155d )
by Pavel
16:50
created

JmsSerializerDriverPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 38
ccs 19
cts 19
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 34 4
1
<?php
2
3
namespace ScayTrase\Api\Cruds\DependencyInjection\Compiler;
4
5
use ScayTrase\Api\Cruds\Adaptors\JmsSerializer\JmsDoctrineHandler;
6
use ScayTrase\Api\Cruds\Adaptors\JmsSerializer\JmsDoctrineMetadataDriver;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
final class JmsSerializerDriverPass implements CompilerPassInterface
12
{
13
    /** {@inheritdoc} */
14 30
    public function process(ContainerBuilder $container)
15
    {
16 30
        if (!$container->has('jms_serializer.metadata.doctrine_type_driver')) {
17 15
            return;
18
        }
19
20 15
        $handler = $container->register('cruds.jms.doctrine_associations_handler', JmsDoctrineHandler::class);
21
22
        //fixme: JMS utilizes only public handlers for lazyness
23 15
        $handler->setPublic(true);
24 15
        $handler->addArgument(new Reference('doctrine'));
25
26 15
        $formats    = ['json', 'xml', 'array'];
27
        $directions = [
28 15
            'serialization'   => 'serializeRelation',
29
            'deserialization' => 'deserializeRelation',
30
        ];
31 15
        $type       = JmsDoctrineHandler::TYPE;
32 15
        $name       = 'jms_serializer.handler';
33
34 15
        foreach ($formats as $format) {
35 15
            foreach ($directions as $direction => $method) {
36 15
                $handler->addTag(
37 15
                    $name,
38
                    [
39 15
                        'type'      => $type,
40 15
                        'direction' => $direction,
41 15
                        'format'    => $format,
42 15
                        'method'    => $method,
43
                    ]
44
                );
45
            }
46
        }
47 15
    }
48
}
49