Passed
Push — master ( ec5386...e56f88 )
by Andrey
53s queued 14s
created

Pet   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getDescription() 0 3 1
A addAdditionalField() 0 5 1
A getFields() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\GraphQL\Type;
6
7
use Andi\GraphQL\Definition\Type\ObjectTypeInterface;
8
use Andi\GraphQL\Type\DynamicObjectTypeInterface;
9
use GraphQL\Type\Definition as Webonyx;
10
11
class Pet implements ObjectTypeInterface, DynamicObjectTypeInterface
12
{
13
    private array $additionalFields = [];
14
15
    public function getName(): string
16
    {
17
        return 'pet';
18
    }
19
20
    public function getDescription(): ?string
21
    {
22
        return null;
23
    }
24
25
    public function getFields(): iterable
26
    {
27
        yield new Webonyx\FieldDefinition([
28
            'name' => 'nickname',
29
            'type' => Webonyx\Type::nonNull(Webonyx\Type::string()),
30
            'resolve' => static fn (string $nickname) => $nickname,
31
        ]);
32
33
        yield from $this->additionalFields;
34
    }
35
36
    public function addAdditionalField(mixed $field): static
37
    {
38
        $this->additionalFields[] = $field;
39
40
        return $this;
41
    }
42
}
43