Passed
Pull Request — master (#38)
by Rustam
02:23
created

FilterAnd   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 27
ccs 8
cts 9
cp 0.8889
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 9 3
A __construct() 0 6 2
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