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

ExampleAbstractObjectType   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 27
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFirstname() 0 3 1
A resolveField() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\GraphQL\Type;
6
7
use Andi\GraphQL\Definition\Field\TypeAwareInterface;
8
use Andi\GraphQL\Definition\Type\ResolveFieldAwareInterface;
9
use Andi\GraphQL\Type\AbstractObjectType;
10
use GraphQL\Type\Definition as Webonyx;
11
12
final class ExampleAbstractObjectType extends AbstractObjectType implements ResolveFieldAwareInterface
13
{
14
    protected string $name = 'ExampleAbstractObjectType';
15
16
    protected iterable $fields = [
17
        'lastname' => 'String',
18
        'firstname' => [
19
            'type' => 'String',
20
            'mode' => TypeAwareInterface::IS_REQUIRED,
21
            'description' => 'User firstname',
22
            'resolve' => [self::class, 'getFirstname'],
23
        ],
24
    ];
25
26
    protected iterable $interfaces = [ExampleAbstractInterfaceType::class];
27
28
    private function getFirstname(User $user): string
29
    {
30
        return $user->getFirstname();
31
    }
32
33
    public function resolveField(mixed $value, array $args, mixed $context, Webonyx\ResolveInfo $info): mixed
34
    {
35
        /** @var User $value */
36
        return match ($info->fieldName) {
37
            'lastname' => $value->getLastname(),
38
            default => null,
39
        };
40
    }
41
}
42