Failed Conditions
Pull Request — master (#25)
by Yo
07:26 queued 03:57
created

AbstractExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 20.83%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 0
loc 73
ccs 5
cts 24
cp 0.2083
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A buildContainerId() 0 8 1
A buildContainerParameterReference() 0 7 1
B createService() 0 28 5
1
<?php
2
namespace Yoanm\Behat3SymfonyExtension\ServiceContainer;
3
4
use Behat\Testwork\ServiceContainer\Extension;
5
use Symfony\Component\DependencyInjection\ContainerBuilder;
6
use Symfony\Component\DependencyInjection\Definition;
7
8
abstract class AbstractExtension implements Extension
9
{
10
    const BASE_CONTAINER_ID = 'behat3_symfony_extension';
11
    const KERNEL_SERVICE_ID = 'behat3_symfony_extension.kernel';
12
    const TEST_CLIENT_SERVICE_ID = 'behat3_symfony_extension.test.client';
13
14
    /**
15
     * @param string $key
16
     *
17
     * @return string
18
     */
19 7
    protected function buildContainerId($key)
20
    {
21 7
        return sprintf(
22 7
            '%s.%s',
23 7
            self::BASE_CONTAINER_ID,
24
            $key
25 7
        );
26
    }
27
28
    /**
29
     * @param string $key
30
     *
31
     * @return string
32
     */
33
    protected function buildContainerParameterReference($key)
34
    {
35
        return sprintf(
36
            '%%%s%%',
37
            $this->buildContainerId($key)
38
        );
39
    }
40
41
    /**
42
     * @param ContainerBuilder $container
43
     * @param string           $id
44
     * @param string           $class
45
     * @param array            $argumentList
46
     * @param array            $tagList
47
     * @param array            $addMethodCallList
48
     * @param array|null       $factory
49
     *
50
     * @return Definition
51
     */
52
    protected function createService(
53
        ContainerBuilder $container,
54
        $id,
55
        $class,
56
        $argumentList = [],
57
        $tagList = [],
58
        $addMethodCallList = [],
59
        $factory = null
60
    ) {
61
        $definition = new Definition($class, $argumentList);
62
63
        foreach ($tagList as $tag) {
64
            $definition->addTag($tag);
65
        }
66
67
        foreach ($addMethodCallList as $methodCall) {
68
            $args = isset($methodCall[1]) ? $methodCall[1] : [];
69
            $definition->addMethodCall($methodCall[0], $args);
70
        }
71
72
        if (null !== $factory) {
73
            $definition->setFactory($factory);
74
        }
75
76
        $container->setDefinition($this->buildContainerId($id), $definition);
77
78
        return $definition;
79
    }
80
}
81