AbstractAdditionalFieldListener::listen()   B
last analyzed

Complexity

Conditions 7
Paths 5

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 7

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 7
c 1
b 0
f 0
nc 5
nop 1
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 7
rs 8.8333
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Andi\GraphQL\Spiral\Listener;
6
7
use Andi\GraphQL\Attribute\AbstractField;
8
use Andi\GraphQL\Common\ReflectionMethodWithAttribute;
9
use Andi\GraphQL\TypeRegistryInterface;
10
use Spiral\Attributes\ReaderInterface;
11
use Spiral\Tokenizer\TokenizationListenerInterface;
12
13
abstract class AbstractAdditionalFieldListener implements TokenizationListenerInterface
14
{
15
    /**
16
     * @var array<ReflectionMethodWithAttribute>
17
     */
18
    protected array $methods = [];
19
20
    /** @var class-string<AbstractField> */
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<AbstractField> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<AbstractField>.
Loading history...
21
    protected string $attribute;
22
23 7
    public function __construct(
24
        protected readonly ReaderInterface $reader,
25
        protected readonly TypeRegistryInterface $typeRegistry,
26
    ) {
27 7
    }
28
29 6
    public function listen(\ReflectionClass $class): void
30
    {
31 6
        if ($class->isAbstract() || $class->isEnum() || $class->isTrait()) {
0 ignored issues
show
Bug introduced by
The method isEnum() does not exist on ReflectionClass. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
        if ($class->isAbstract() || $class->/** @scrutinizer ignore-call */ isEnum() || $class->isTrait()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
32 3
            return;
33
        }
34
35 3
        foreach ($class->getMethods() as $method) {
36 3
            if ($method->getDeclaringClass()->getName() !== $class->getName()) {
37 1
                continue;
38
            }
39
40 2
            if ($attribute = $this->reader->firstFunctionMetadata($method, $this->attribute)) {
41 1
                $this->methods[] = new ReflectionMethodWithAttribute($method, $attribute);
42
            }
43
        }
44
    }
45
}
46