Test Failed
Push — feature/improve ( 3cba19 )
by Yo
03:30
created

AbstractExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 0
loc 53
rs 10
c 0
b 0
f 0
ccs 15
cts 15
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildContainerId() 0 8 1
B createService() 0 23 4
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
13
    /**
14
     * @param string $key
15
     *
16
     * @return string
17
     */
18 9
    protected function buildContainerId($key)
19
    {
20 9
        return sprintf(
21 9
            '%s.%s',
22 9
            self::BASE_CONTAINER_ID,
23
            $key
24 9
        );
25
    }
26
27
    /**
28
     * @param ContainerBuilder $container
29
     * @param string           $id
30
     * @param string           $class
31
     * @param array            $argumentList
32
     * @param array            $tagList
33
     * @param array            $addMethodCallList
34
     *
35 6
     * @return Definition
36
     */
37
    protected function createService(
38
        ContainerBuilder $container,
39
        $id,
40
        $class,
41
        $argumentList = [],
42
        $tagList = [],
43 6
        $addMethodCallList = []
44
    ) {
45 6
        $definition = new Definition($class, $argumentList);
46 4
47 6
        foreach ($tagList as $tag) {
48
            $definition->addTag($tag);
49 6
        }
50 2
51 6
        foreach ($addMethodCallList as $methodCall) {
52
            $args = isset($methodCall[1]) ? $methodCall[1] : [];
53 6
            $definition->addMethodCall($methodCall[0], $args);
54 6
        }
55
56
        $container->setDefinition($this->buildContainerId($id), $definition);
57
58
        return $definition;
59
    }
60
}
61