SetTestClientPass   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 21
ccs 6
cts 10
cp 0.6
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 19 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 2
    public function process(ContainerBuilder $container): void
23
    {
24 2
        if (null === $container->getParameter('liip_functional_test.query.max_query_count')) {
25 1
            $container->removeDefinition('liip_functional_test.query.count_client');
26
27 1
            return;
28
        }
29
30 1
        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
            $definition = $container->getDefinition('test.client');
34
            $definition->setPublic(false);
35
            $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
        $container->setAlias('test.client', new Alias('liip_functional_test.query.count_client', true));
41
    }
42
}
43