AbstractAdditionalFieldListener   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 29
ccs 10
cts 10
cp 1
rs 10
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B listen() 0 13 7
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