Completed
Push — standalone ( 7c3a2c...83bb11 )
by Philip
05:16
created

ClassMetadata::mergeMethods()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
crap 3
1
<?php
2
3
namespace Dontdrinkandroot\RestBundle\Metadata;
4
5
use Dontdrinkandroot\RestBundle\Metadata\Annotation\Right;
6
use Metadata\MergeableClassMetadata;
7
use Metadata\MergeableInterface;
8
9
class ClassMetadata extends MergeableClassMetadata
10
{
11
    /**
12
     * @var bool
13
     */
14
    public $restResource;
15
16
    /**
17
     * @var string
18
     */
19
    public $namePrefix;
20
21
    /**
22
     * @var string
23
     */
24
    public $pathPrefix;
25
26
    /**
27
     * @var string
28
     */
29
    public $service;
30
31
    /**
32
     * @var string
33
     */
34
    public $controller;
35
36
    /**
37
     * @var Right|null
38
     */
39
    public $postRight;
40
41
    /**
42
     * @var Right|null
43
     */
44
    public $putRight;
45
46
    /**
47
     * @var Right|null
48
     */
49
    public $deleteRight;
50
51
    /**
52
     * @var Right|null
53
     */
54
    public $listRight;
55
56
    /**
57
     * @var Right|null
58
     */
59
    public $getRight;
60
61
    /**
62
     * @var string[]
63
     */
64
    public $methods = ['LIST', 'POST', 'GET', 'PUT', 'DELETE'];
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 2
    public function merge(MergeableInterface $object)
70
    {
71 2
        parent::merge($object);
72
        /** @var ClassMetadata $object */
73 2
        $this->restResource = $object->restResource;
74 2
        $this->namePrefix = $object->namePrefix;
75 2
        $this->pathPrefix = $object->pathPrefix;
76 2
        $this->service = $object->service;
77 2
        $this->controller = $object->controller;
78 2
        $this->listRight = $object->listRight;
79 2
        $this->getRight = $object->getRight;
80 2
        $this->postRight = $object->postRight;
81 2
        $this->putRight = $object->putRight;
82 2
        $this->deleteRight = $object->deleteRight;
83 2
        $this->methods = $this->mergeMethods($this->methods, $object->methods);
84 2
    }
85
86
    /**
87
     * @param bool $restResource
88
     */
89 22
    public function setRestResource($restResource)
90
    {
91 22
        $this->restResource = $restResource;
92 22
    }
93
94
    /**
95
     * @return boolean
96
     */
97 4
    public function isRestResource()
98
    {
99 4
        return $this->restResource;
100
    }
101
102
    /**
103
     * @return string
104
     */
105 4
    public function getNamePrefix()
106
    {
107 4
        return $this->namePrefix;
108
    }
109
110
    /**
111
     * @param string $namePrefix
112
     */
113
    public function setNamePrefix($namePrefix)
114
    {
115
        $this->namePrefix = $namePrefix;
116
    }
117
118
    /**
119
     * @return string
120
     */
121 4
    public function getPathPrefix()
122
    {
123 4
        return $this->pathPrefix;
124
    }
125
126
    /**
127
     * @param string $pathPrefix
128
     */
129 12
    public function setPathPrefix(string $pathPrefix)
130
    {
131 12
        $this->pathPrefix = $pathPrefix;
132 12
    }
133
134
    /**
135
     * @return string
136
     */
137 4
    public function getController()
138
    {
139 4
        return $this->controller;
140
    }
141
142
    /**
143
     * @param string $controller
144
     */
145
    public function setController($controller)
146
    {
147
        $this->controller = $controller;
148
    }
149
150
    /**
151
     * @return string
152
     */
153 4
    public function getService()
154
    {
155 4
        return $this->service;
156
    }
157
158
    /**
159
     * @param string $service
160
     */
161
    public function setService($service)
162
    {
163
        $this->service = $service;
164
    }
165
166
    /**
167
     * @return Right|null
168
     */
169 2
    public function getDeleteRight()
170
    {
171 2
        return $this->deleteRight;
172
    }
173
174
    /**
175
     * @param Right|null $deleteRight
176
     */
177
    public function setDeleteRight(Right $deleteRight)
178
    {
179
        $this->deleteRight = $deleteRight;
180
    }
181
182
    /**
183
     * @return Right|null
184
     */
185 2
    public function getPostRight()
186
    {
187 2
        return $this->postRight;
188
    }
189
190
    /**
191
     * @param Right|null $postRight
192
     */
193
    public function setPostRight(Right $postRight)
194
    {
195
        $this->postRight = $postRight;
196
    }
197
198
    /**
199
     * @return Right|null
200
     */
201 6
    public function getPutRight()
202
    {
203 6
        return $this->putRight;
204
    }
205
206
    /**
207
     * @param Right|null $putRight
208
     */
209 12
    public function setPutRight(Right $putRight)
210
    {
211 12
        $this->putRight = $putRight;
212 12
    }
213
214
    /**
215
     * @return Right|null
216
     */
217 6
    public function getListRight()
218
    {
219 6
        return $this->listRight;
220
    }
221
222
    /**
223
     * @param Right|null $listRight
224
     */
225 12
    public function setListRight(Right $listRight)
226
    {
227 12
        $this->listRight = $listRight;
228 12
    }
229
230
    /**
231
     * @return Right|null
232
     */
233 6
    public function getGetRight()
234
    {
235 6
        return $this->getRight;
236
    }
237
238
    /**
239
     * @param Right|null $getRight
240
     */
241 12
    public function setGetRight(Right $getRight)
242
    {
243 12
        $this->getRight = $getRight;
244 12
    }
245
246
    /**
247
     * @return string[]
248
     */
249 4
    public function getMethods()
250
    {
251 4
        return $this->methods;
252
    }
253
254
    /**
255
     * @param string[] $methods
256
     */
257
    public function setMethods(array $methods)
258
    {
259
        $this->methods = $methods;
260
    }
261
262 22
    public function getPropertyMetadata(string $property): ?PropertyMetadata
263
    {
264 22
        if (array_key_exists($property, $this->propertyMetadata)) {
265 22
            return $this->propertyMetadata[$property];
266
        }
267
268 12
        return null;
269
    }
270
271 2
    private function mergeMethods($thisMethods, $otherMethods)
272
    {
273 2
        $mergedMethods = [];
274 2
        foreach ($thisMethods as $thisMethod) {
275 2
            if (in_array($thisMethod, $otherMethods)) {
276 2
                $mergedMethods[] = $thisMethod;
277
            }
278
        }
279
280 2
        return $mergedMethods;
281
    }
282
}
283