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

TargetAttribute   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 18
ccs 9
cts 9
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A match() 0 9 1
A __construct() 0 2 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 TargetAttribute implements FilterInterface
11
{
12
    /**
13
     * @param class-string $attribute
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
14
     */
15 6
    public function __construct(private string $attribute)
16
    {
17 6
    }
18
19 7
    public function match(ReflectionClass $reflectionClass): bool
20
    {
21 7
        $attributes = $reflectionClass->getAttributes($this->attribute, ReflectionAttribute::IS_INSTANCEOF);
22 7
        $attributeNames = array_map(
23 7
            static fn(ReflectionAttribute $attribute) => $attribute->getName(),
24 7
            $attributes
25 7
        );
26
27 7
        return !empty($attributeNames);
28
    }
29
}
30