Failed Conditions
Pull Request — master (#25)
by Yo
03:13 queued 39s
created

AbstractExtension::buildContainerId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1
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 ContainerBuilder $container
30
     * @param string           $id
31
     * @param string           $class
32
     * @param array            $argumentList
33
     * @param array            $tagList
34
     * @param array            $addMethodCallList
35
     * @param array|null       $factory
36
     *
37
     * @return Definition
38
     */
39
    protected function createService(
40
        ContainerBuilder $container,
41
        $id,
42
        $class,
43
        $argumentList = [],
44
        $tagList = [],
45
        $addMethodCallList = [],
46
        $factory = null
47
    ) {
48
        $definition = new Definition($class, $argumentList);
49
50
        foreach ($tagList as $tag) {
51
            $definition->addTag($tag);
52
        }
53
54
        foreach ($addMethodCallList as $methodCall) {
55
            $args = isset($methodCall[1]) ? $methodCall[1] : [];
56
            $definition->addMethodCall($methodCall[0], $args);
57
        }
58
59
        if (null !== $factory) {
60
            $definition->setFactory($factory);
61
        }
62
63
        $container->setDefinition($this->buildContainerId($id), $definition);
64
65
        return $definition;
66
    }
67
}
68