Completed
Push — master ( 825b2b...9563c8 )
by René
03:01
created

RuleCollection   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 3
dl 0
loc 36
ccs 3
cts 3
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 4 1
A check() 0 10 2
1
<?php
2
3
namespace Zortje\Rules;
4
5
use Zortje\Rules\Common\Collection;
6
7
/**
8
 * Class RuleCollection
9
 *
10
 * @package Zortje\Rules
11
 */
12
class RuleCollection extends Collection
13
{
14
15
    /**
16
     * @var RuleInterface[]
17
     */
18
    protected $collection = [];
19
20
    /**
21
     * Add Rule to collection
22
     *
23
     * @param RuleInterface $rule
24
     */
25 1
    public function add(RuleInterface $rule)
26
    {
27 1
        $this->collection[] = $rule;
28 1
    }
29
30
    /**
31
     * Check all rules in collection
32
     *
33
     * @param Subject $ruleSubject
34
     *
35
     * @return ResultCollection
36
     */
37
    public function check(Subject $ruleSubject): ResultCollection
38
    {
39
        $ruleResultCollection = new ResultCollection();
40
41
        foreach ($this->collection as $rule) {
42
            $ruleResultCollection->merge($rule->check($ruleSubject));
43
        }
44
45
        return $ruleResultCollection;
46
    }
47
}
48