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

ClassAttributes::match()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 8
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 13
ccs 9
cts 9
cp 1
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Classifier\Filter;
6
7
use ReflectionAttribute;
8
use ReflectionClass;
9
10
final class ClassAttributes implements FilterInterface
11
{
12
    private array $attributes;
13
14 8
    public function __construct(string ...$attributes)
15
    {
16 8
        $this->attributes = $attributes;
17
    }
18
19 8
    public function match(ReflectionClass $reflectionClass): bool
20
    {
21 8
        if (empty($this->attributes)) {
22 4
            return false;
23
        }
24
25 4
        $attributes = $reflectionClass->getAttributes();
26 4
        $attributeNames = array_map(
27 4
            static fn(ReflectionAttribute $attribute) => $attribute->getName(),
28 4
            $attributes
29 4
        );
30
31 4
        return count(array_intersect($this->attributes, $attributeNames)) === count($this->attributes);
32
    }
33
}
34