Passed
Pull Request — master (#38)
by Sergei
05:23 queued 02:36
created

FilterAnd::match()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Classifier\Filter\Condition;
6
7
use ReflectionClass;
8
use Yiisoft\Classifier\Filter\FilterInterface;
9
10
class FilterAnd implements FilterInterface
11
{
12
    private array $filters;
13
14 1
    public function __construct(FilterInterface ...$filters)
15
    {
16 1
        if (count($filters) < 2) {
17 1
            throw new \InvalidArgumentException('At least 2 filters should be provided.');
18
        }
19
        $this->filters = $filters;
20
    }
21
22
    /**
23
     * @inheritDoc
24
     */
25 2
    public function match(ReflectionClass $reflectionClass): bool
26
    {
27 2
        foreach ($this->filters as $filter) {
28 2
            if (!$filter->match($reflectionClass)) {
29 1
                return false;
30
            }
31
        }
32
33 1
        return true;
34
    }
35
}
36