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

RuleCollection::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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