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

AbstractExtension::createService()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.7972
c 0
b 0
f 0
ccs 9
cts 9
cp 1
cc 4
eloc 15
nc 6
nop 6
crap 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