Passed
Push — master ( 130df2...007dfb )
by Alexis
10:23
created

SetTestClientPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 20
ccs 11
cts 11
cp 1
rs 9.6
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Liip/FunctionalTestBundle
7
 *
8
 * (c) Lukas Kahwe Smith <[email protected]>
9
 *
10
 * This source file is subject to the MIT license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13
14
namespace Liip\FunctionalTestBundle\DependencyInjection\Compiler;
15
16
use Symfony\Component\DependencyInjection\Alias;
17
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18
use Symfony\Component\DependencyInjection\ContainerBuilder;
19
20
class SetTestClientPass implements CompilerPassInterface
21
{
22 5
    public function process(ContainerBuilder $container): void
23
    {
24 5
        if (null === $container->getParameter('liip_functional_test.query.max_query_count')) {
25 3
            $container->removeDefinition('liip_functional_test.query.count_client');
26
27 3
            return;
28
        }
29
30 2
        if ($container->hasDefinition('test.client')) {
31
            // test.client is a definition.
32
            // Register it again as a private service to inject it as the parent
33 1
            $definition = $container->getDefinition('test.client');
34 1
            $definition->setPublic(false);
35 1
            $container->setDefinition('liip_functional_test.query.count_client.parent', $definition);
36
        } else {
37 1
            throw new \Exception('The LiipFunctionalTestBundle\'s Query Counter can only be used in the test environment.'.PHP_EOL.'See https://github.com/liip/LiipFunctionalTestBundle#only-in-test-environment');
38
        }
39
40 1
        $container->setAlias('test.client', new Alias('liip_functional_test.query.count_client', true));
41 1
    }
42
}
43