Completed
Push — master ( 39c546...d78055 )
by Tobias
32:44 queued 31:26
created

AddLoaderToSerializerCacheWarmerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 12
cp 0
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
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
        $definition = $container->getDefinition('serializer.mapping.cache_warmer');
22
        $argument = $definition->getArgument(0);
23
        /** @var Definition $argumentDefinition */
24
        foreach ($argument as $argumentDefinition) {
25
            if (AnnotationLoader::class === $argumentDefinition->getClass()) {
26
                $argument[] = new Reference(FakeSerializerLoader::class);
27
                $definition->replaceArgument(0, $argument);
28
29
                return;
30
            }
31
        }
32
    }
33
}
34