Completed
Pull Request — master (#24)
by David
01:56
created

SourceField   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 13
dl 0
loc 71
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A isLogged() 0 3 1
A getName() 0 3 1
A getReturnType() 0 3 1
A getRight() 0 3 1
A __construct() 0 6 1
1
<?php
2
3
4
namespace TheCodingMachine\GraphQL\Controllers\Annotations;
5
6
/**
7
 * SourceFields are fields that are directly source from the base object into GraphQL.
8
 *
9
 * @Annotation
10
 * @Target({"CLASS"})
11
 * @Attributes({
12
 *   @Attribute("name", type = "string"),
13
 *   @Attribute("logged", type = "bool"),
14
 *   @Attribute("right", type = "TheCodingMachine\GraphQL\Controllers\Annotations\Right"),
15
 *   @Attribute("returnType", type = "string"),
16
 * })
17
 */
18
class SourceField
19
{
20
    /**
21
     * @var Right|null
22
     */
23
    private $right;
24
25
    /**
26
     * @var string|null
27
     */
28
    private $name;
29
30
    /**
31
     * @var bool
32
     */
33
    private $logged;
34
35
    /**
36
     * @var string|null
37
     */
38
    private $returnType;
39
40
    /**
41
     * @param mixed[] $attributes
42
     */
43
    public function __construct(array $attributes = [])
44
    {
45
        $this->name = $attributes['name'] ?? null;
46
        $this->logged = $attributes['logged'] ?? false;
47
        $this->right = $attributes['right'] ?? null;
48
        $this->returnType = $attributes['returnType'] ?? null;
49
    }
50
51
    /**
52
     * Returns the GraphQL right to be applied to this source field.
53
     *
54
     * @return Right|null
55
     */
56
    public function getRight(): ?Right
57
    {
58
        return $this->right;
59
    }
60
61
    /**
62
     * Returns the name of the GraphQL query/mutation/field.
63
     * If not specified, the name of the method should be used instead.
64
     *
65
     * @return null|string
66
     */
67
    public function getName(): ?string
68
    {
69
        return $this->name;
70
    }
71
72
    /**
73
     * @return bool
74
     */
75
    public function isLogged(): bool
76
    {
77
        return $this->logged;
78
    }
79
80
    /**
81
     * Returns the GraphQL return type of the request (as a string).
82
     * The string can represent the FQCN of the type or an entry in the container resolving to the GraphQL type.
83
     *
84
     * @return string|null
85
     */
86
    public function getReturnType(): ?string
87
    {
88
        return $this->returnType;
89
    }
90
}
91