UserPetUnion   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A resolveType() 0 11 3
A getDescription() 0 3 1
A getName() 0 3 1
A getTypes() 0 4 1
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