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

TargetAttribute::match()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 9
ccs 7
cts 7
cp 1
crap 1
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 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