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

UserFullName   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 57
rs 10
wmc 8

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getName() 0 3 1
A getDeprecationReason() 0 3 1
A getMode() 0 3 1
A complexity() 0 3 1
A getType() 0 3 1
A getArguments() 0 7 1
A getDescription() 0 3 1
A resolve() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\GraphQL\Field;
6
7
use Andi\GraphQL\Argument\Argument;
8
use Andi\GraphQL\Definition\Field\ArgumentsAwareInterface;
9
use Andi\GraphQL\Definition\Field\ComplexityAwareInterface;
10
use Andi\GraphQL\Definition\Field\ObjectFieldInterface;
11
use Andi\GraphQL\Definition\Field\ResolveAwareInterface;
12
use Andi\GraphQL\Definition\Field\TypeAwareInterface;
13
use App\GraphQL\Type\User;
14
use GraphQL\Type\Definition as Webonyx;
15
16
final class UserFullName implements
17
    ObjectFieldInterface,
18
    ArgumentsAwareInterface,
19
    ResolveAwareInterface,
20
    ComplexityAwareInterface
21
{
22
    public function getName(): string
23
    {
24
        return 'fullName';
25
    }
26
27
    public function getDescription(): ?string
28
    {
29
        return null;
30
    }
31
32
    public function getDeprecationReason(): ?string
33
    {
34
        return null;
35
    }
36
37
    public function getType(): string
38
    {
39
        return 'String';
40
    }
41
42
    public function getMode(): int
43
    {
44
        return TypeAwareInterface::IS_REQUIRED;
45
    }
46
47
    public function getArguments(): iterable
48
    {
49
        yield new Argument(
50
            name: 'separator',
51
            type: 'String',
52
            mode: TypeAwareInterface::IS_REQUIRED,
53
            defaultValue: ' ',
54
        );
55
    }
56
57
    public function resolve(mixed $objectValue, array $args, mixed $context, Webonyx\ResolveInfo $info): mixed
58
    {
59
        /** @var User $objectValue */
60
        return implode(
61
            $args['separator'],
62
            [
63
                $objectValue->getLastname(),
64
                $objectValue->getFirstname(),
65
                (new \ReflectionProperty($objectValue, 'middlename'))->getValue($objectValue),
66
            ],
67
        );
68
    }
69
70
    public function complexity(int $childrenComplexity, array $args): int
71
    {
72
        return $childrenComplexity + 1;
73
    }
74
}
75