GroupCollection   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 35
rs 10
c 0
b 0
f 0
wmc 7

3 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 3 1
A __construct() 0 11 3
A fill() 0 9 3
1
<?php
2
/**
3
 * Created by solly [18.10.17 11:02]
4
 */
5
6
namespace insolita\codestat\lib\collection;
7
8
class GroupCollection extends BaseCollection
9
{
10
    /**@var Group[] $items * */
11
    protected $items;
12
    
13
    /**
14
     * @param \insolita\codestat\lib\collection\Group[] $items
15
     */
16
    public function __construct(array $items = [])
17
    {
18
        $rules = [];
19
        foreach ($items as $name => $rule) {
20
            if ($rule instanceof Group) {
21
                $rules[$rule->getName()] = $rule;
22
            } else {
23
                $rules[$name] = new Group($name, $rule);
24
            }
25
        }
26
        parent::__construct($rules);
27
    }
28
    
29
    public function fill(\ReflectionClass $reflection)
30
    {
31
        foreach ($this->items as $name => $group) {
32
            if ($group->validate($reflection)) {
33
                $group->addFile($reflection->getFileName());
34
                break;
35
            }
36
        }
37
        return $this;
38
    }
39
    
40
    public static function make(array $items)
41
    {
42
        return new static($items);
43
    }
44
}
45