41
41
use Symfony \Component \Console \Output \ConsoleOutputInterface ;
42
42
use Symfony \Component \Console \Output \OutputInterface ;
43
43
use Symfony \Component \Console \Style \SymfonyStyle ;
44
- use Symfony \Contracts \EventDispatcher \EventDispatcherInterface ;
45
44
use Symfony \Component \ErrorCatcher \ErrorHandler ;
46
45
use Symfony \Component \ErrorCatcher \Exception \FatalThrowableError ;
46
+ use Symfony \Contracts \EventDispatcher \EventDispatcherInterface ;
47
47
48
48
/**
49
49
* An Application is the container for a collection of commands.
@@ -78,10 +78,6 @@ class Application
78
78
private $ singleCommand = false ;
79
79
private $ initialized ;
80
80
81
- /**
82
- * @param string $name The name of the application
83
- * @param string $version The version of the application
84
- */
85
81
public function __construct (string $ name = 'UNKNOWN ' , string $ version = 'UNKNOWN ' )
86
82
{
87
83
$ this ->name = $ name ;
@@ -342,12 +338,10 @@ public function areExceptionsCaught()
342
338
343
339
/**
344
340
* Sets whether to catch exceptions or not during commands execution.
345
- *
346
- * @param bool $boolean Whether to catch exceptions or not during commands execution
347
341
*/
348
- public function setCatchExceptions ($ boolean )
342
+ public function setCatchExceptions (bool $ boolean )
349
343
{
350
- $ this ->catchExceptions = ( bool ) $ boolean ;
344
+ $ this ->catchExceptions = $ boolean ;
351
345
}
352
346
353
347
/**
@@ -362,12 +356,10 @@ public function isAutoExitEnabled()
362
356
363
357
/**
364
358
* Sets whether to automatically exit after a command execution or not.
365
- *
366
- * @param bool $boolean Whether to automatically exit after a command execution or not
367
359
*/
368
- public function setAutoExit ($ boolean )
360
+ public function setAutoExit (bool $ boolean )
369
361
{
370
- $ this ->autoExit = ( bool ) $ boolean ;
362
+ $ this ->autoExit = $ boolean ;
371
363
}
372
364
373
365
/**
@@ -382,10 +374,8 @@ public function getName()
382
374
383
375
/**
384
376
* Sets the application name.
385
- *
386
- * @param string $name The application name
387
- */
388
- public function setName ($ name )
377
+ **/
378
+ public function setName (string $ name )
389
379
{
390
380
$ this ->name = $ name ;
391
381
}
@@ -402,10 +392,8 @@ public function getVersion()
402
392
403
393
/**
404
394
* Sets the application version.
405
- *
406
- * @param string $version The application version
407
395
*/
408
- public function setVersion ($ version )
396
+ public function setVersion (string $ version )
409
397
{
410
398
$ this ->version = $ version ;
411
399
}
@@ -431,11 +419,9 @@ public function getLongVersion()
431
419
/**
432
420
* Registers a new command.
433
421
*
434
- * @param string $name The command name
435
- *
436
422
* @return Command The newly created command
437
423
*/
438
- public function register ($ name )
424
+ public function register (string $ name )
439
425
{
440
426
return $ this ->add (new Command ($ name ));
441
427
}
@@ -494,13 +480,11 @@ public function add(Command $command)
494
480
/**
495
481
* Returns a registered command by name or alias.
496
482
*
497
- * @param string $name The command name or alias
498
- *
499
483
* @return Command A Command object
500
484
*
501
485
* @throws CommandNotFoundException When given command name does not exist
502
486
*/
503
- public function get ($ name )
487
+ public function get (string $ name )
504
488
{
505
489
$ this ->init ();
506
490
@@ -525,11 +509,9 @@ public function get($name)
525
509
/**
526
510
* Returns true if the command exists, false otherwise.
527
511
*
528
- * @param string $name The command name or alias
529
- *
530
512
* @return bool true if the command exists, false otherwise
531
513
*/
532
- public function has ($ name )
514
+ public function has (string $ name )
533
515
{
534
516
$ this ->init ();
535
517
@@ -560,13 +542,11 @@ public function getNamespaces()
560
542
/**
561
543
* Finds a registered namespace by a name or an abbreviation.
562
544
*
563
- * @param string $namespace A namespace or abbreviation to search for
564
- *
565
545
* @return string A registered namespace
566
546
*
567
547
* @throws NamespaceNotFoundException When namespace is incorrect or ambiguous
568
548
*/
569
- public function findNamespace ($ namespace )
549
+ public function findNamespace (string $ namespace )
570
550
{
571
551
$ allNamespaces = $ this ->getNamespaces ();
572
552
$ expr = preg_replace_callback ('{([^:]+|)} ' , function ($ matches ) { return preg_quote ($ matches [1 ]).'[^:]* ' ; }, $ namespace );
@@ -602,13 +582,11 @@ public function findNamespace($namespace)
602
582
* Contrary to get, this command tries to find the best
603
583
* match if you give it an abbreviation of a name or alias.
604
584
*
605
- * @param string $name A command name or a command alias
606
- *
607
585
* @return Command A Command instance
608
586
*
609
587
* @throws CommandNotFoundException When command name is incorrect or ambiguous
610
588
*/
611
- public function find ($ name )
589
+ public function find (string $ name )
612
590
{
613
591
$ this ->init ();
614
592
@@ -694,11 +672,9 @@ public function find($name)
694
672
*
695
673
* The array keys are the full names and the values the command instances.
696
674
*
697
- * @param string $namespace A namespace name
698
- *
699
675
* @return Command[] An array of Command instances
700
676
*/
701
- public function all ($ namespace = null )
677
+ public function all (string $ namespace = null )
702
678
{
703
679
$ this ->init ();
704
680
@@ -738,11 +714,9 @@ public function all($namespace = null)
738
714
/**
739
715
* Returns an array of possible abbreviations given a set of names.
740
716
*
741
- * @param array $names An array of names
742
- *
743
- * @return array An array of abbreviations
717
+ * @return string[][] An array of abbreviations
744
718
*/
745
- public static function getAbbreviations ($ names )
719
+ public static function getAbbreviations (array $ names )
746
720
{
747
721
$ abbrevs = [];
748
722
foreach ($ names as $ name ) {
@@ -1020,11 +994,9 @@ protected function getDefaultHelperSet()
1020
994
/**
1021
995
* Returns abbreviated suggestions in string format.
1022
996
*
1023
- * @param array $abbrevs Abbreviated suggestions to convert
1024
- *
1025
997
* @return string A formatted string of abbreviated suggestions
1026
998
*/
1027
- private function getAbbreviationSuggestions ($ abbrevs )
999
+ private function getAbbreviationSuggestions (array $ abbrevs )
1028
1000
{
1029
1001
return ' ' .implode ("\n " , $ abbrevs );
1030
1002
}
@@ -1034,12 +1006,9 @@ private function getAbbreviationSuggestions($abbrevs)
1034
1006
*
1035
1007
* This method is not part of public API and should not be used directly.
1036
1008
*
1037
- * @param string $name The full name of the command
1038
- * @param string $limit The maximum number of parts of the namespace
1039
- *
1040
1009
* @return string The namespace of the command
1041
1010
*/
1042
- public function extractNamespace ($ name , $ limit = null )
1011
+ public function extractNamespace (string $ name , int $ limit = null )
1043
1012
{
1044
1013
$ parts = explode (': ' , $ name );
1045
1014
array_pop ($ parts );
@@ -1051,12 +1020,9 @@ public function extractNamespace($name, $limit = null)
1051
1020
* Finds alternative of $name among $collection,
1052
1021
* if nothing is found in $collection, try in $abbrevs.
1053
1022
*
1054
- * @param string $name The string
1055
- * @param iterable $collection The collection
1056
- *
1057
1023
* @return string[] A sorted array of similar string
1058
1024
*/
1059
- private function findAlternatives ($ name , $ collection )
1025
+ private function findAlternatives (string $ name , iterable $ collection )
1060
1026
{
1061
1027
$ threshold = 1e3 ;
1062
1028
$ alternatives = [];
@@ -1101,12 +1067,9 @@ private function findAlternatives($name, $collection)
1101
1067
/**
1102
1068
* Sets the default Command name.
1103
1069
*
1104
- * @param string $commandName The Command name
1105
- * @param bool $isSingleCommand Set to true if there is only one command in this application
1106
- *
1107
1070
* @return self
1108
1071
*/
1109
- public function setDefaultCommand ($ commandName , $ isSingleCommand = false )
1072
+ public function setDefaultCommand (string $ commandName , bool $ isSingleCommand = false )
1110
1073
{
1111
1074
$ this ->defaultCommand = $ commandName ;
1112
1075
@@ -1161,11 +1124,9 @@ private function splitStringByWidth($string, $width)
1161
1124
/**
1162
1125
* Returns all namespaces of the command name.
1163
1126
*
1164
- * @param string $name The full name of the command
1165
- *
1166
1127
* @return string[] The namespaces of the command
1167
1128
*/
1168
- private function extractAllNamespaces ($ name )
1129
+ private function extractAllNamespaces (string $ name )
1169
1130
{
1170
1131
// -1 as third argument is needed to skip the command short name when exploding
1171
1132
$ parts = explode (': ' , $ name , -1 );
0 commit comments