Passed
Push — master ( 7ab89a...b0680f )
by Adrien
01:53
created

AbstractAnnotation::getDefaultValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GraphQL\Doctrine\Annotation;
6
7
use GraphQL\Type\Definition\Type;
8
9
/**
10
 * Abstract annotation with common logic for Argument and Field
11
 */
12
abstract class AbstractAnnotation
13
{
14
    /**
15
     * The name of the argument, it must matches the actual PHP argument name
16
     *
17
     * @var null|string
18
     * @Required
19
     */
20
    private $name;
21
22
    /**
23
     * FQCN of PHP class implementing the GraphQL type
24
     *
25
     * @var null|string
26
     */
27
    private $type;
28
29
    /**
30
     * Instance of the GraphQL type
31
     *
32
     * @var null|Type
33
     */
34
    private $typeInstance;
35
36
    /**
37
     * @var null|string
38
     */
39
    private $description;
40
41
    /**
42
     * @var mixed
43
     */
44
    private $defaultValue;
45
46
    /**
47
     * @var bool
48
     */
49
    private $hasDefaultValue = false;
50
51 12
    public function __construct($values = [])
52
    {
53 12
        foreach ($values as $key => $value) {
54 7
            $setter = 'set' . ucfirst($key);
55 7
            $this->$setter($value);
56
        }
57 12
    }
58
59 7
    public function toArray(): array
60
    {
61
        $data = [
62 7
            'name' => $this->getName(),
63 7
            'type' => $this->getTypeInstance(),
64 7
            'description' => $this->getDescription(),
65
        ];
66
67 7
        if ($this->hasDefaultValue()) {
68 7
            $data['defaultValue'] = $this->getDefaultValue();
69
        }
70
71 7
        return $data;
72
    }
73
74
    /**
75
     * @return null|string
76
     */
77 12
    public function getName(): ?string
78
    {
79 12
        return $this->name;
80
    }
81
82
    /**
83
     * @param null|string $name
84
     */
85 12
    public function setName(?string $name): void
86
    {
87 12
        $this->name = $name;
88 12
    }
89
90
    /**
91
     * @return null|string
92
     */
93 8
    public function getType(): ?string
94
    {
95 8
        return $this->type;
96
    }
97
98
    /**
99
     * @param null|string $type
100
     */
101 6
    public function setType(?string $type): void
102
    {
103 6
        $this->type = $type;
104 6
    }
105
106
    /**
107
     * @return null|string
108
     */
109 12
    public function getDescription(): ?string
110
    {
111 12
        return $this->description;
112
    }
113
114
    /**
115
     * @param null|string $description
116
     */
117 12
    public function setDescription(?string $description): void
118
    {
119 12
        $this->description = $description;
120 12
    }
121
122
    /**
123
     * @return mixed
124
     */
125 12
    public function hasDefaultValue()
126
    {
127 12
        return $this->hasDefaultValue;
128
    }
129
130
    /**
131
     * @return mixed
132
     */
133 7
    public function getDefaultValue()
134
    {
135 7
        return $this->defaultValue;
136
    }
137
138
    /**
139
     * @param mixed $defaultValue
140
     */
141 7
    public function setDefaultValue($defaultValue): void
142
    {
143 7
        $this->defaultValue = $defaultValue;
144 7
        $this->hasDefaultValue = true;
145 7
    }
146
147
    /**
148
     * @return null|Type
149
     */
150 12
    public function getTypeInstance(): ?Type
151
    {
152 12
        return $this->typeInstance;
153
    }
154
155
    /**
156
     * @param null|Type $typeInstance
157
     */
158 11
    public function setTypeInstance(?Type $typeInstance): void
159
    {
160 11
        $this->typeInstance = $typeInstance;
161 11
    }
162
}
163