UserPetUnion::resolveType()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 5
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 11
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\GraphQL\Type;
6
7
use Andi\GraphQL\Definition\Type\ResolveTypeAwareInterface;
8
use Andi\GraphQL\Definition\Type\UnionTypeInterface;
9
use GraphQL\Type\Definition as Webonyx;
10
11
final class UserPetUnion implements UnionTypeInterface, ResolveTypeAwareInterface
12
{
13
    public function getName(): string
14
    {
15
        return 'UserPetUnion';
16
    }
17
18
    public function getDescription(): ?string
19
    {
20
        return null;
21
    }
22
23
    public function getTypes(): iterable
24
    {
25
        yield 'User';
26
        yield Pet::class;
27
    }
28
29
    public static function resolveType(mixed $value, mixed $context, Webonyx\ResolveInfo $info): ?string
30
    {
31
        if ($value instanceof User) {
32
            return User::class;
33
        }
34
35
        if (\is_string($value)) {
36
            return 'pet';
37
        }
38
39
        return null;
40
    }
41
}
42