UserPetUnion::getTypes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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