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

CompositeRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 27
ccs 7
cts 7
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addRule() 0 4 1
A __construct() 0 5 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 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