AddLoaderToSerializerCacheWarmerPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 15
cp 0
rs 9.6666
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 20
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Happyr\AnnotationWarmer\DependencyInjection\CompilerPass;
6
7
use Happyr\AnnotationWarmer\Loader\FakeSerializerLoader;
8
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Definition;
11
use Symfony\Component\DependencyInjection\Reference;
12
use Symfony\Component\Serializer\Mapping\Loader\AnnotationLoader;
13
14
/**
15
 * @author Tobias Nyholm <[email protected]>
16
 */
17
final class AddLoaderToSerializerCacheWarmerPass implements CompilerPassInterface
18
{
19
    public function process(ContainerBuilder $container)
20
    {
21
        if (!$container->hasDefinition('serializer.mapping.cache_warmer')) {
22
            return;
23
        };
24
25
        $definition = $container->getDefinition('serializer.mapping.cache_warmer');
26
        $argument = $definition->getArgument(0);
27
        /** @var Definition $argumentDefinition */
28
        foreach ($argument as $argumentDefinition) {
29
            if (AnnotationLoader::class === $argumentDefinition->getClass()) {
30
                $argument[] = new Reference(FakeSerializerLoader::class);
31
                $definition->replaceArgument(0, $argument);
32
33
                return;
34
            }
35
        }
36
    }
37
}
38