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

User   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 48
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getFirstname() 0 4 1
A getInterfaces() 0 4 1
A getLastname() 0 4 1
A getDisplayName() 0 7 1
A __construct() 0 6 1
A getFields() 0 3 1
A getPet() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\GraphQL\Type;
6
7
use Andi\GraphQL\Attribute\ObjectField;
8
use Andi\GraphQL\Attribute\ObjectType;
9
use Andi\GraphQL\Definition\Type\FieldsAwareInterface;
10
use Andi\GraphQL\Definition\Type\InterfacesAwareInterface;
11
use App\GraphQL\Field\UserFullName;
12
13
#[ObjectType]
14
class User implements UserInterface, InterfacesAwareInterface, FieldsAwareInterface
15
{
16
    public function __construct(
17
        private readonly string $lastname,
18
        private readonly string $firstname,
19
        #[ObjectField]
20
        private readonly string $middlename,
21
    ) {
22
    }
23
24
    #[ObjectField]
25
    public function getLastname(): string
26
    {
27
        return $this->lastname;
28
    }
29
30
    #[ObjectField]
31
    public function getFirstname(): string
32
    {
33
        return $this->firstname;
34
    }
35
36
    #[ObjectField]
37
    public function getDisplayName(): string
38
    {
39
        return sprintf('%1$s %2$.1s. %3$s',
40
            $this->firstname,
41
            $this->middlename,
42
            $this->lastname,
43
        );
44
    }
45
46
    #[ObjectField(type: Pet::class)]
47
    public function getPet(): string
48
    {
49
        return 'Cerberus';
50
    }
51
52
    public function getInterfaces(): iterable
53
    {
54
        yield UserInterface::class;
55
        yield FullNameAwareInterface::class;
56
    }
57
58
    public function getFields(): iterable
59
    {
60
        yield new UserFullName();
61
    }
62
}
63