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

ClassImplements::match()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
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 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Classifier\Filter;
6
7
use ReflectionClass;
8
9
final class ClassImplements implements FilterInterface
10
{
11
    private array $interfaces;
12
13 22
    public function __construct(string ...$interfaces)
14
    {
15 22
        $this->interfaces = $interfaces;
16
    }
17
18 22
    public function match(ReflectionClass $reflectionClass): bool
19
    {
20 22
        if (empty($this->interfaces) || $reflectionClass->isInterface()) {
21 10
            return false;
22
        }
23 20
        $interfaces = $reflectionClass->getInterfaceNames();
24
25 20
        return count(array_intersect($this->interfaces, $interfaces)) === count($this->interfaces);
26
    }
27
}
28