RunnerManager   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 97
Duplicated Lines 28.87 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 15
lcom 0
cbo 1
dl 28
loc 97
ccs 27
cts 33
cp 0.8182
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getRunner() 0 6 2
A getRunners() 14 14 3
A getGroups() 14 14 3
A getDefaultGroup() 0 4 1
A getRunnerServiceId() 0 10 3
A getReporters() 0 11 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Liip\MonitorBundle\Helper;
4
5
use Liip\MonitorBundle\Runner;
6
use Symfony\Component\DependencyInjection\ContainerInterface;
7
8
class RunnerManager
9
{
10
    /** @var ContainerInterface */
11
    private $container;
12
13 7
    public function __construct(ContainerInterface $container)
14
    {
15 7
        $this->container = $container;
16 7
    }
17
18
    /**
19
     * @param string|null $group
20
     *
21
     * @return Runner|null
22
     */
23 4
    public function getRunner($group)
24
    {
25 4
        $runnerServiceId = $this->getRunnerServiceId($group);
26
27 4
        return $runnerServiceId ? $this->container->get($runnerServiceId) : null;
28
    }
29
30
    /**
31
     * @return array|Runner[] key/value $group/$runner
32
     */
33 1 View Code Duplication
    public function getRunners()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35 1
        $runnerServiceIds = $this->container->getParameter('liip_monitor.runners');
36
37 1
        $runners = [];
38
39 1
        foreach ($runnerServiceIds as $serviceId) {
40 1
            if (preg_match('/liip_monitor.runner_(.+)/', $serviceId, $matches)) {
41 1
                $runners[$matches[1]] = $this->container->get($serviceId);
42
            }
43
        }
44
45 1
        return $runners;
46
    }
47
48
    /**
49
     * @return array|string[]
50
     */
51 1 View Code Duplication
    public function getGroups()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53 1
        $runnerServiceIds = $this->container->getParameter('liip_monitor.runners');
54
55 1
        $groups = [];
56
57 1
        foreach ($runnerServiceIds as $serviceId) {
58 1
            if (preg_match('/liip_monitor.runner_(.+)/', $serviceId, $matches)) {
59 1
                $groups[] = $matches[1];
60
            }
61
        }
62
63 1
        return $groups;
64
    }
65
66
    /**
67
     * @return string
68
     */
69 2
    public function getDefaultGroup()
70
    {
71 2
        return $this->container->getParameter('liip_monitor.default_group');
72
    }
73
74
    /**
75
     * @param string|null $group
76
     *
77
     * @return string|null
78
     */
79 4
    private function getRunnerServiceId($group)
80
    {
81 4
        if (null === $group) {
82 1
            $group = $this->getDefaultGroup();
83
        }
84
85 4
        $runnerServiceId = 'liip_monitor.runner_'.$group;
86
87 4
        return $this->container->has($runnerServiceId) ? $runnerServiceId : null;
88
    }
89
90
    /**
91
     * @return array
92
     */
93
    public function getReporters()
94
    {
95
        $runners = $this->getRunners();
96
        $reporters = [];
97
98
        foreach ($runners as $runner) {
99
            $reporters += array_keys($runner->getReporters() + $runner->getAdditionalReporters());
100
        }
101
102
        return $reporters;
103
    }
104
}
105