Passed
Pull Request — master (#38)
by Rustam
02:23
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
    /**
13
     * @var FilterInterface[]
14
     */
15
    private array $filters;
16
17 1
    public function __construct(FilterInterface ...$filters)
18
    {
19 1
        if (count($filters) < 2) {
20 1
            throw new \InvalidArgumentException('At least 2 filters should be provided.');
21
        }
22
        $this->filters = $filters;
23
    }
24
25
    /**
26
     * @inheritDoc
27
     */
28 2
    public function match(ReflectionClass $reflectionClass): bool
29
    {
30 2
        foreach ($this->filters as $filter) {
31 2
            if (!$filter->match($reflectionClass)) {
32 1
                return false;
33
            }
34
        }
35
36 1
        return true;
37
    }
38
}
39