Completed
Push — master ( e5e74e...13adb5 )
by Yo
02:16
created

AbstractExtension::createService()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 11
cts 11
cp 1
rs 8.7972
c 0
b 0
f 0
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
    const TEST_CLIENT_SERVICE_ID = 'behat3_symfony_extension.test.client';
13
14
    /**
15
     * @param string $key
16
     *
17
     * @return string
18
     */
19 9
    protected function buildContainerId($key)
20
    {
21 9
        return sprintf(
22 9
            '%s.%s',
23 9
            self::BASE_CONTAINER_ID,
24
            $key
25 9
        );
26
    }
27
28
    /**
29
     * @param ContainerBuilder $container
30
     * @param string           $id
31
     * @param string           $class
32
     * @param array            $argumentList
33
     * @param array            $tagList
34
     * @param array            $addMethodCallList
35
     *
36
     * @return Definition
37
     */
38 6
    protected function createService(
39
        ContainerBuilder $container,
40
        $id,
41
        $class,
42
        $argumentList = [],
43
        $tagList = [],
44
        $addMethodCallList = []
45
    ) {
46 6
        $definition = new Definition($class, $argumentList);
47
48 6
        foreach ($tagList as $tag) {
49 6
            $definition->addTag($tag);
50 6
        }
51
52 6
        foreach ($addMethodCallList as $methodCall) {
53 4
            $args = isset($methodCall[1]) ? $methodCall[1] : [];
54 4
            $definition->addMethodCall($methodCall[0], $args);
55 6
        }
56
57 6
        $container->setDefinition($this->buildContainerId($id), $definition);
58
59 6
        return $definition;
60
    }
61
}
62