Passed
Push — master ( c9351b...a8a6df )
by Smoren
02:20
created

CompositeRule::__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 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 2
rs 10
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 CompositeRule extends Rule implements CompositeRuleInterface
11
{
12
    /**
13
     * @var array<RuleInterface>
14
     */
15
    protected array $rules = [];
16
17
    /**
18
     * @param array<RuleInterface> $rules
19
     */
20 9
    public function __construct(array $rules, string $name)
21
    {
22 9
        parent::__construct($name);
23 9
        foreach ($rules as $rule) {
24 7
            $this->addRule($rule);
25
        }
26
    }
27
28
    /**
29
     * {@inheritDoc}
30
     *
31
     * @return static
32
     */
33 7
    public function addRule(RuleInterface $rule): self
34
    {
35 7
        $this->rules[] = $rule;
36 7
        return $this;
37
    }
38
}
39