Skip to content

Commit 5332901

Browse files
committed
minor changes
1 parent d895fb8 commit 5332901

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

src/Annotation/Route.php

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,58 +37,80 @@ final class Route implements RouteDescriptorInterface
3737
{
3838

3939
/**
40+
* A route name
41+
*
4042
* @var string
4143
*/
4244
private $name;
4345

4446
/**
47+
* A route host
48+
*
4549
* @var null|string
4650
*/
4751
private $host;
4852

4953
/**
54+
* A route path
55+
*
5056
* @var string
5157
*/
5258
private $path;
5359

5460
/**
61+
* A route methods
62+
*
5563
* @var string[]
5664
*/
5765
private $methods;
5866

5967
/**
68+
* A route middlewares
69+
*
6070
* @var string[]
6171
*/
6272
private $middlewares;
6373

6474
/**
75+
* A route attributes
76+
*
6577
* @var array
6678
*/
6779
private $attributes;
6880

6981
/**
82+
* A route summary
83+
*
7084
* @var string
7185
*/
7286
private $summary;
7387

7488
/**
89+
* A route description
90+
*
7591
* @var string
7692
*/
7793
private $description;
7894

7995
/**
96+
* A route tags
97+
*
8098
* @var string[]
8199
*/
82100
private $tags;
83101

84102
/**
103+
* A route priority
104+
*
85105
* @var int
86106
*/
87107
private $priority;
88108

89109
/**
90110
* Constructor of the annotation
111+
*
91112
* @param array $params
113+
*
92114
* @throws InvalidDescriptorArgumentException
93115
*/
94116
public function __construct(array $params)
@@ -185,39 +207,71 @@ public function getPriority() : int
185207
return $this->priority;
186208
}
187209

210+
/**
211+
* @param array $params
212+
*
213+
* @return string
214+
*
215+
* @throws InvalidDescriptorArgumentException
216+
*/
188217
private function extractNameFromParams(array $params) : string
189218
{
190219
$name = $params['name'] ?? '';
220+
191221
if ('' === $name || !is_string($name)) {
192222
throw new InvalidDescriptorArgumentException('@Route.name must contain a non-empty string.');
193223
}
194224

195225
return $name;
196226
}
197227

228+
/**
229+
* @param array $params
230+
*
231+
* @return null|string
232+
*
233+
* @throws InvalidDescriptorArgumentException
234+
*/
198235
private function extractHostFromParams(array $params) : ?string
199236
{
200237
$host = $params['host'] ?? null;
238+
201239
if (isset($host) && ('' === $host || !is_string($host))) {
202240
throw new InvalidDescriptorArgumentException('@Route.host must contain a non-empty string.');
203241
}
204242

205243
return $host;
206244
}
207245

246+
/**
247+
* @param array $params
248+
*
249+
* @return string
250+
*
251+
* @throws InvalidDescriptorArgumentException
252+
*/
208253
private function extractPathFromParams(array $params) : string
209254
{
210255
$path = $params['path'] ?? '';
256+
211257
if ('' === $path || !is_string($path)) {
212258
throw new InvalidDescriptorArgumentException('@Route.path must contain a non-empty string.');
213259
}
214260

215261
return $path;
216262
}
217263

264+
/**
265+
* @param array $params
266+
*
267+
* @return string[]
268+
*
269+
* @throws InvalidDescriptorArgumentException
270+
*/
218271
private function extractMethodsFromParams(array $params) : array
219272
{
220273
$methods = $params['methods'] ?? [];
274+
221275
if ([] === $methods || !is_array($methods)) {
222276
throw new InvalidDescriptorArgumentException('@Route.methods must contain a non-empty array.');
223277
}
@@ -231,9 +285,17 @@ private function extractMethodsFromParams(array $params) : array
231285
return $methods;
232286
}
233287

288+
/**
289+
* @param array $params
290+
*
291+
* @return string[]
292+
*
293+
* @throws InvalidDescriptorArgumentException
294+
*/
234295
private function extractMiddlewaresFromParams(array $params) : array
235296
{
236297
$middlewares = $params['middlewares'] ?? [];
298+
237299
if (!is_array($middlewares)) {
238300
throw new InvalidDescriptorArgumentException('@Route.middlewares must contain an array.');
239301
}
@@ -249,39 +311,71 @@ private function extractMiddlewaresFromParams(array $params) : array
249311
return $middlewares;
250312
}
251313

314+
/**
315+
* @param array $params
316+
*
317+
* @return array
318+
*
319+
* @throws InvalidDescriptorArgumentException
320+
*/
252321
private function extractAttributesFromParams(array $params) : array
253322
{
254323
$attributes = $params['attributes'] ?? [];
324+
255325
if (!is_array($attributes)) {
256326
throw new InvalidDescriptorArgumentException('@Route.attributes must contain an array.');
257327
}
258328

259329
return $attributes;
260330
}
261331

332+
/**
333+
* @param array $params
334+
*
335+
* @return string
336+
*
337+
* @throws InvalidDescriptorArgumentException
338+
*/
262339
private function extractSummaryFromParams(array $params) : string
263340
{
264341
$summary = $params['summary'] ?? '';
342+
265343
if (!is_string($summary)) {
266344
throw new InvalidDescriptorArgumentException('@Route.summary must contain a string.');
267345
}
268346

269347
return $summary;
270348
}
271349

350+
/**
351+
* @param array $params
352+
*
353+
* @return string
354+
*
355+
* @throws InvalidDescriptorArgumentException
356+
*/
272357
private function extractDescriptionFromParams(array $params) : string
273358
{
274359
$description = $params['description'] ?? '';
360+
275361
if (!is_string($description)) {
276362
throw new InvalidDescriptorArgumentException('@Route.description must contain a string.');
277363
}
278364

279365
return $description;
280366
}
281367

368+
/**
369+
* @param array $params
370+
*
371+
* @return string[]
372+
*
373+
* @throws InvalidDescriptorArgumentException
374+
*/
282375
private function extractTagsFromParams(array $params) : array
283376
{
284377
$tags = $params['tags'] ?? [];
378+
285379
if (!is_array($tags)) {
286380
throw new InvalidDescriptorArgumentException('@Route.tags must contain an array.');
287381
}
@@ -295,9 +389,17 @@ private function extractTagsFromParams(array $params) : array
295389
return $tags;
296390
}
297391

392+
/**
393+
* @param array $params
394+
*
395+
* @return int
396+
*
397+
* @throws InvalidDescriptorArgumentException
398+
*/
298399
private function extractPriorityFromParams(array $params) : int
299400
{
300401
$priority = $params['priority'] ?? 0;
402+
301403
if (!is_int($priority)) {
302404
throw new InvalidDescriptorArgumentException('@Route.priority must contain an integer.');
303405
}

0 commit comments

Comments
 (0)