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

AbstractExtension   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 26.32%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 60
ccs 5
cts 19
cp 0.2632
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A buildContainerId() 0 8 1
B createService() 0 28 5
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