SerializerLoaderPass   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 25
ccs 9
cts 10
cp 0.9
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 12 3
1
<?php
2
3
namespace Bdf\SerializerBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
9
10
/**
11
 * Registers all service tag as loader into the serializer.
12
 */
13
class SerializerLoaderPass implements CompilerPassInterface
14
{
15
    use PriorityTaggedServiceTrait;
16
17
    private $service;
18
    private $loaderTag;
19
20 4
    public function __construct(string $service = 'bdf_serializer.metadata_factory', string $loaderTag = 'bdf_serializer.loader')
21
    {
22 4
        $this->service = $service;
23 4
        $this->loaderTag = $loaderTag;
24
    }
25
26 3
    public function process(ContainerBuilder $container)
27
    {
28 3
        if (!$container->hasDefinition($this->service)) {
29
            return;
30
        }
31
32 3
        if (!$normalizers = $this->findAndSortTaggedServices($this->loaderTag, $container)) {
33 1
            throw new RuntimeException(sprintf('You must tag at least one service as "%s" to use the "%s" service.', $this->loaderTag, $this->service));
34
        }
35
36 2
        $serializerDefinition = $container->getDefinition($this->service);
37 2
        $serializerDefinition->replaceArgument(0, $normalizers);
38
    }
39
}
40