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

ExampleAbstractObjectType::getFirstname()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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