8000 [Console] [5.0] Add all type-hint · symfony/symfony@c11267f · GitHub
[go: up one dir, main page]

Skip to content

Commit c11267f

Browse files
committed
[Console] [5.0] Add all type-hint
1 parent 8fb4741 commit c11267f

34 files changed

+171
-300
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ public function isAutoExitEnabled()
365365
*
366366
* @param bool $boolean Whether to automatically exit after a command execution or not
367367
*/
368-
public function setAutoExit($boolean)
368+
public function setAutoExit(bool $boolean)
369369
{
370-
$this->autoExit = (bool) $boolean;
370+
$this->autoExit = $boolean;
371371
}
372372

373373
/**
@@ -385,7 +385,7 @@ public function getName()
385385
*
386386
* @param string $name The application name
387387
*/
388-
public function setName($name)
388+
public function setName(string $name)
389389
{
390390
$this->name = $name;
391391
}
@@ -405,7 +405,7 @@ public function getVersion()
405405
*
406406
* @param string $version The application version
407407
*/
408-
public function setVersion($version)
408+
public function setVersion(string $version)
409409
{
410410
$this->version = $version;
411411
}
@@ -435,7 +435,7 @@ public function getLongVersion()
435435
*
436436
* @return Command The newly created command
437437
*/
438-
public function register($name)
438+
public function register(string $name)
439439
{
440440
return $this->add(new Command($name));
441441
}
@@ -500,7 +500,7 @@ public function add(Command $command)
500500
*
501501
* @throws CommandNotFoundException When given command name does not exist
502502
*/
503-
public function get($name)
503+
public function get(string $name)
504504
{
505505
$this->init();
506506

@@ -529,7 +529,7 @@ public function get($name)
529529
*
530530
* @return bool true if the command exists, false otherwise
531531
*/
532-
public function has($name)
532+
public function has(string $name)
533533
{
534534
$this->init();
535535

@@ -566,7 +566,7 @@ public function getNamespaces()
566566
*
567567
* @throws NamespaceNotFoundException When namespace is incorrect or ambiguous
568568
*/
569-
public function findNamespace($namespace)
569+
public function findNamespace(string $namespace)
570570
{
571571
$allNamespaces = $this->getNamespaces();
572572
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $namespace);
@@ -608,7 +608,7 @@ public function findNamespace($namespace)
608608
*
609609
* @throws CommandNotFoundException When command name is incorrect or ambiguous
610610
*/
611-
public function find($name)
611+
public function find(string $name)
612612
{
613613
$this->init();
614614

@@ -698,7 +698,7 @@ public function find($name)
698698
*
699699
* @return Command[] An array of Command instances
700700
*/
701-
public function all($namespace = null)
701+
public function all(string $namespace = null)
702702
{
703703
$this->init();
704704

@@ -742,7 +742,7 @@ public function all($namespace = null)
742742
*
743743
* @return array An array of abbreviations
744744
*/
745-
public static function getAbbreviations($names)
745+
public static function getAbbreviations(array $names)
746746
{
747747
$abbrevs = [];
748748
foreach ($names as $name) {
@@ -1039,7 +1039,7 @@ private function getAbbreviationSuggestions($abbrevs)
10391039
*
10401040
* @return string The namespace of the command
10411041
*/
1042-
public function extractNamespace($name, $limit = null)
1042+
public function extractNamespace(string $name, string $limit = null)
10431043
{
10441044
$parts = explode(':', $name);
10451045
array_pop($parts);
@@ -1056,7 +1056,7 @@ public function extractNamespace($name, $limit = null)
10561056
*
10571057
* @return string[] A sorted array of similar string
10581058
*/
1059-
private function findAlternatives($name, $collection)
1059+
private function findAlternatives(string $name, iterable $collection)
10601060
{
10611061
$threshold = 1e3;
10621062
$alternatives = [];
@@ -1106,7 +1106,7 @@ private function findAlternatives($name, $collection)
11061106
*
11071107
* @return self
11081108
*/
1109-
public function setDefaultCommand($commandName, $isSingleCommand = false)
1109+
public function setDefaultCommand(string $commandName, bool $isSingleCommand = false)
11101110
{
11111111
$this->defaultCommand = $commandName;
11121112

@@ -1165,7 +1165,7 @@ private function splitStringByWidth($string, $width)
11651165
*
11661166
* @return string[] The namespaces of the command
11671167
*/
1168-
private function extractAllNamespaces($name)
1168+
private function extractAllNamespaces(string $name)
11691169
{
11701170
// -1 as third argument is needed to skip the command short name when exploding
11711171
$parts = explode(':', $name, -1);

src/Symfony/Component/Console/Command/Command.php

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public function setCode(callable $code)
293293
*
294294
* @param bool $mergeArgs Whether to merge or not the Application definition arguments to Command definition arguments
295295
*/
296-
public function mergeApplicationDefinition($mergeArgs = true)
296+
public function mergeApplicationDefinition(bool $mergeArgs = true)
297297
{
298298
if (null === $this->application || (true === $this->applicationDefinitionMerged && ($this->applicationDefinitionMergedWithArgs || !$mergeArgs))) {
299299
return;
@@ -360,16 +360,13 @@ public function getNativeDefinition()
360360
/**
361361
* Adds an argument.
362362
*
363-
* @param string $name The argument name
364-
* @param int|null $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
365-
* @param string $description A description text
366363
* @param string|string[]|null $default The default value (for InputArgument::OPTIONAL mode only)
367364
*
368365
* @throws InvalidArgumentException When argument mode is not valid
369366
*
370367
* @return $this
371368
*/
372-
public function addArgument($name, $mode = null, $description = '', $default = null)
369+
public function addArgument(string $name, int $mode = null, string $description = '', $default = null)
373370
{
374371
$this->definition->addArgument(new InputArgument($name, $mode, $description, $default));
375372

@@ -389,7 +386,7 @@ public function addArgument($name, $mode = null, $description = '', $default = n
389386
*
390387
* @return $this
391388
*/
392-
public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null)
389+
public function addOption(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null)
393390
{
394391
$this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default));
395392

@@ -410,7 +407,7 @@ public function addOption($name, $shortcut = null, $mode = null, $description =
410407
*
411408
* @throws InvalidArgumentException When the name is invalid
412409
*/
413-
public function setName($name)
410+
public function setName(string $name)
414411
{
415412
$this->validateName($name);
416413

@@ -431,7 +428,7 @@ public function setName($name)
431428
*
432429
* @return $this
433430
*/
434-
public function setProcessTitle($title)
431+
public function setProcessTitle(string $title)
435432
{
436433
$this->processTitle = $title;
437434

@@ -453,9 +450,9 @@ public function getName()
453450
*
454451
* @return Command The current instance
455452
*/
456-
public function setHidden($hidden)
453+
public function setHidden(bool $hidden)
457454
{
458-
$this->hidden = (bool) $hidden;
455+
$this->hidden = $hidden;
459456

460457
return $this;
461458
}
@@ -475,7 +472,7 @@ public function isHidden()
475472
*
476473
* @return $this
477474
*/
478-
public function setDescription($description)
475+
public function setDescription(string $description)
479476
{
480477
$this->description = $description;
481478

@@ -499,7 +496,7 @@ public function getDescription()
499496
*
500497
* @return $this
501498
*/
502-
public function setHelp($help)
499+
public function setHelp(string $help)
503500
{
504501
$this->help = $help;
505502

@@ -548,12 +545,8 @@ public function getProcessedHelp()
548545
*
549546
* @throws InvalidArgumentException When an alias is invalid
550547
*/
551-
public function setAliases($aliases)
548+
public function setAliases(array $aliases)
552549
{
553-
if (!\is_array($aliases) && !$aliases instanceof \Traversable) {
554-
throw new InvalidArgumentException('$aliases must be an array or an instance of \Traversable');
555-
}
556-
557550
foreach ($aliases as $alias) {
558551
$this->validateName($alias);
559552
}
@@ -580,7 +573,7 @@ public function getAliases()
580573
*
581574
* @return string The synopsis
582575
*/
583-
public function getSynopsis($short = false)
576+
public function getSynopsis(bool $short = false)
584577
{
585578
$key = $short ? 'short' : 'long';
586579

@@ -598,7 +591,7 @@ public function getSynopsis($short = false)
598591
*
599592
* @return $this
600593
*/
601-
public function addUsage($usage)
594+
public function addUsage(string $usage)
602595
{
603596
if (0 !== strpos($usage, $this->name)) {
604597
$usage = sprintf('%s %s', $this->name, $usage);
@@ -629,7 +622,7 @@ public function getUsages()
629622
* @throws LogicException if no HelperSet is defined
630623
* @throws InvalidArgumentException if the helper is not defined
631624
*/
632-
public function getHelper($name)
625+
public function getHelper(string $name)
633626
{
634627
if (null === $this->helperSet) {
635628
throw new LogicException(sprintf('Cannot retrieve helper "%s" because there is no HelperSet defined. Did you forget to add your command to the application or to set the application on the command using the setApplication() method? You can also set the HelperSet directly using the setHelperSet() method.', $name));

src/Symfony/Component/Console/Command/LockableTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ trait LockableTrait
3232
*
3333
* @return bool
3434
*/
35-
private function lock($name = null, $blocking = false)
35+
private function lock(?string $name = null, bool $blocking = false)
3636
{
3737
if (!class_exists(SemaphoreStore::class)) {
3838
throw new LogicException('To enable the locking feature you must install the symfony/lock component.');

src/Symfony/Component/Console/CommandLoader/CommandLoaderInterface.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,18 @@ interface CommandLoaderInterface
1313
/**
1414
* Loads a command.
1515
*
16-
* @param string $name
17-
*
1816
* @return Command
1917
*
2018
* @throws CommandNotFoundException
2119
*/
22-
public function get($name);
20+
public function get(string $name);
2321

2422
/**
2523
* Checks if a command exists.
2624
*
27-
* @param string $name
28-
*
2925
* @return bool
3026
*/
31-
public function has($name);
27+
public function has(string $name);
3228

3329
/**
3430
* @return string[] All registered command names

src/Symfony/Component/Console/CommandLoader/ContainerCommandLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(ContainerInterface $container, array $commandMap)
2828
/**
2929
* {@inheritdoc}
3030
*/
31-
public function get($name)
31+
public function get(string $name)
3232
{
3333
if (!$this->has($name)) {
3434
throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
@@ -40,7 +40,7 @@ public function get($name)
4040
/**
4141
* {@inheritdoc}
4242
*/
43-
public function has($name)
43+
public function has(string $name)
4444
{
4545
return isset($this->commandMap[$name]) && $this->container->has($this->commandMap[$name]);
4646
}

src/Symfony/Component/Console/CommandLoader/FactoryCommandLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public function __construct(array $factories)
3333
/**
3434
* {@inheritdoc}
3535
*/
36-
public function has($name)
36+
public function has(string $name)
3737
{
3838
return isset($this->factories[$name]);
3939
}
4040

4141
/**
4242
* {@inheritdoc}
4343
*/
44-
public function get($name)
44+
public function get(string $name)
4545
{
4646
if (!isset($this->factories[$name])) {
4747
throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));

src/Symfony/Component/Console/Descriptor/ApplicationDescription.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function getCommands()
8181
*
8282
* @throws CommandNotFoundException
8383
*/
84-
public function getCommand($name)
84+
public function getCommand(string $name)
8585
{
8686
if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
8787
throw new CommandNotFoundException(sprintf('Command %s does not exist.', $name));

src/Symfony/Component/Console/Descriptor/Descriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function describe(OutputInterface $output, $object, array $options = [])
6565
* @param string $content
6666
* @param bool $decorated
6767
*/
68-
protected function write($content, $decorated = false)
68+
protected function write(string $content, bool $decorated = false)
6969
{
7070
$this->output->write($content, false, $decorated ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW);
7171
}

src/Symfony/Component/Console/Descriptor/XmlDescriptor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function getCommandDocument(Command $command)
8686
*
8787
* @return \DOMDocument
8888
*/
89-
public function getApplicationDocument(Application $application, $namespace = null)
89+
public function getApplicationDocument(Application $application, string $namespace = null)
9090
{
9191
$dom = new \DOMDocument('1.0', 'UTF-8');
9292
$dom->appendChild($rootXml = $dom->createElement('symfony'));

0 commit comments

Comments
 (0)
0