Passed
Pull Request — master (#24)
by David
03:06
created

ExposedField::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
4
namespace TheCodingMachine\GraphQL\Controllers\Annotations;
5
6
/**
7
 * ExposedFields are fields that are directly exposed 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 = Right::class),
15
 *   @Attribute("returnType", type = "string"),
16
 * })
17
 */
18
class ExposedField
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 exposed 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