GroupCollection::make()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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