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

ClassAttributes   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 22
ccs 11
cts 11
cp 1
rs 10
wmc 3

2 Methods

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