Completed
Pull Request — master (#428)
by personal
01:43
created

Group   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getName() 0 4 1
A getRegex() 0 4 1
A reduceMetrics() 0 15 3
1
<?php
2
3
namespace Hal\Metric\Group;
4
5
use Hal\Metric\Metrics;
6
7
/**
8
 * Class Group
9
 * Allows to group metrics by regex, given them a name
10
 * @package Hal\Metric\Group
11
 */
12
class Group
13
{
14
    /**
15
     * @var string
16
     */
17
    private $name;
18
19
    /**
20
     * @var string
21
     */
22
    private $regex;
23
24
    /**
25
     * Group constructor.
26
     * @param string $name
27
     * @param string $regex
28
     */
29
    public function __construct($name, $regex)
30
    {
31
        $this->name = $name;
32
        $this->regex = $regex;
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function getName()
39
    {
40
        return $this->name;
41
    }
42
43
    /**
44
     * @return string
45
     */
46
    public function getRegex()
47
    {
48
        return $this->regex;
49
    }
50
51
    /**
52
     * @param Metrics $metrics
53
     * @return Metrics
54
     */
55
    public function reduceMetrics(Metrics $metrics)
56
    {
57
        $all = $metrics->all();
58
        $matched = new Metrics();
59
60
        foreach ($all as $metric) {
61
            if (!preg_match($this->regex, $metric->getName())) {
62
                continue;
63
            }
64
65
            $matched->attach($metric);
66
        }
67
68
        return $matched;
69
    }
70
}
71