Skip to content

Commit 5414d2a

Browse files
committed
minor changes
1 parent 91c4a5b commit 5414d2a

File tree

1 file changed

+37
-41
lines changed

1 file changed

+37
-41
lines changed

src/Annotation/Route.php

Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,13 @@ public function getPriority() : int
216216
*/
217217
private function extractNameFromParams(array $params) : string
218218
{
219-
if (!isset($params['name']) || '' === $params['name'] || !is_string($params['name'])) {
219+
$name = $params['name'] ?? '';
220+
221+
if ('' === $name || !is_string($name)) {
220222
throw new InvalidDescriptorArgumentException('@Route.name must contain a non-empty string.');
221223
}
222224

223-
return $params['name'];
225+
return $name;
224226
}
225227

226228
/**
@@ -232,11 +234,13 @@ private function extractNameFromParams(array $params) : string
232234
*/
233235
private function extractHostFromParams(array $params) : ?string
234236
{
235-
if (isset($params['host']) && ('' === $params['host'] || !is_string($params['host']))) {
237+
$host = $params['host'] ?? null;
238+
239+
if (isset($host) && ('' === $host || !is_string($host))) {
236240
throw new InvalidDescriptorArgumentException('@Route.host must contain a non-empty string.');
237241
}
238242

239-
return $params['host'] ?? null;
243+
return $host;
240244
}
241245

242246
/**
@@ -248,11 +252,13 @@ private function extractHostFromParams(array $params) : ?string
248252
*/
249253
private function extractPathFromParams(array $params) : string
250254
{
251-
if (!isset($params['path']) || '' === $params['path'] || !is_string($params['path'])) {
255+
$path = $params['path'] ?? '';
256+
257+
if ('' === $path || !is_string($path)) {
252258
throw new InvalidDescriptorArgumentException('@Route.path must contain a non-empty string.');
253259
}
254260

255-
return $params['path'];
261+
return $path;
256262
}
257263

258264
/**
@@ -264,17 +270,19 @@ private function extractPathFromParams(array $params) : string
264270
*/
265271
private function extractMethodsFromParams(array $params) : array
266272
{
267-
if (!isset($params['methods']) || [] === $params['methods'] || !is_array($params['methods'])) {
273+
$methods = $params['methods'] ?? [];
274+
275+
if ([] === $methods || !is_array($methods)) {
268276
throw new InvalidDescriptorArgumentException('@Route.methods must contain a non-empty array.');
269277
}
270278

271-
foreach ($params['methods'] as $value) {
279+
foreach ($methods as $value) {
272280
if ('' === $value || !is_string($value)) {
273281
throw new InvalidDescriptorArgumentException('@Route.methods must contain non-empty strings.');
274282
}
275283
}
276284

277-
return $params['methods'];
285+
return $methods;
278286
}
279287

280288
/**
@@ -286,23 +294,21 @@ private function extractMethodsFromParams(array $params) : array
286294
*/
287295
private function extractMiddlewaresFromParams(array $params) : array
288296
{
289-
if (!isset($params['middlewares'])) {
290-
return [];
291-
}
297+
$middlewares = $params['middlewares'] ?? [];
292298

293-
if (!is_array($params['middlewares'])) {
299+
if (!is_array($middlewares)) {
294300
throw new InvalidDescriptorArgumentException('@Route.middlewares must contain an array.');
295301
}
296302

297-
foreach ($params['middlewares'] as $value) {
303+
foreach ($middlewares as $value) {
298304
if ('' === $value || !is_string($value) || !is_subclass_of($value, MiddlewareInterface::class)) {
299305
throw new InvalidDescriptorArgumentException(
300306
'@Route.middlewares must contain the class names of existing middlewares.'
301307
);
302308
}
303309
}
304310

305-
return $params['middlewares'];
311+
return $middlewares;
306312
}
307313

308314
/**
@@ -314,15 +320,13 @@ private function extractMiddlewaresFromParams(array $params) : array
314320
*/
315321
private function extractAttributesFromParams(array $params) : array
316322
{
317-
if (!isset($params['attributes'])) {
318-
return [];
319-
}
323+
$attributes = $params['attributes'] ?? [];
320324

321-
if (!is_array($params['attributes'])) {
325+
if (!is_array($attributes)) {
322326
throw new InvalidDescriptorArgumentException('@Route.attributes must contain an array.');
323327
}
324328

325-
return $params['attributes'];
329+
return $attributes;
326330
}
327331

328332
/**
@@ -334,15 +338,13 @@ private function extractAttributesFromParams(array $params) : array
334338
*/
335339
private function extractSummaryFromParams(array $params) : string
336340
{
337-
if (!isset($params['summary'])) {
338-
return '';
339-
}
341+
$summary = $params['summary'] ?? '';
340342

341-
if (!is_string($params['summary'])) {
343+
if (!is_string($summary)) {
342344
throw new InvalidDescriptorArgumentException('@Route.summary must contain a string.');
343345
}
344346

345-
return $params['summary'];
347+
return $summary;
346348
}
347349

348350
/**
@@ -354,15 +356,13 @@ private function extractSummaryFromParams(array $params) : string
354356
*/
355357
private function extractDescriptionFromParams(array $params) : string
356358
{
357-
if (!isset($params['description'])) {
358-
return '';
359-
}
359+
$description = $params['description'] ?? '';
360360

361-
if (!is_string($params['description'])) {
361+
if (!is_string($description)) {
362362
throw new InvalidDescriptorArgumentException('@Route.description must contain a string.');
363363
}
364364

365-
return $params['description'];
365+
return $description;
366366
}
367367

368368
/**
@@ -374,21 +374,19 @@ private function extractDescriptionFromParams(array $params) : string
374374
*/
375375
private function extractTagsFromParams(array $params) : array
376376
{
377-
if (!isset($params['tags'])) {
378-
return [];
379-
}
377+
$tags = $params['tags'] ?? [];
380378

381-
if (!is_array($params['tags'])) {
379+
if (!is_array($tags)) {
382380
throw new InvalidDescriptorArgumentException('@Route.tags must contain an array.');
383381
}
384382

385-
foreach ($params['tags'] as $value) {
383+
foreach ($tags as $value) {
386384
if ('' === $value || !is_string($value)) {
387385
throw new InvalidDescriptorArgumentException('@Route.tags must contain non-empty strings.');
388386
}
389387
}
390388

391-
return $params['tags'];
389+
return $tags;
392390
}
393391

394392
/**
@@ -400,14 +398,12 @@ private function extractTagsFromParams(array $params) : array
400398
*/
401399
private function extractPriorityFromParams(array $params) : int
402400
{
403-
if (!isset($params['priority'])) {
404-
return 0;
405-
}
401+
$priority = $params['priority'] ?? 0;
406402

407-
if (!is_int($params['priority'])) {
403+
if (!is_int($priority)) {
408404
throw new InvalidDescriptorArgumentException('@Route.priority must contain an integer.');
409405
}
410406

411-
return $params['priority'];
407+
return $priority;
412408
}
413409
}

0 commit comments

Comments
 (0)