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

buildContainerParameterReference()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
crap 2
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