Passed
Push — master ( 295792...3cace9 )
by Smoren
03:09
created

CompositeMixedRule::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Smoren\Validator\Rules;
6
7
use Smoren\Validator\Interfaces\RuleInterface;
8
use Smoren\Validator\Interfaces\CompositeRuleInterface;
9
10
abstract class CompositeMixedRule extends MixedRule implements CompositeRuleInterface
11
{
12
    /**
13
     * @var array<RuleInterface>
14
     */
15
    protected array $rules = [];
16
17
    /**
18
     * @param array<RuleInterface> $rules
19
     */
20 16
    public function __construct(array $rules, string $name)
21
    {
22 16
        parent::__construct($name);
23 16
        foreach ($rules as $rule) {
24 12
            $this->addRule($rule);
25
        }
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     *
31
     * @return static
32
     */
33 12
    public function addRule(RuleInterface $rule): self
34
    {
35 12
        $this->rules[] = $rule;
36 12
        return $this;
37
    }
38
}
39