Skip to content

[Console] [5.0] Add all type-hint #32318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 21 additions & 60 deletions src/Symfony/Component/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\ErrorCatcher\ErrorHandler;
use Symfony\Component\ErrorCatcher\Exception\FatalThrowableError;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

/**
* An Application is the container for a collection of commands.
Expand Down Expand Up @@ -78,10 +78,6 @@ class Application
private $singleCommand = false;
private $initialized;

/**
* @param string $name The name of the application
* @param string $version The version of the application
*/
public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN')
{
$this->name = $name;
Expand Down Expand Up @@ -342,12 +338,10 @@ public function areExceptionsCaught()

/**
* Sets whether to catch exceptions or not during commands execution.
*
* @param bool $boolean Whether to catch exceptions or not during commands execution
*/
public function setCatchExceptions($boolean)
public function setCatchExceptions(bool $boolean)
{
$this->catchExceptions = (bool) $boolean;
$this->catchExceptions = $boolean;
}

/**
Expand All @@ -362,12 +356,10 @@ public function isAutoExitEnabled()

/**
* Sets whether to automatically exit after a command execution or not.
*
* @param bool $boolean Whether to automatically exit after a command execution or not
*/
public function setAutoExit($boolean)
public function setAutoExit(bool $boolean)
{
$this->autoExit = (bool) $boolean;
$this->autoExit = $boolean;
}

/**
Expand All @@ -382,10 +374,8 @@ public function getName()

/**
* Sets the application name.
*
* @param string $name The application name
*/
public function setName($name)
**/
public function setName(string $name)
{
$this->name = $name;
}
Expand All @@ -402,10 +392,8 @@ public function getVersion()

/**
* Sets the application version.
*
* @param string $version The application version
*/
public function setVersion($version)
public function setVersion(string $version)
{
$this->version = $version;
}
Expand All @@ -431,11 +419,9 @@ public function getLongVersion()
/**
* Registers a new command.
*
* @param string $name The command name
*
* @return Command The newly created command
*/
public function register($name)
public function register(string $name)
{
return $this->add(new Command($name));
}
Expand Down Expand Up @@ -494,13 +480,11 @@ public function add(Command $command)
/**
* Returns a registered command by name or alias.
*
* @param string $name The command name or alias
*
* @return Command A Command object
*
* @throws CommandNotFoundException When given command name does not exist
*/
public function get($name)
public function get(string $name)
{
$this->init();

Expand All @@ -525,11 +509,9 @@ public function get($name)
/**
* Returns true if the command exists, false otherwise.
*
* @param string $name The command name or alias
*
* @return bool true if the command exists, false otherwise
*/
public function has($name)
public function has(string $name)
{
$this->init();

Expand Down Expand Up @@ -560,13 +542,11 @@ public function getNamespaces()
/**
* Finds a registered namespace by a name or an abbreviation.
*
* @param string $namespace A namespace or abbreviation to search for
*
* @return string A registered namespace
*
* @throws NamespaceNotFoundException When namespace is incorrect or ambiguous
*/
public function findNamespace($namespace)
public function findNamespace(string $namespace)
{
$allNamespaces = $this->getNamespaces();
$expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $namespace);
Expand Down Expand Up @@ -602,13 +582,11 @@ public function findNamespace($namespace)
* Contrary to get, this command tries to find the best
* match if you give it an abbreviation of a name or alias.
*
* @param string $name A command name or a command alias
*
* @return Command A Command instance
*
* @throws CommandNotFoundException When command name is incorrect or ambiguous
*/
public function find($name)
public function find(string $name)
{
$this->init();

Expand Down Expand Up @@ -694,11 +672,9 @@ public function find($name)
*
* The array keys are the full names and the values the command instances.
*
* @param string $namespace A namespace name
*
* @return Command[] An array of Command instances
*/
public function all($namespace = null)
public function all(string $namespace = null)
{
$this->init();

Expand Down Expand Up @@ -738,11 +714,9 @@ public function all($namespace = null)
/**
* Returns an array of possible abbreviations given a set of names.
*
* @param array $names An array of names
*
* @return array An array of abbreviations
* @return string[][] An array of abbreviations
*/
public static function getAbbreviations($names)
public static function getAbbreviations(array $names)
{
$abbrevs = [];
foreach ($names as $name) {
Expand Down Expand Up @@ -1020,11 +994,9 @@ protected function getDefaultHelperSet()
/**
* Returns abbreviated suggestions in string format.
*
* @param array $abbrevs Abbreviated suggestions to convert
*
* @return string A formatted string of abbreviated suggestions
*/
private function getAbbreviationSuggestions($abbrevs)
private function getAbbreviationSuggestions(array $abbrevs)
{
return ' '.implode("\n ", $abbrevs);
}
Expand All @@ -1034,12 +1006,9 @@ private function getAbbreviationSuggestions($abbrevs)
*
* This method is not part of public API and should not be used directly.
*
* @param string $name The full name of the command
* @param string $limit The maximum number of parts of the namespace
*
* @return string The namespace of the command
*/
public function extractNamespace($name, $limit = null)
public function extractNamespace(string $name, int $limit = null)
{
$parts = explode(':', $name);
array_pop($parts);
Expand All @@ -1051,12 +1020,9 @@ public function extractNamespace($name, $limit = null)
* Finds alternative of $name among $collection,
* if nothing is found in $collection, try in $abbrevs.
*
* @param string $name The string
* @param iterable $collection The collection
*
* @return string[] A sorted array of similar string
*/
private function findAlternatives($name, $collection)
private function findAlternatives(string $name, iterable $collection)
{
$threshold = 1e3;
$alternatives = [];
Expand Down Expand Up @@ -1101,12 +1067,9 @@ private function findAlternatives($name, $collection)
/**
* Sets the default Command name.
*
* @param string $commandName The Command name
* @param bool $isSingleCommand Set to true if there is only one command in this application
*
* @return self
*/
public function setDefaultCommand($commandName, $isSingleCommand = false)
public function setDefaultCommand(string $commandName, bool $isSingleCommand = false)
{
$this->defaultCommand = $commandName;

Expand Down Expand Up @@ -1161,11 +1124,9 @@ private function splitStringByWidth($string, $width)
/**
* Returns all namespaces of the command name.
*
* @param string $name The full name of the command
*
* @return string[] The namespaces of the command
*/
private function extractAllNamespaces($name)
private function extractAllNamespaces(string $name)
{
// -1 as third argument is needed to skip the command short name when exploding
$parts = explode(':', $name, -1);
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy