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

Skip to content

Commit 72c85c5

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

38 files changed

+201
-320
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
use Symfony\Component\Console\Output\ConsoleOutputInterface;
4242
use Symfony\Component\Console\Output\OutputInterface;
4343
use Symfony\Component\Console\Style\SymfonyStyle;
44-
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
4544
use Symfony\Component\ErrorCatcher\ErrorHandler;
4645
use Symfony\Component\ErrorCatcher\Exception\FatalThrowableError;
46+
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
4747

4848
/**
4949
* An Application is the container for a collection of commands.
@@ -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) {
@@ -1034,12 +1034,9 @@ private function getAbbreviationSuggestions($abbrevs)
10341034
*
10351035
* This method is not part of public API and should not be used directly.
10361036
*
1037-
* @param string $name The full name of the command
1038-
* @param string $limit The maximum number of parts of the namespace
1039-
*
10401037
* @return string The namespace of the command
10411038
*/
1042-
public function extractNamespace($name, $limit = null)
1039+
public function extractNamespace(string $name, int $limit = null)
10431040
{
10441041
$parts = explode(':', $name);
10451042
array_pop($parts);
@@ -1056,7 +1053,7 @@ public function extractNamespace($name, $limit = null)
10561053
*
10571054
* @return string[] A sorted array of similar string
10581055
*/
1059-
private function findAlternatives($name, $collection)
1056+
private function findAlternatives(string $name, iterable $collection)
10601057
{
10611058
$threshold = 1e3;
10621059
$alternatives = [];
@@ -1106,7 +1103,7 @@ private function findAlternatives($name, $collection)
11061103
*
11071104
* @return self
11081105
*/
1109-
public function setDefaultCommand($commandName, $isSingleCommand = false)
1106+
public function setDefaultCommand(string $commandName, bool $isSingleCommand = false)
11101107
{
11111108
$this->defaultCommand = $commandName;
11121109

@@ -1165,7 +1162,7 @@ private function splitStringByWidth($string, $width)
11651162
*
11661163
* @return string[] The namespaces of the command
11671164
*/
1168-
private function extractAllNamespaces($name)
1165+
private function extractAllNamespaces(string $name)
11691166
{
11701167
// -1 as third argument is needed to skip the command short name when exploding
11711168
$parts = explode(':', $name, -1);

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

Lines changed: 14 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 mergeApplicationDef 10000 inition($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,14 @@ public function getNativeDefinition()
360360
/**
361361
* Adds an argument.
362362
*
363-
* @param string $name The argument name
364363
* @param int|null $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
365-
* @param string $description A description text
366-
* @param string|string[]|null $default The default value (for InputArgument::OPTIONAL mode only)
364+
* @param string|string[]|null $default The default value (for InputArgument::OPTIONAL mode only)
367365
*
368366
* @throws InvalidArgumentException When argument mode is not valid
369367
*
370368
* @return $this
371369
*/
372-
public function addArgument($name, $mode = null, $description = '', $default = null)
370+
public function addArgument(string $name, int $mode = null, string $description = '', $default = null)
373371
{
374372
$this->definition->addArgument(new InputArgument($name, $mode, $description, $default));
375373

@@ -389,7 +387,7 @@ public function addArgument($name, $mode = null, $description = '', $default = n
389387
*
390388
* @return $this
391389
*/
392-
public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null)
390+
public function addOption(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null)
393391
{
394392
$this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default));
395393

@@ -410,7 +408,7 @@ public function addOption($name, $shortcut = null, $mode = null, $description =
410408
*
411409
* @throws InvalidArgumentException When the name is invalid
412410
*/
413-
public function setName($name)
411+
public function setName(string $name)
414412
{
415413
$this->validateName($name);
416414

@@ -431,7 +429,7 @@ public function setName($name)
431429
*
432430
* @return $this
433431
*/
434-
public function setProcessTitle($title)
432+
public function setProcessTitle(string $title)
435433
{
436434
$this->processTitle = $title;
437435

@@ -453,9 +451,9 @@ public function getName()
453451
*
454452
* @return Command The current instance
455453
*/
456-
public function setHidden($hidden)
454+
public function setHidden(bool $hidden)
457455
{
458-
$this->hidden = (bool) $hidden;
456+
$this->hidden = $hidden;
459457

460458
return $this;
461459
}
@@ -475,7 +473,7 @@ public function isHidden()
475473
*
476474
* @return $this
477475
*/
478-
public function setDescription($description)
476+
public function setDescription(string $description)
479477
{
480478
$this->description = $description;
481479

@@ -499,7 +497,7 @@ public function getDescription()
499497
*
500498
* @return $this
501499
*/
502-
public function setHelp($help)
500+
public function setHelp(string $help)
503501
{
504502
$this->help = $help;
505503

@@ -548,12 +546,8 @@ public function getProcessedHelp()
548546
*
549547
* @throws InvalidArgumentException When an alias is invalid
550548
*/
551-
public function setAliases($aliases)
549+
public function setAliases(?iterable $aliases)
552550
{
553-
if (!\is_array($aliases) && !$aliases instanceof \Traversable) {
554-
throw new InvalidArgumentException('$aliases must be an array or an instance of \Traversable');
555-
}
556-
557551
foreach ($aliases as $alias) {
558552
$this->validateName($alias);
559553
}
@@ -580,7 +574,7 @@ public function getAliases()
580574
*
581575
* @return string The synopsis
582576
*/
583-
public function getSynopsis($short = false)
577+
public function getSynopsis(bool $short = false)
584578
{
585579
$key = $short ? 'short' : 'long';
586580

@@ -598,7 +592,7 @@ public function getSynopsis($short = false)
598592
*
599593
* @return $this
600594
*/
601-
public function addUsage($usage)
595+
public function addUsage(string $usage)
602596
{
603597
if (0 !== strpos($usage, $this->name)) {
604598
$usage = sprintf('%s %s', $this->name, $usage);
@@ -629,7 +623,7 @@ public function getUsages()
629623
* @throws LogicException if no HelperSet is defined
630624
* @throws InvalidArgumentException if the helper is not defined
631625
*/
632-
public function getHelper($name)
626+
public function getHelper(string $name)
633627
{
634628
if (null === $this->helperSet) {
635629
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: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Console\CommandLoader;
413

514
use Symfony\Component\Console\Command\Command;
@@ -13,22 +22,18 @@ interface CommandLoaderInterface
1322
/**
1423
* Loads a command.
1524
*
16-
* @param string $name
17-
*
1825
* @return Command
1926
*
2027
* @throws CommandNotFoundException
2128
*/
22-
public function get($name);
29+
public function get(string $name);
2330

2431
/**
2532
* Checks if a command exists.
2633
*
27-
* @param string $name
28-
*
2934
* @return bool
3035
*/
31-
public function has($name);
36+
public function has(string $name);
3237

3338
/**
3439
* @return string[] All registered command names

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Symfony\Component\Console\CommandLoader;
413

514
use Psr\Container\ContainerInterface;
@@ -28,7 +37,7 @@ public function __construct(ContainerInterface $container, array $commandMap)
2837
/**
2938
* {@inheritdoc}
3039
*/
31-
public function get($name)
40+
public function get(string $name)
3241
{
3342
if (!$this->has($name)) {
3443
throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
@@ -40,7 +49,7 @@ public function get($name)
4049
/**
4150
* {@inheritdoc}
4251
*/
43-
public function has($name)
52+
public function has(string $name)
4453
{
4554
return isset($this->commandMap[$name]) && $this->container->has($this->commandMap[$name]);
4655
}

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 & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,8 @@ public function describe(OutputInterface $output, $object, array $options = [])
6161

6262
/**
6363
* Writes content to output.
64-
*
65-
* @param string $content
66-
* @param bool $decorated
6764
*/
68-
protected function write($content, $decorated = false)
65+
protected function write(string $content, bool $decorated = false)
6966
{
7067
$this->output->write($content, false, $decorated ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW);
7168
}

0 commit comments

Comments
 (0)
0