@@ -126,11 +126,9 @@ public function getPath()
126
126
*
127
127
* This method implements a fluent interface.
128
128
*
129
- * @param string $pattern The path pattern
130
- *
131
129
* @return $this
132
130
*/
133
- public function setPath ($ pattern )
131
+ public function setPath (string $ pattern )
134
132
{
135
133
if (false !== strpbrk ($ pattern , '?< ' )) {
136
134
$ pattern = preg_replace_callback ('#\{(\w++)(<.*?>)?(\?[^\}]*+)?\}# ' , function ($ m ) {
@@ -168,11 +166,9 @@ public function getHost()
168
166
*
169
167
* This method implements a fluent interface.
170
168
*
171
- * @param string $pattern The host pattern
172
- *
173
169
* @return $this
174
170
*/
175
- public function setHost ($ pattern )
171
+ public function setHost (? string $ pattern )
176
172
{
177
173
$ this ->host = (string ) $ pattern ;
178
174
$ this ->compiled = null ;
@@ -212,11 +208,9 @@ public function setSchemes($schemes)
212
208
/**
213
209
* Checks if a scheme requirement has been set.
214
210
*
215
- * @param string $scheme
216
- *
217
211
* @return bool true if the scheme requirement exists, otherwise false
218
212
*/
219
- public function hasScheme ($ scheme )
213
+ public function hasScheme (string $ scheme )
220
214
{
221
215
return \in_array (strtolower ($ scheme ), $ this ->schemes , true );
222
216
}
@@ -302,12 +296,11 @@ public function addOptions(array $options)
302
296
*
303
297
* This method implements a fluent interface.
304
298
*
305
- * @param string $name An option name
306
- * @param mixed $value The option value
299
+ * @param mixed $value The option value
307
300
*
308
301
* @return $this
309
302
*/
310
- public function setOption ($ name , $ value )
303
+ public function setOption (string $ name , $ value )
311
304
{
312
305
$ this ->options [$ name ] = $ value ;
313
306
$ this ->compiled = null ;
@@ -318,23 +311,19 @@ public function setOption($name, $value)
318
311
/**
319
312
* Get an option value.
320
313
*
321
- * @param string $name An option name
322
- *
323
314
* @return mixed The option value or null when not given
324
315
*/
325
- public function getOption ($ name )
316
+ public function getOption (string $ name )
326
317
{
327
318
return isset ($ this ->options [$ name ]) ? $ this ->options [$ name ] : null ;
328
319
}
329
320
330
321
/**
331
322
* Checks if an option has been set.
332
323
*
333
- * @param string $name An option name
334
- *
335
324
* @return bool true if the option is set, false otherwise
336
325
*/
337
- public function hasOption ($ name )
326
+ public function hasOption (string $ name )
338
327
{
339
328
return \array_key_exists ($ name , $ this ->options );
340
329
}
@@ -387,36 +376,31 @@ public function addDefaults(array $defaults)
387
376
/**
388
377
* Gets a default value.
389
378
*
390
- * @param string $name A variable name
391
- *
392
379
* @return mixed The default value or null when not given
393
380
*/
394
- public function getDefault ($ name )
381
+ public function getDefault (string $ name )
395
382
{
396
383
return isset ($ this ->defaults [$ name ]) ? $ this ->defaults [$ name ] : null ;
397
384
}
398
385
399
386
/**
400
387
* Checks if a default value is set for the given variable.
401
388
*
402
- * @param string $name A variable name
403
- *
404
389
* @return bool true if the default value is set, false otherwise
405
390
*/
406
- public function hasDefault ($ name )
391
+ public function hasDefault (string $ name )
407
392
{
408
393
return \array_key_exists ($ name , $ this ->defaults );
409
394
}
410
395
411
396
/**
412
397
* Sets a default value.
413
398
*
414
- * @param string $name A variable name
415
- * @param mixed $default The default value
399
+ * @param mixed $default The default value
416
400
*
417
401
* @return $this
418
402
*/
419
- public function setDefault ($ name , $ default )
403
+ public function setDefault (string $ name , $ default )
420
404
{
421
405
$ this ->defaults [$ name ] = $ default ;
422
406
$ this ->compiled = null ;
@@ -472,36 +456,29 @@ public function addRequirements(array $requirements)
472
456
/**
473
457
* Returns the requirement for the given key.
474
458
*
475
- * @param string $key The key
476
- *
477
459
* @return string|null The regex or null when not given
478
460
*/
479
- public function getRequirement ($ key )
461
+ public function getRequirement (string $ key )
480
462
{
481
463
return isset ($ this ->requirements [$ key ]) ? $ this ->requirements [$ key ] : null ;
482
464
}
483
465
484
466
/**
485
467
* Checks if a requirement is set for the given key.
486
468
*
487
- * @param string $key A variable name
488
- *
489
469
* @return bool true if a requirement is specified, false otherwise
490
470
*/
491
- public function hasRequirement ($ key )
471
+ public function hasRequirement (string $ key )
492
472
{
493
473
return \array_key_exists ($ key , $ this ->requirements );
494
474
}
495
475
496
476
/**
497
477
* Sets a requirement for the given key.
498
478
*
499
- * @param string $key The key
500
- * @param string $regex The regex
501
- *
502
479
* @return $this
503
480
*/
504
- public function setRequirement ($ key , $ regex )
481
+ public function setRequirement (string $ key , string $ regex )
505
482
{
506
483
$ this ->requirements [$ key ] = $ this ->sanitizeRequirement ($ key , $ regex );
507
484
$ this ->compiled = null ;
@@ -524,11 +501,9 @@ public function getCondition()
524
501
*
525
502
* This method implements a fluent interface.
526
503
*
527
- * @param string $condition The condition
528
- *
529
504
* @return $this
530
505
*/
531
- public function setCondition ($ condition )
506
+ public function setCondition (? string $ condition )
532
507
{
533
508
$ this ->condition = (string ) $ condition ;
534
509
$ this ->compiled = null ;
@@ -557,12 +532,8 @@ public function compile()
557
532
return $ this ->compiled = $ class ::compile ($ this );
558
533
}
559
534
560
- private function sanitizeRequirement ($ key , $ regex )
535
+ private function sanitizeRequirement (string $ key , string $ regex )
561
536
{
562
- if (!\is_string ($ regex )) {
563
- throw new \InvalidArgumentException (sprintf ('Routing requirement for "%s" must be a string. ' , $ key ));
564
- }
565
-
566
537
if ('' !== $ regex && '^ ' === $ regex [0 ]) {
567
538
$ regex = (string ) substr ($ regex , 1 ); // returns false for a single character
568
539
}
0 commit comments