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

FilterAnd   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

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

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
    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