[Console] [5.0] Add all type-hint

This commit is contained in:
Amrouche Hamza 2019-07-02 09:44:51 +02:00
parent 8fb4741f92
commit 26624ed529
No known key found for this signature in database
GPG Key ID: E45A3DA456145BC1
44 changed files with 244 additions and 515 deletions

View File

@ -41,9 +41,9 @@ use Symfony\Component\Console\Output\ConsoleOutput;
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.
@ -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;
@ -342,12 +338,10 @@ class Application
/**
* 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;
}
/**
@ -362,12 +356,10 @@ class Application
/**
* 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;
}
/**
@ -382,10 +374,8 @@ class Application
/**
* Sets the application name.
*
* @param string $name The application name
*/
public function setName($name)
**/
public function setName(string $name)
{
$this->name = $name;
}
@ -402,10 +392,8 @@ class Application
/**
* Sets the application version.
*
* @param string $version The application version
*/
public function setVersion($version)
public function setVersion(string $version)
{
$this->version = $version;
}
@ -431,11 +419,9 @@ class Application
/**
* 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));
}
@ -494,13 +480,11 @@ class Application
/**
* 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();
@ -525,11 +509,9 @@ class Application
/**
* 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();
@ -560,13 +542,11 @@ class Application
/**
* 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);
@ -602,13 +582,11 @@ class Application
* 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();
@ -694,11 +672,9 @@ class Application
*
* 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();
@ -738,11 +714,9 @@ class Application
/**
* 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) {
@ -1020,11 +994,9 @@ class Application
/**
* 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);
}
@ -1034,12 +1006,9 @@ class Application
*
* 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);
@ -1051,12 +1020,9 @@ class Application
* 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 = [];
@ -1101,12 +1067,9 @@ class Application
/**
* 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;
@ -1161,11 +1124,9 @@ class Application
/**
* 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);

View File

@ -293,7 +293,7 @@ class Command
*
* @param bool $mergeArgs Whether to merge or not the Application definition arguments to Command definition arguments
*/
public function mergeApplicationDefinition($mergeArgs = true)
public function mergeApplicationDefinition(bool $mergeArgs = true)
{
if (null === $this->application || (true === $this->applicationDefinitionMerged && ($this->applicationDefinitionMergedWithArgs || !$mergeArgs))) {
return;
@ -360,16 +360,14 @@ class Command
/**
* Adds an argument.
*
* @param string $name The argument name
* @param int|null $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
* @param string $description A description text
* @param string|string[]|null $default The default value (for InputArgument::OPTIONAL mode only)
* @param int|null $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL
* @param string|string[]|null $default The default value (for InputArgument::OPTIONAL mode only)
*
* @throws InvalidArgumentException When argument mode is not valid
*
* @return $this
*/
public function addArgument($name, $mode = null, $description = '', $default = null)
public function addArgument(string $name, int $mode = null, string $description = '', $default = null)
{
$this->definition->addArgument(new InputArgument($name, $mode, $description, $default));
@ -379,17 +377,15 @@ class Command
/**
* Adds an option.
*
* @param string $name The option name
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @param int|null $mode The option mode: One of the InputOption::VALUE_* constants
* @param string $description A description text
* @param string|string[]|int|bool|null $default The default value (must be null for InputOption::VALUE_NONE)
* @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts
* @param int|null $mode The option mode: One of the InputOption::VALUE_* constants
* @param string|string[]|int|bool|null $default The default value (must be null for InputOption::VALUE_NONE)
*
* @throws InvalidArgumentException If option mode is invalid or incompatible
*
* @return $this
*/
public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null)
public function addOption(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null)
{
$this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default));
@ -404,13 +400,11 @@ class Command
*
* $command->setName('foo:bar');
*
* @param string $name The command name
*
* @return $this
*
* @throws InvalidArgumentException When the name is invalid
*/
public function setName($name)
public function setName(string $name)
{
$this->validateName($name);
@ -427,11 +421,9 @@ class Command
*
* PHP 5.5+ or the proctitle PECL library is required
*
* @param string $title The process title
*
* @return $this
*/
public function setProcessTitle($title)
public function setProcessTitle(string $title)
{
$this->processTitle = $title;
@ -453,9 +445,9 @@ class Command
*
* @return Command The current instance
*/
public function setHidden($hidden)
public function setHidden(bool $hidden)
{
$this->hidden = (bool) $hidden;
$this->hidden = $hidden;
return $this;
}
@ -471,11 +463,9 @@ class Command
/**
* Sets the description for the command.
*
* @param string $description The description for the command
*
* @return $this
*/
public function setDescription($description)
public function setDescription(string $description)
{
$this->description = $description;
@ -495,11 +485,9 @@ class Command
/**
* Sets the help for the command.
*
* @param string $help The help for the command
*
* @return $this
*/
public function setHelp($help)
public function setHelp(string $help)
{
$this->help = $help;
@ -548,12 +536,8 @@ class Command
*
* @throws InvalidArgumentException When an alias is invalid
*/
public function setAliases($aliases)
public function setAliases(iterable $aliases)
{
if (!\is_array($aliases) && !$aliases instanceof \Traversable) {
throw new InvalidArgumentException('$aliases must be an array or an instance of \Traversable');
}
foreach ($aliases as $alias) {
$this->validateName($alias);
}
@ -580,7 +564,7 @@ class Command
*
* @return string The synopsis
*/
public function getSynopsis($short = false)
public function getSynopsis(bool $short = false)
{
$key = $short ? 'short' : 'long';
@ -592,13 +576,11 @@ class Command
}
/**
* Add a command usage example.
*
* @param string $usage The usage, it'll be prefixed with the command name
* Add a command usage example, it'll be prefixed with the command name.
*
* @return $this
*/
public function addUsage($usage)
public function addUsage(string $usage)
{
if (0 !== strpos($usage, $this->name)) {
$usage = sprintf('%s %s', $this->name, $usage);
@ -622,14 +604,12 @@ class Command
/**
* Gets a helper instance by name.
*
* @param string $name The helper name
*
* @return mixed The helper value
*
* @throws LogicException if no HelperSet is defined
* @throws InvalidArgumentException if the helper is not defined
*/
public function getHelper($name)
public function getHelper(string $name)
{
if (null === $this->helperSet) {
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));

View File

@ -32,7 +32,7 @@ trait LockableTrait
*
* @return bool
*/
private function lock($name = null, $blocking = false)
private function lock(string $name = null, bool $blocking = false)
{
if (!class_exists(SemaphoreStore::class)) {
throw new LogicException('To enable the locking feature you must install the symfony/lock component.');

View File

@ -1,5 +1,14 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\CommandLoader;
use Symfony\Component\Console\Command\Command;
@ -13,22 +22,18 @@ interface CommandLoaderInterface
/**
* Loads a command.
*
* @param string $name
*
* @return Command
*
* @throws CommandNotFoundException
*/
public function get($name);
public function get(string $name);
/**
* Checks if a command exists.
*
* @param string $name
*
* @return bool
*/
public function has($name);
public function has(string $name);
/**
* @return string[] All registered command names

View File

@ -1,5 +1,14 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Console\CommandLoader;
use Psr\Container\ContainerInterface;
@ -28,7 +37,7 @@ class ContainerCommandLoader implements CommandLoaderInterface
/**
* {@inheritdoc}
*/
public function get($name)
public function get(string $name)
{
if (!$this->has($name)) {
throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
@ -40,7 +49,7 @@ class ContainerCommandLoader implements CommandLoaderInterface
/**
* {@inheritdoc}
*/
public function has($name)
public function has(string $name)
{
return isset($this->commandMap[$name]) && $this->container->has($this->commandMap[$name]);
}

View File

@ -33,7 +33,7 @@ class FactoryCommandLoader implements CommandLoaderInterface
/**
* {@inheritdoc}
*/
public function has($name)
public function has(string $name)
{
return isset($this->factories[$name]);
}
@ -41,7 +41,7 @@ class FactoryCommandLoader implements CommandLoaderInterface
/**
* {@inheritdoc}
*/
public function get($name)
public function get(string $name)
{
if (!isset($this->factories[$name])) {
throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));

View File

@ -75,13 +75,11 @@ class ApplicationDescription
}
/**
* @param string $name
*
* @return Command
*
* @throws CommandNotFoundException
*/
public function getCommand($name)
public function getCommand(string $name)
{
if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
throw new CommandNotFoundException(sprintf('Command %s does not exist.', $name));

View File

@ -61,11 +61,8 @@ abstract class Descriptor implements DescriptorInterface
/**
* Writes content to output.
*
* @param string $content
* @param bool $decorated
*/
protected function write($content, $decorated = false)
protected function write(string $content, bool $decorated = false)
{
$this->output->write($content, false, $decorated ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW);
}

View File

@ -44,7 +44,7 @@ class MarkdownDescriptor extends Descriptor
/**
* {@inheritdoc}
*/
protected function write($content, $decorated = true)
protected function write(string $content, bool $decorated = true)
{
parent::write($content, $decorated);
}
@ -92,7 +92,9 @@ class MarkdownDescriptor extends Descriptor
$this->write('### Arguments');
foreach ($definition->getArguments() as $argument) {
$this->write("\n\n");
$this->write($this->describeInputArgument($argument));
if (null !== $describeInputArgument = $this->describeInputArgument($argument)) {
$this->write($describeInputArgument);
}
}
}
@ -104,7 +106,9 @@ class MarkdownDescriptor extends Descriptor
$this->write('### Options');
foreach ($definition->getOptions() as $option) {
$this->write("\n\n");
$this->write($this->describeInputOption($option));
if (null !== $describeInputOption = $this->describeInputOption($option)) {
$this->write($describeInputOption);
}
}
}
}
@ -163,7 +167,9 @@ class MarkdownDescriptor extends Descriptor
foreach ($description->getCommands() as $command) {
$this->write("\n\n");
$this->write($this->describeCommand($command));
if (null !== $describeCommand = $this->describeCommand($command)) {
$this->write($describeCommand);
}
}
}

View File

@ -81,12 +81,9 @@ class XmlDescriptor extends Descriptor
}
/**
* @param Application $application
* @param string|null $namespace
*
* @return \DOMDocument
*/
public function getApplicationDocument(Application $application, $namespace = null)
public function getApplicationDocument(Application $application, string $namespace = null)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$dom->appendChild($rootXml = $dom->createElement('symfony'));

View File

@ -28,11 +28,9 @@ class OutputFormatter implements WrappableOutputFormatterInterface
/**
* Escapes "<" special char in given text.
*
* @param string $text Text to escape
*
* @return string Escaped text
*/
public static function escape($text)
public static function escape(string $text)
{
$text = preg_replace('/([^\\\\]?)</', '$1\\<', $text);
@ -42,13 +40,11 @@ class OutputFormatter implements WrappableOutputFormatterInterface
/**
* Escapes trailing "\" in given text.
*
* @param string $text Text to escape
*
* @return string Escaped text
*
* @internal
*/
public static function escapeTrailingBackslash($text)
public static function escapeTrailingBackslash(string $text)
{
if ('\\' === substr($text, -1)) {
$len = \strlen($text);
@ -63,8 +59,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface
/**
* Initializes console output formatter.
*
* @param bool $decorated Whether this formatter should actually decorate strings
* @param OutputFormatterStyleInterface[] $styles Array of "name => FormatterStyle" instances
* @param OutputFormatterStyleInterface[] $styles Array of "name => FormatterStyle" instances
*/
public function __construct(bool $decorated = false, array $styles = [])
{
@ -85,9 +80,9 @@ class OutputFormatter implements WrappableOutputFormatterInterface
/**
* {@inheritdoc}
*/
public function setDecorated($decorated)
public function setDecorated(bool $decorated)
{
$this->decorated = (bool) $decorated;
$this->decorated = $decorated;
}
/**
@ -101,7 +96,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface
/**
* {@inheritdoc}
*/
public function setStyle($name, OutputFormatterStyleInterface $style)
public function setStyle(string $name, OutputFormatterStyleInterface $style)
{
$this->styles[strtolower($name)] = $style;
}
@ -109,7 +104,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface
/**
* {@inheritdoc}
*/
public function hasStyle($name)
public function hasStyle(string $name)
{
return isset($this->styles[strtolower($name)]);
}
@ -117,7 +112,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface
/**
* {@inheritdoc}
*/
public function getStyle($name)
public function getStyle(string $name)
{
if (!$this->hasStyle($name)) {
throw new InvalidArgumentException(sprintf('Undefined style: %s', $name));
@ -129,15 +124,15 @@ class OutputFormatter implements WrappableOutputFormatterInterface
/**
* {@inheritdoc}
*/
public function format($message)
public function format(?string $message)
{
return $this->formatAndWrap((string) $message, 0);
return $this->formatAndWrap($message, 0);
}
/**
* {@inheritdoc}
*/
public function formatAndWrap(string $message, int $width)
public function formatAndWrap(?string $message, int $width)
{
$offset = 0;
$output = '';

View File

@ -20,10 +20,8 @@ interface OutputFormatterInterface
{
/**
* Sets the decorated flag.
*
* @param bool $decorated Whether to decorate the messages or not
*/
public function setDecorated($decorated);
public function setDecorated(bool $decorated);
/**
* Gets the decorated flag.
@ -34,38 +32,27 @@ interface OutputFormatterInterface
/**
* Sets a new style.
*
* @param string $name The style name
* @param OutputFormatterStyleInterface $style The style instance
*/
public function setStyle($name, OutputFormatterStyleInterface $style);
public function setStyle(string $name, OutputFormatterStyleInterface $style);
/**
* Checks if output formatter has style with specified name.
*
* @param string $name
*
* @return bool
*/
public function hasStyle($name);
public function hasStyle(string $name);
/**
* Gets style options from style with specified name.
*
* @param string $name
*
* @return OutputFormatterStyleInterface
*
* @throws \InvalidArgumentException When style isn't defined
*/
public function getStyle($name);
public function getStyle(string $name);
/**
* Formats a message according to the given styles.
*
* @param string $message The message to style
*
* @return string The styled message
*/
public function format($message);
public function format(?string $message);
}

View File

@ -77,13 +77,9 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
}
/**
* Sets style foreground color.
*
* @param string|null $color The color name
*
* @throws InvalidArgumentException When the color name isn't defined
* {@inheritdoc}
*/
public function setForeground($color = null)
public function setForeground(string $color = null)
{
if (null === $color) {
$this->foreground = null;
@ -99,13 +95,9 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
}
/**
* Sets style background color.
*
* @param string|null $color The color name
*
* @throws InvalidArgumentException When the color name isn't defined
* {@inheritdoc}
*/
public function setBackground($color = null)
public function setBackground(string $color = null)
{
if (null === $color) {
$this->background = null;
@ -126,13 +118,9 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
}
/**
* Sets some specific style option.
*
* @param string $option The option name
*
* @throws InvalidArgumentException When the option name isn't defined
* {@inheritdoc}
*/
public function setOption($option)
public function setOption(string $option)
{
if (!isset(static::$availableOptions[$option])) {
throw new InvalidArgumentException(sprintf('Invalid option specified: "%s". Expected one of (%s)', $option, implode(', ', array_keys(static::$availableOptions))));
@ -144,13 +132,9 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
}
/**
* Unsets some specific style option.
*
* @param string $option The option name
*
* @throws InvalidArgumentException When the option name isn't defined
* {@inheritdoc}
*/
public function unsetOption($option)
public function unsetOption(string $option)
{
if (!isset(static::$availableOptions[$option])) {
throw new InvalidArgumentException(sprintf('Invalid option specified: "%s". Expected one of (%s)', $option, implode(', ', array_keys(static::$availableOptions))));
@ -175,13 +159,9 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface
}
/**
* Applies the style to a given text.
*
* @param string $text The text to style
*
* @return string
* {@inheritdoc}
*/
public function apply($text)
public function apply(string $text)
{
$setCodes = [];
$unsetCodes = [];

View File

@ -20,31 +20,23 @@ interface OutputFormatterStyleInterface
{
/**
* Sets style foreground color.
*
* @param string $color The color name
*/
public function setForeground($color = null);
public function setForeground(string $color = null);
/**
* Sets style background color.
*
* @param string $color The color name
*/
public function setBackground($color = null);
public function setBackground(string $color = null);
/**
* Sets some specific style option.
*
* @param string $option The option name
*/
public function setOption($option);
public function setOption(string $option);
/**
* Unsets some specific style option.
*
* @param string $option The option name
*/
public function unsetOption($option);
public function unsetOption(string $option);
/**
* Sets multiple style options at once.
@ -54,9 +46,7 @@ interface OutputFormatterStyleInterface
/**
* Applies the style to a given text.
*
* @param string $text The text to style
*
* @return string
*/
public function apply($text);
public function apply(string $text);
}

View File

@ -21,5 +21,5 @@ interface WrappableOutputFormatterInterface extends OutputFormatterInterface
/**
* Formats a message according to the given styles, wrapping at `$width` (0 means no wrapping).
*/
public function formatAndWrap(string $message, int $width);
public function formatAndWrap(?string $message, int $width);
}

View File

@ -27,13 +27,9 @@ class DebugFormatterHelper extends Helper
/**
* Starts a debug formatting session.
*
* @param string $id The id of the formatting session
* @param string $message The message to display
* @param string $prefix The prefix to use
*
* @return string
*/
public function start($id, $message, $prefix = 'RUN')
public function start(string $id, string $message, string $prefix = 'RUN')
{
$this->started[$id] = ['border' => ++$this->count % \count($this->colors)];
@ -43,15 +39,9 @@ class DebugFormatterHelper extends Helper
/**
* Adds progress to a formatting session.
*
* @param string $id The id of the formatting session
* @param string $buffer The message to display
* @param bool $error Whether to consider the buffer as error
* @param string $prefix The prefix for output
* @param string $errorPrefix The prefix for error output
*
* @return string
*/
public function progress($id, $buffer, $error = false, $prefix = 'OUT', $errorPrefix = 'ERR')
public function progress(string $id, string $buffer, bool $error = false, string $prefix = 'OUT', string $errorPrefix = 'ERR')
{
$message = '';
@ -85,14 +75,9 @@ class DebugFormatterHelper extends Helper
/**
* Stops a formatting session.
*
* @param string $id The id of the formatting session
* @param string $message The message to display
* @param bool $successful Whether to consider the result as success
* @param string $prefix The prefix for the end output
*
* @return string
*/
public function stop($id, $message, $successful, $prefix = 'RES')
public function stop(string $id, string $message, bool $successful, string $prefix = 'RES')
{
$trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : '';
@ -108,11 +93,9 @@ class DebugFormatterHelper extends Helper
}
/**
* @param string $id The id of the formatting session
*
* @return string
*/
private function getBorder($id)
private function getBorder(string $id)
{
return sprintf('<bg=%s> </>', $this->colors[$this->started[$id]['border']]);
}

View File

@ -23,13 +23,9 @@ class FormatterHelper extends Helper
/**
* Formats a message within a section.
*
* @param string $section The section name
* @param string $message The message
* @param string $style The style to apply to the section
*
* @return string The format section
*/
public function formatSection($section, $message, $style = 'info')
public function formatSection(string $section, string $message, string $style = 'info')
{
return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message);
}
@ -38,12 +34,10 @@ class FormatterHelper extends Helper
* Formats a message as a block of text.
*
* @param string|array $messages The message to write in the block
* @param string $style The style to apply to the whole block
* @param bool $large Whether to return a large block
*
* @return string The formatter message
*/
public function formatBlock($messages, $style, $large = false)
public function formatBlock($messages, string $style, bool $large = false)
{
if (!\is_array($messages)) {
$messages = [$messages];
@ -75,13 +69,9 @@ class FormatterHelper extends Helper
/**
* Truncates a message to the given length.
*
* @param string $message
* @param int $length
* @param string $suffix
*
* @return string
*/
public function truncate($message, $length, $suffix = '...')
public function truncate(string $message, int $length, string $suffix = '...')
{
$computedLength = $length - $this->strlen($suffix);

View File

@ -41,11 +41,9 @@ abstract class Helper implements HelperInterface
/**
* Returns the length of a string, using mb_strwidth if it is available.
*
* @param string $string The string to check its length
*
* @return int The length of the string
*/
public static function strlen($string)
public static function strlen(?string $string)
{
if (false === $encoding = mb_detect_encoding($string, null, true)) {
return \strlen($string);
@ -57,13 +55,9 @@ abstract class Helper implements HelperInterface
/**
* Returns the subset of a string, using mb_substr if it is available.
*
* @param string $string String to subset
* @param int $from Start offset
* @param int|null $length Length to read
*
* @return string The string subset
*/
public static function substr($string, $from, $length = null)
public static function substr(string $string, int $from, int $length = null)
{
if (false === $encoding = mb_detect_encoding($string, null, true)) {
return substr($string, $from, $length);
@ -101,7 +95,7 @@ abstract class Helper implements HelperInterface
}
}
public static function formatMemory($memory)
public static function formatMemory(int $memory)
{
if ($memory >= 1024 * 1024 * 1024) {
return sprintf('%.1f GiB', $memory / 1024 / 1024 / 1024);

View File

@ -37,13 +37,7 @@ class HelperSet implements \IteratorAggregate
}
}
/**
* Sets a helper.
*
* @param HelperInterface $helper The helper instance
* @param string $alias An alias
*/
public function set(HelperInterface $helper, $alias = null)
public function set(HelperInterface $helper, string $alias = null)
{
$this->helpers[$helper->getName()] = $helper;
if (null !== $alias) {
@ -56,11 +50,9 @@ class HelperSet implements \IteratorAggregate
/**
* Returns true if the helper if defined.
*
* @param string $name The helper name
*
* @return bool true if the helper is defined, false otherwise
*/
public function has($name)
public function has(string $name)
{
return isset($this->helpers[$name]);
}
@ -68,13 +60,11 @@ class HelperSet implements \IteratorAggregate
/**
* Gets a helper value.
*
* @param string $name The helper name
*
* @return HelperInterface The helper instance
*
* @throws InvalidArgumentException if the helper is not defined
*/
public function get($name)
public function get(string $name)
{
if (!$this->has($name)) {
throw new InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));

View File

@ -28,16 +28,13 @@ class ProcessHelper extends Helper
/**
* Runs an external process.
*
* @param OutputInterface $output An OutputInterface instance
* @param array|Process $cmd An instance of Process or an array of the command and arguments
* @param string|null $error An error message that must be displayed if something went wrong
* @param callable|null $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
* @param int $verbosity The threshold for verbosity
* @param array|Process $cmd An instance of Process or an array of the command and arguments
* @param callable|null $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
*
* @return Process The process that ran
*/
public function run(OutputInterface $output, $cmd, $error = null, callable $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE): Process
public function run(OutputInterface $output, $cmd, string $error = null, callable $callback = null, int $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE): Process
{
if ($output instanceof ConsoleOutputInterface) {
$output = $output->getErrorOutput();
@ -91,11 +88,9 @@ class ProcessHelper extends Helper
* This is identical to run() except that an exception is thrown if the process
* exits with a non-zero exit code.
*
* @param OutputInterface $output An OutputInterface instance
* @param string|Process $cmd An instance of Process or a command to run
* @param string|null $error An error message that must be displayed if something went wrong
* @param callable|null $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
* @param string|Process $cmd An instance of Process or a command to run
* @param callable|null $callback A PHP callback to run whenever there is some
* output available on STDOUT or STDERR
*
* @return Process The process that ran
*
@ -103,7 +98,7 @@ class ProcessHelper extends Helper
*
* @see run()
*/
public function mustRun(OutputInterface $output, $cmd, $error = null, callable $callback = null): Process
public function mustRun(OutputInterface $output, $cmd, string $error = null, callable $callback = null): Process
{
$process = $this->run($output, $cmd, $error, $callback);
@ -116,10 +111,6 @@ class ProcessHelper extends Helper
/**
* Wraps a Process callback to add debugging output.
*
* @param OutputInterface $output An OutputInterface interface
* @param Process $process The Process
* @param callable|null $callback A PHP callable
*/
public function wrapCallback(OutputInterface $output, Process $process, callable $callback = null): callable
{

View File

@ -34,10 +34,8 @@ class ProgressIndicator
private static $formats;
/**
* @param OutputInterface $output
* @param string|null $format Indicator format
* @param int $indicatorChangeInterval Change interval in milliseconds
* @param array|null $indicatorValues Animated indicator characters
* @param int $indicatorChangeInterval Change interval in milliseconds
* @param array|null $indicatorValues Animated indicator characters
*/
public function __construct(OutputInterface $output, string $format = null, int $indicatorChangeInterval = 100, array $indicatorValues = null)
{
@ -65,10 +63,8 @@ class ProgressIndicator
/**
* Sets the current indicator message.
*
* @param string|null $message
*/
public function setMessage($message)
public function setMessage(?string $message)
{
$this->message = $message;
@ -80,7 +76,7 @@ class ProgressIndicator
*
* @param $message
*/
public function start($message)
public function start(string $message)
{
if ($this->started) {
throw new LogicException('Progress indicator already started.');
@ -125,7 +121,7 @@ class ProgressIndicator
*
* @param $message
*/
public function finish($message)
public function finish(string $message)
{
if (!$this->started) {
throw new LogicException('Progress indicator has not yet been started.');
@ -140,11 +136,9 @@ class ProgressIndicator
/**
* Gets the format for a given name.
*
* @param string $name The format name
*
* @return string|null A format string
*/
public static function getFormatDefinition($name)
public static function getFormatDefinition(string $name)
{
if (!self::$formats) {
self::$formats = self::initFormats();
@ -157,11 +151,8 @@ class ProgressIndicator
* Sets a placeholder formatter for a given name.
*
* This method also allow you to override an existing placeholder.
*
* @param string $name The placeholder name (including the delimiter char like %)
* @param callable $callable A PHP callable
*/
public static function setPlaceholderFormatterDefinition($name, $callable)
public static function setPlaceholderFormatterDefinition(string $name, callable $callable)
{
if (!self::$formatters) {
self::$formatters = self::initPlaceholderFormatters();
@ -171,13 +162,11 @@ class ProgressIndicator
}
/**
* Gets the placeholder formatter for a given name.
*
* @param string $name The placeholder name (including the delimiter char like %)
* Gets the placeholder formatter for a given name (including the delimiter char like %).
*
* @return callable|null A PHP callable
*/
public static function getPlaceholderFormatterDefinition($name)
public static function getPlaceholderFormatterDefinition(string $name)
{
if (!self::$formatters) {
self::$formatters = self::initPlaceholderFormatters();

View File

@ -331,7 +331,7 @@ class QuestionHelper extends Helper
return $fullChoice;
}
private function mostRecentlyEnteredValue($entered)
private function mostRecentlyEnteredValue(string $entered)
{
// Determine the most recent value that the user entered
if (false === strpos($entered, ',')) {

View File

@ -101,11 +101,8 @@ class Table
/**
* Sets a style definition.
*
* @param string $name The style name
* @param TableStyle $style A TableStyle instance
*/
public static function setStyleDefinition($name, TableStyle $style)
public static function setStyleDefinition(string $name, TableStyle $style)
{
if (!self::$styles) {
self::$styles = self::initStyles();
@ -117,11 +114,9 @@ class Table
/**
* Gets a style definition by name.
*
* @param string $name The style name
*
* @return TableStyle
*/
public static function getStyleDefinition($name)
public static function getStyleDefinition(string $name)
{
if (!self::$styles) {
self::$styles = self::initStyles();
@ -161,15 +156,12 @@ class Table
/**
* Sets table column style.
*
* @param int $columnIndex Column index
* @param TableStyle|string $name The style name or a TableStyle instance
* @param TableStyle|string $name The style name or a TableStyle instance
*
* @return $this
*/
public function setColumnStyle($columnIndex, $name)
public function setColumnStyle(int $columnIndex, $name)
{
$columnIndex = (int) $columnIndex;
$this->columnStyles[$columnIndex] = $this->resolveStyle($name);
return $this;
@ -180,11 +172,9 @@ class Table
*
* If style was not set, it returns the global table style.
*
* @param int $columnIndex Column index
*
* @return TableStyle
*/
public function getColumnStyle($columnIndex)
public function getColumnStyle(int $columnIndex)
{
return $this->columnStyles[$columnIndex] ?? $this->getStyle();
}
@ -192,14 +182,11 @@ class Table
/**
* Sets the minimum width of a column.
*
* @param int $columnIndex Column index
* @param int $width Minimum column width in characters
*
* @return $this
*/
public function setColumnWidth($columnIndex, $width)
public function setColumnWidth(int $columnIndex, int $width)
{
$this->columnWidths[(int) $columnIndex] = (int) $width;
$this->columnWidths[$columnIndex] = $width;
return $this;
}
@ -207,8 +194,6 @@ class Table
/**
* Sets the minimum width of all columns.
*
* @param array $widths
*
* @return $this
*/
public function setColumnWidths(array $widths)

View File

@ -51,11 +51,9 @@ class TableStyle
/**
* Sets padding character, used for cell padding.
*
* @param string $paddingChar
*
* @return $this
*/
public function setPaddingChar($paddingChar)
public function setPaddingChar(string $paddingChar)
{
if (!$paddingChar) {
throw new LogicException('The padding char must not be empty');
@ -89,9 +87,6 @@ class TableStyle
* 80-902734-1-6 And Then There Were None Agatha Christie
* ╚═══════════════╧══════════════════════════╧══════════════════╝
* </code>
*
* @param string $outside Outside border char (see #1 of example)
* @param string|null $inside Inside border char (see #2 of example), equals $outside if null
*/
public function setHorizontalBorderChars(string $outside, string $inside = null): self
{
@ -115,9 +110,6 @@ class TableStyle
* 80-902734-1-6 And Then There Were None Agatha Christie
* ╚═══════════════╧══════════════════════════╧══════════════════╝
* </code>
*
* @param string $outside Outside border char (see #1 of example)
* @param string|null $inside Inside border char (see #2 of example), equals $outside if null
*/
public function setVerticalBorderChars(string $outside, string $inside = null): self
{
@ -263,7 +255,7 @@ class TableStyle
*
* @return $this
*/
public function setCellRowFormat($cellRowFormat)
public function setCellRowFormat(string $cellRowFormat)
{
$this->cellRowFormat = $cellRowFormat;
@ -287,7 +279,7 @@ class TableStyle
*
* @return $this
*/
public function setCellRowContentFormat($cellRowContentFormat)
public function setCellRowContentFormat(string $cellRowContentFormat)
{
$this->cellRowContentFormat = $cellRowContentFormat;
@ -311,7 +303,7 @@ class TableStyle
*
* @return $this
*/
public function setBorderFormat($borderFormat)
public function setBorderFormat(string $borderFormat)
{
$this->borderFormat = $borderFormat;
@ -331,11 +323,9 @@ class TableStyle
/**
* Sets cell padding type.
*
* @param int $padType STR_PAD_*
*
* @return $this
*/
public function setPadType($padType)
public function setPadType(int $padType)
{
if (!\in_array($padType, [STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH], true)) {
throw new InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).');

View File

@ -43,10 +43,6 @@ class ArgvInput extends Input
private $tokens;
private $parsed;
/**
* @param array|null $argv An array of parameters from the CLI (in the argv format)
* @param InputDefinition|null $definition A InputDefinition instance
*/
public function __construct(array $argv = null, InputDefinition $definition = null)
{
if (null === $argv) {
@ -90,10 +86,8 @@ class ArgvInput extends Input
/**
* Parses a short option.
*
* @param string $token The current token
*/
private function parseShortOption($token)
private function parseShortOption(string $token)
{
$name = substr($token, 1);
@ -112,11 +106,9 @@ class ArgvInput extends Input
/**
* Parses a short option set.
*
* @param string $name The current token
*
* @throws RuntimeException When option given doesn't exist
*/
private function parseShortOptionSet($name)
private function parseShortOptionSet(string $name)
{
$len = \strlen($name);
for ($i = 0; $i < $len; ++$i) {
@ -138,10 +130,8 @@ class ArgvInput extends Input
/**
* Parses a long option.
*
* @param string $token The current token
*/
private function parseLongOption($token)
private function parseLongOption(string $token)
{
$name = substr($token, 2);
@ -158,11 +148,9 @@ class ArgvInput extends Input
/**
* Parses an argument.
*
* @param string $token The current token
*
* @throws RuntimeException When too many arguments are given
*/
private function parseArgument($token)
private function parseArgument(string $token)
{
$c = \count($this->arguments);
@ -190,12 +178,11 @@ class ArgvInput extends Input
/**
* Adds a short option value.
*
* @param string $shortcut The short option key
* @param mixed $value The value for the option
* @param mixed $value The value for the option
*
* @throws RuntimeException When option given doesn't exist
*/
private function addShortOption($shortcut, $value)
private function addShortOption(string $shortcut, $value)
{
if (!$this->definition->hasShortcut($shortcut)) {
throw new RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut));
@ -207,12 +194,11 @@ class ArgvInput extends Input
/**
* Adds a long option value.
*
* @param string $name The long option key
* @param mixed $value The value for the option
* @param mixed $value The value for the option
*
* @throws RuntimeException When option given doesn't exist
*/
private function addLongOption($name, $value)
private function addLongOption(string $name, $value)
{
if (!$this->definition->hasOption($name)) {
throw new RuntimeException(sprintf('The "--%s" option does not exist.', $name));
@ -288,7 +274,7 @@ class ArgvInput extends Input
/**
* {@inheritdoc}
*/
public function hasParameterOption($values, $onlyParams = false)
public function hasParameterOption($values, bool $onlyParams = false)
{
$values = (array) $values;
@ -313,7 +299,7 @@ class ArgvInput extends Input
/**
* {@inheritdoc}
*/
public function getParameterOption($values, $default = false, $onlyParams = false)
public function getParameterOption($values, $default = false, bool $onlyParams = false)
{
$values = (array) $values;
$tokens = $this->tokens;

View File

@ -51,7 +51,7 @@ class ArrayInput extends Input
/**
* {@inheritdoc}
*/
public function hasParameterOption($values, $onlyParams = false)
public function hasParameterOption($values, bool $onlyParams = false)
{
$values = (array) $values;
@ -75,7 +75,7 @@ class ArrayInput extends Input
/**
* {@inheritdoc}
*/
public function getParameterOption($values, $default = false, $onlyParams = false)
public function getParameterOption($values, $default = false, bool $onlyParams = false)
{
$values = (array) $values;
@ -143,12 +143,11 @@ class ArrayInput extends Input
/**
* Adds a short option value.
*
* @param string $shortcut The short option key
* @param mixed $value The value for the option
* @param mixed $value The value for the option
*
* @throws InvalidOptionException When option given doesn't exist
*/
private function addShortOption($shortcut, $value)
private function addShortOption(string $shortcut, $value)
{
if (!$this->definition->hasShortcut($shortcut)) {
throw new InvalidOptionException(sprintf('The "-%s" option does not exist.', $shortcut));
@ -160,13 +159,12 @@ class ArrayInput extends Input
/**
* Adds a long option value.
*
* @param string $name The long option key
* @param mixed $value The value for the option
* @param mixed $value The value for the option
*
* @throws InvalidOptionException When option given doesn't exist
* @throws InvalidOptionException When a required value is missing
*/
private function addLongOption($name, $value)
private function addLongOption(string $name, $value)
{
if (!$this->definition->hasOption($name)) {
throw new InvalidOptionException(sprintf('The "--%s" option does not exist.', $name));

View File

@ -88,9 +88,9 @@ abstract class Input implements InputInterface, StreamableInputInterface
/**
* {@inheritdoc}
*/
public function setInteractive($interactive)
public function setInteractive(bool $interactive)
{
$this->interactive = (bool) $interactive;
$this->interactive = $interactive;
}
/**
@ -144,7 +144,7 @@ abstract class Input implements InputInterface, StreamableInputInterface
/**
* {@inheritdoc}
*/
public function getOption($name)
public function getOption(string $name)
{
if (!$this->definition->hasOption($name)) {
throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
@ -156,7 +156,7 @@ abstract class Input implements InputInterface, StreamableInputInterface
/**
* {@inheritdoc}
*/
public function setOption($name, $value)
public function setOption(string $name, $value)
{
if (!$this->definition->hasOption($name)) {
throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
@ -168,7 +168,7 @@ abstract class Input implements InputInterface, StreamableInputInterface
/**
* {@inheritdoc}
*/
public function hasOption($name)
public function hasOption(string $name)
{
return $this->definition->hasOption($name);
}
@ -176,11 +176,9 @@ abstract class Input implements InputInterface, StreamableInputInterface
/**
* Escapes a token through escapeshellarg if it contains unsafe chars.
*
* @param string $token
*
* @return string
*/
public function escapeToken($token)
public function escapeToken(string $token)
{
return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token);
}

View File

@ -67,7 +67,7 @@ class InputDefinition
*
* @param InputArgument[] $arguments An array of InputArgument objects
*/
public function setArguments($arguments = [])
public function setArguments(array $arguments = [])
{
$this->arguments = [];
$this->requiredCount = 0;
@ -81,7 +81,7 @@ class InputDefinition
*
* @param InputArgument[] $arguments An array of InputArgument objects
*/
public function addArguments($arguments = [])
public function addArguments(?array $arguments = [])
{
if (null !== $arguments) {
foreach ($arguments as $argument) {
@ -204,7 +204,7 @@ class InputDefinition
*
* @param InputOption[] $options An array of InputOption objects
*/
public function setOptions($options = [])
public function setOptions(array $options = [])
{
$this->options = [];
$this->shortcuts = [];
@ -216,7 +216,7 @@ class InputDefinition
*
* @param InputOption[] $options An array of InputOption objects
*/
public function addOptions($options = [])
public function addOptions(array $options = [])
{
foreach ($options as $option) {
$this->addOption($option);
@ -251,13 +251,11 @@ class InputDefinition
/**
* Returns an InputOption by name.
*
* @param string $name The InputOption name
*
* @return InputOption A InputOption object
*
* @throws InvalidArgumentException When option given doesn't exist
*/
public function getOption($name)
public function getOption(string $name)
{
if (!$this->hasOption($name)) {
throw new InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
@ -272,11 +270,9 @@ class InputDefinition
* This method can't be used to check if the user included the option when
* executing the command (use getOption() instead).
*
* @param string $name The InputOption name
*
* @return bool true if the InputOption object exists, false otherwise
*/
public function hasOption($name)
public function hasOption(string $name)
{
return isset($this->options[$name]);
}
@ -294,11 +290,9 @@ class InputDefinition
/**
* Returns true if an InputOption object exists by shortcut.
*
* @param string $name The InputOption shortcut
*
* @return bool true if the InputOption object exists, false otherwise
*/
public function hasShortcut($name)
public function hasShortcut(string $name)
{
return isset($this->shortcuts[$name]);
}
@ -306,11 +300,9 @@ class InputDefinition
/**
* Gets an InputOption by shortcut.
*
* @param string $shortcut The Shortcut name
*
* @return InputOption An InputOption object
*/
public function getOptionForShortcut($shortcut)
public function getOptionForShortcut(string $shortcut)
{
return $this->getOption($this->shortcutToName($shortcut));
}
@ -333,15 +325,13 @@ class InputDefinition
/**
* Returns the InputOption name given a shortcut.
*
* @param string $shortcut The shortcut
*
* @return string The InputOption name
*
* @throws InvalidArgumentException When option given does not exist
*
* @internal
*/
public function shortcutToName($shortcut)
public function shortcutToName(string $shortcut)
{
if (!isset($this->shortcuts[$shortcut])) {
throw new InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
@ -353,11 +343,9 @@ class InputDefinition
/**
* Gets the synopsis.
*
* @param bool $short Whether to return the short version (with options folded) or not
*
* @return string The synopsis
*/
public function getSynopsis($short = false)
public function getSynopsis(bool $short = false)
{
$elements = [];

View File

@ -41,7 +41,7 @@ interface InputInterface
*
* @return bool true if the value is contained in the raw parameters
*/
public function hasParameterOption($values, $onlyParams = false);
public function hasParameterOption($values, bool $onlyParams = false);
/**
* Returns the value of a raw option (not parsed).
@ -57,7 +57,7 @@ interface InputInterface
*
* @return mixed The option value
*/
public function getParameterOption($values, $default = false, $onlyParams = false);
public function getParameterOption($values, $default = false, bool $onlyParams = false);
/**
* Binds the current Input instance with the given arguments and options.
@ -83,23 +83,20 @@ interface InputInterface
/**
* Returns the argument value for a given argument name.
*
* @param string $name The argument name
*
* @return string|string[]|null The argument value
*
* @throws InvalidArgumentException When argument given doesn't exist
*/
public function getArgument($name);
public function getArgument(string $name);
/**
* Sets an argument value by name.
*
* @param string $name The argument name
* @param string|string[]|null $value The argument value
*
* @throws InvalidArgumentException When argument given doesn't exist
*/
public function setArgument($name, $value);
public function setArgument(string $name, $value);
/**
* Returns true if an InputArgument object exists by name or position.
@ -120,32 +117,27 @@ interface InputInterface
/**
* Returns the option value for a given option name.
*
* @param string $name The option name
*
* @return string|string[]|bool|null The option value
*
* @throws InvalidArgumentException When option given doesn't exist
*/
public function getOption($name);
public function getOption(string $name);
/**
* Sets an option value by name.
*
* @param string $name The option name
* @param string|string[]|bool|null $value The option value
*
* @throws InvalidArgumentException When option given doesn't exist
*/
public function setOption($name, $value);
public function setOption(string $name, $value);
/**
* Returns true if an InputOption object exists by name.
*
* @param string $name The InputOption name
*
* @return bool true if the InputOption object exists, false otherwise
*/
public function hasOption($name);
public function hasOption(string $name);
/**
* Is this input means interactive?
@ -156,8 +148,6 @@ interface InputInterface
/**
* Sets the input interactivity.
*
* @param bool $interactive If the input should be interactive
*/
public function setInteractive($interactive);
public function setInteractive(bool $interactive);
}

View File

@ -40,13 +40,11 @@ class StringInput extends ArgvInput
/**
* Tokenizes a string.
*
* @param string $input The input to tokenize
*
* @return array An array of tokens
*
* @throws InvalidArgumentException When unable to parse input (should never happen)
*/
private function tokenize($input)
private function tokenize(string $input)
{
$tokens = [];
$length = \strlen($input);

View File

@ -34,7 +34,7 @@ class BufferedOutput extends Output
/**
* {@inheritdoc}
*/
protected function doWrite($message, $newline)
protected function doWrite(string $message, bool $newline)
{
$this->buffer .= $message;

View File

@ -60,7 +60,7 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
/**
* {@inheritdoc}
*/
public function setDecorated($decorated)
public function setDecorated(bool $decorated)
{
parent::setDecorated($decorated);
$this->stderr->setDecorated($decorated);
@ -78,7 +78,7 @@ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
/**
* {@inheritdoc}
*/
public function setVerbosity($level)
public function setVerbosity(int $level)
{
parent::setVerbosity($level);
$this->stderr->setVerbosity($level);

View File

@ -44,7 +44,7 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function setDecorated($decorated)
public function setDecorated(bool $decorated)
{
// do nothing
}
@ -60,7 +60,7 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function setVerbosity($level)
public function setVerbosity(int $level)
{
// do nothing
}
@ -108,7 +108,7 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function writeln($messages, $options = self::OUTPUT_NORMAL)
public function writeln($messages, int $options = self::OUTPUT_NORMAL)
{
// do nothing
}
@ -116,7 +116,7 @@ class NullOutput implements OutputInterface
/**
* {@inheritdoc}
*/
public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL)
public function write($messages, bool $newline = false, int $options = self::OUTPUT_NORMAL)
{
// do nothing
}

View File

@ -63,7 +63,7 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function setDecorated($decorated)
public function setDecorated(bool $decorated)
{
$this->formatter->setDecorated($decorated);
}
@ -79,9 +79,9 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function setVerbosity($level)
public function setVerbosity(int $level)
{
$this->verbosity = (int) $level;
$this->verbosity = $level;
}
/**
@ -127,7 +127,7 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function writeln($messages, $options = self::OUTPUT_NORMAL)
public function writeln($messages, int $options = self::OUTPUT_NORMAL)
{
$this->write($messages, true, $options);
}
@ -135,7 +135,7 @@ abstract class Output implements OutputInterface
/**
* {@inheritdoc}
*/
public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL)
public function write($messages, bool $newline = false, int $options = self::OUTPUT_NORMAL)
{
if (!is_iterable($messages)) {
$messages = [$messages];
@ -169,9 +169,6 @@ abstract class Output implements OutputInterface
/**
* Writes a message to the output.
*
* @param string $message A message to write to the output
* @param bool $newline Whether to add a newline or not
*/
abstract protected function doWrite($message, $newline);
abstract protected function doWrite(string $message, bool $newline);
}

View File

@ -37,7 +37,7 @@ interface OutputInterface
* @param bool $newline Whether to add a newline
* @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
*/
public function write($messages, $newline = false, $options = 0);
public function write($messages, bool $newline = false, int $options = 0);
/**
* Writes a message to the output and adds a newline at the end.
@ -45,14 +45,12 @@ interface OutputInterface
* @param string|iterable $messages The message as an iterable of strings or a single string
* @param int $options A bitmask of options (one of the OUTPUT or VERBOSITY constants), 0 is considered the same as self::OUTPUT_NORMAL | self::VERBOSITY_NORMAL
*/
public function writeln($messages, $options = 0);
public function writeln($messages, int $options = 0);
/**
* Sets the verbosity of the output.
*
* @param int $level The level of verbosity (one of the VERBOSITY constants)
*/
public function setVerbosity($level);
public function setVerbosity(int $level);
/**
* Gets the current verbosity of the output.
@ -91,10 +89,8 @@ interface OutputInterface
/**
* Sets the decorated flag.
*
* @param bool $decorated Whether to decorate the messages
*/
public function setDecorated($decorated);
public function setDecorated(bool $decorated);
/**
* Gets the decorated flag.

View File

@ -68,7 +68,7 @@ class StreamOutput extends Output
/**
* {@inheritdoc}
*/
protected function doWrite($message, $newline)
protected function doWrite(string $message, bool $newline)
{
if ($newline) {
$message .= PHP_EOL;

View File

@ -33,7 +33,7 @@ abstract class OutputStyle implements OutputInterface, StyleInterface
/**
* {@inheritdoc}
*/
public function newLine($count = 1)
public function newLine(int $count = 1)
{
$this->output->write(str_repeat(PHP_EOL, $count));
}
@ -43,7 +43,7 @@ abstract class OutputStyle implements OutputInterface, StyleInterface
*
* @return ProgressBar
*/
public function createProgressBar($max = 0)
public function createProgressBar(int $max = 0)
{
return new ProgressBar($this->output, $max);
}
@ -51,7 +51,7 @@ abstract class OutputStyle implements OutputInterface, StyleInterface
/**
* {@inheritdoc}
*/
public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL)
{
$this->output->write($messages, $newline, $type);
}
@ -59,7 +59,7 @@ abstract class OutputStyle implements OutputInterface, StyleInterface
/**
* {@inheritdoc}
*/
public function writeln($messages, $type = self::OUTPUT_NORMAL)
public function writeln($messages, int $type = self::OUTPUT_NORMAL)
{
$this->output->writeln($messages, $type);
}
@ -67,7 +67,7 @@ abstract class OutputStyle implements OutputInterface, StyleInterface
/**
* {@inheritdoc}
*/
public function setVerbosity($level)
public function setVerbosity(int $level)
{
$this->output->setVerbosity($level);
}
@ -83,7 +83,7 @@ abstract class OutputStyle implements OutputInterface, StyleInterface
/**
* {@inheritdoc}
*/
public function setDecorated($decorated)
public function setDecorated(bool $decorated)
{
$this->output->setDecorated($decorated);
}

View File

@ -20,17 +20,13 @@ interface StyleInterface
{
/**
* Formats a command title.
*
* @param string $message
*/
public function title($message);
public function title(string $message);
/**
* Formats a section title.
*
* @param string $message
*/
public function section($message);
public function section(string $message);
/**
* Formats a list.
@ -87,65 +83,47 @@ interface StyleInterface
/**
* Asks a question.
*
* @param string $question
* @param string|null $default
* @param callable|null $validator
*
* @return mixed
*/
public function ask($question, $default = null, $validator = null);
public function ask(string $question, ?string $default = null, callable $validator = null);
/**
* Asks a question with the user input hidden.
*
* @param string $question
* @param callable|null $validator
*
* @return mixed
*/
public function askHidden($question, $validator = null);
public function askHidden(string $question, callable $validator = null);
/**
* Asks for confirmation.
*
* @param string $question
* @param bool $default
*
* @return bool
*/
public function confirm($question, $default = true);
public function confirm(string $question, bool $default = true);
/**
* Asks a choice question.
*
* @param string $question
* @param array $choices
* @param string|int|null $default
*
* @return mixed
*/
public function choice($question, array $choices, $default = null);
public function choice(string $question, array $choices, $default = null);
/**
* Add newline(s).
*
* @param int $count The number of newlines
*/
public function newLine($count = 1);
public function newLine(int $count = 1);
/**
* Starts the progress output.
*
* @param int $max Maximum steps (0 if unknown)
*/
public function progressStart($max = 0);
public function progressStart(int $max = 0);
/**
* Advances the progress output X steps.
*
* @param int $step Number of steps to advance
*/
public function progressAdvance($step = 1);
public function progressAdvance(int $step = 1);
/**
* Finishes the progress output.

View File

@ -55,13 +55,8 @@ class SymfonyStyle extends OutputStyle
* Formats a message as a block of text.
*
* @param string|array $messages The message to write in the block
* @param string|null $type The block type (added in [] on first line)
* @param string|null $style The style to apply to the whole block
* @param string $prefix The prefix for the block
* @param bool $padding Whether to add vertical padding
* @param bool $escape Whether to escape the message
*/
public function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = true)
public function block($messages, ?string $type = null, ?string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true)
{
$messages = \is_array($messages) ? array_values($messages) : [$messages];
@ -73,7 +68,7 @@ class SymfonyStyle extends OutputStyle
/**
* {@inheritdoc}
*/
public function title($message)
public function title(string $message)
{
$this->autoPrependBlock();
$this->writeln([
@ -86,7 +81,7 @@ class SymfonyStyle extends OutputStyle
/**
* {@inheritdoc}
*/
public function section($message)
public function section(string $message)
{
$this->autoPrependBlock();
$this->writeln([
@ -193,7 +188,7 @@ class SymfonyStyle extends OutputStyle
/**
* {@inheritdoc}
*/
public function ask($question, $default = null, $validator = null)
public function ask(string $question, ?string $default = null, $validator = null)
{
$question = new Question($question, $default);
$question->setValidator($validator);
@ -204,7 +199,7 @@ class SymfonyStyle extends OutputStyle
/**
* {@inheritdoc}
*/
public function askHidden($question, $validator = null)
public function askHidden(string $question, $validator = null)
{
$question = new Question($question);
@ -225,7 +220,7 @@ class SymfonyStyle extends OutputStyle
/**
* {@inheritdoc}
*/
public function choice($question, array $choices, $default = null)
public function choice(string $question, array $choices, $default = null)
{
if (null !== $default) {
$values = array_flip($choices);
@ -238,7 +233,7 @@ class SymfonyStyle extends OutputStyle
/**
* {@inheritdoc}
*/
public function progressStart($max = 0)
public function progressStart(int $max = 0)
{
$this->progressBar = $this->createProgressBar($max);
$this->progressBar->start();
@ -247,7 +242,7 @@ class SymfonyStyle extends OutputStyle
/**
* {@inheritdoc}
*/
public function progressAdvance($step = 1)
public function progressAdvance(int $step = 1)
{
$this->getProgressBar()->advance($step);
}
@ -265,7 +260,7 @@ class SymfonyStyle extends OutputStyle
/**
* {@inheritdoc}
*/
public function createProgressBar($max = 0)
public function createProgressBar(int $max = 0)
{
$progressBar = parent::createProgressBar($max);
@ -304,7 +299,7 @@ class SymfonyStyle extends OutputStyle
/**
* {@inheritdoc}
*/
public function writeln($messages, $type = self::OUTPUT_NORMAL)
public function writeln($messages, int $type = self::OUTPUT_NORMAL)
{
if (!is_iterable($messages)) {
$messages = [$messages];
@ -319,7 +314,7 @@ class SymfonyStyle extends OutputStyle
/**
* {@inheritdoc}
*/
public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL)
{
if (!is_iterable($messages)) {
$messages = [$messages];
@ -334,7 +329,7 @@ class SymfonyStyle extends OutputStyle
/**
* {@inheritdoc}
*/
public function newLine($count = 1)
public function newLine(int $count = 1)
{
parent::newLine($count);
$this->bufferedOutput->write(str_repeat("\n", $count));

View File

@ -47,12 +47,9 @@ class ApplicationTester
* * verbosity: Sets the output verbosity flag
* * capture_stderr_separately: Make output of stdOut and stdErr separately available
*
* @param array $input An array of arguments and options
* @param array $options An array of options
*
* @return int The command exit code
*/
public function run(array $input, $options = [])
public function run(array $input, array $options = [])
{
$this->input = new ArrayInput($input);
if (isset($options['interactive'])) {

View File

@ -29,11 +29,9 @@ trait TesterTrait
/**
* Gets the display returned by the last execution of the command or application.
*
* @param bool $normalize Whether to normalize end of lines to \n or not
*
* @return string The display
*/
public function getDisplay($normalize = false)
public function getDisplay(bool $normalize = false)
{
if (null === $this->output) {
throw new \RuntimeException('Output not initialized, did you execute the command before requesting the display?');
@ -57,7 +55,7 @@ trait TesterTrait
*
* @return string
*/
public function getErrorOutput($normalize = false)
public function getErrorOutput(bool $normalize = false)
{
if (!$this->captureStreamsIndependently) {
throw new \LogicException('The error output is not available when the tester is run without "capture_stderr_separately" option set.');

View File

@ -185,13 +185,6 @@ class CommandTest extends TestCase
$this->assertEquals(['name1'], $command->getAliases(), '->setAliases() sets the aliases');
}
public function testSetAliasesNull()
{
$command = new \TestCommand();
$this->expectException('InvalidArgumentException');
$command->setAliases(null);
}
public function testGetSynopsis()
{
$command = new \TestCommand();

View File

@ -23,6 +23,6 @@ class TableStyleTest extends TestCase
public function testSetPadTypeWithInvalidType()
{
$style = new TableStyle();
$style->setPadType('TEST');
$style->setPadType(31);
}
}

View File

@ -182,7 +182,7 @@ class TestOutput extends Output
$this->output = '';
}
protected function doWrite($message, $newline)
protected function doWrite(string $message, bool $newline)
{
$this->output .= $message.($newline ? "\n" : '');
}