From 42dbad2f51e2440ef59d3afc18051ac9070240b9 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 19 May 2021 15:18:37 +0200 Subject: [PATCH 001/215] Bump Symfony 6 to PHP 8 --- composer.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/composer.json b/composer.json index fa720142a..d0fc10a55 100644 --- a/composer.json +++ b/composer.json @@ -16,11 +16,9 @@ } ], "require": { - "php": ">=7.2.5", + "php": ">=8.0.2", "symfony/deprecation-contracts": "^2.1", "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php73": "^1.8", - "symfony/polyfill-php80": "^1.15", "symfony/service-contracts": "^1.1|^2", "symfony/string": "^5.1" }, From 5fc79742ca9ede9aff576782da6c3d864923feda Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 20 May 2021 14:59:02 +0200 Subject: [PATCH 002/215] Bump symfony/* deps to ^5.4|^6.0 --- composer.json | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/composer.json b/composer.json index 46f8a4403..aa0b2d10a 100644 --- a/composer.json +++ b/composer.json @@ -20,15 +20,15 @@ "symfony/deprecation-contracts": "^2.1", "symfony/polyfill-mbstring": "~1.0", "symfony/service-contracts": "^1.1|^2", - "symfony/string": "^5.1|^6.0" + "symfony/string": "^5.4|^6.0" }, "require-dev": { - "symfony/config": "^4.4|^5.0|^6.0", - "symfony/event-dispatcher": "^4.4|^5.0|^6.0", - "symfony/dependency-injection": "^4.4|^5.0|^6.0", - "symfony/lock": "^4.4|^5.0|^6.0", - "symfony/process": "^4.4|^5.0|^6.0", - "symfony/var-dumper": "^4.4|^5.0|^6.0", + "symfony/config": "^5.4|^6.0", + "symfony/event-dispatcher": "^5.4|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/lock": "^5.4|^6.0", + "symfony/process": "^5.4|^6.0", + "symfony/var-dumper": "^5.4|^6.0", "psr/log": "~1.0" }, "provide": { @@ -41,11 +41,11 @@ "psr/log": "For using the console logger" }, "conflict": { - "symfony/dependency-injection": "<4.4", - "symfony/dotenv": "<5.1", - "symfony/event-dispatcher": "<4.4", - "symfony/lock": "<4.4", - "symfony/process": "<4.4" + "symfony/dependency-injection": "<5.4", + "symfony/dotenv": "<5.4", + "symfony/event-dispatcher": "<5.4", + "symfony/lock": "<5.4", + "symfony/process": "<5.4" }, "autoload": { "psr-4": { "Symfony\\Component\\Console\\": "" }, From 0bb26665b6de71dbc26ddcc475f4bb49c15035c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Wed, 19 May 2021 20:52:47 +0200 Subject: [PATCH 003/215] Remove constraint for PHP < 8 --- Command/Command.php | 4 ++-- Tests/Command/CommandTest.php | 3 --- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/Command/Command.php b/Command/Command.php index e35ae51eb..8e869f231 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -67,7 +67,7 @@ public static function getDefaultName() { $class = static::class; - if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) { + if ($attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) { return $attribute[0]->newInstance()->name; } @@ -83,7 +83,7 @@ public static function getDefaultDescription(): ?string { $class = static::class; - if (\PHP_VERSION_ID >= 80000 && $attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) { + if ($attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) { return $attribute[0]->newInstance()->description; } diff --git a/Tests/Command/CommandTest.php b/Tests/Command/CommandTest.php index fad1f3458..0f54e7a4d 100644 --- a/Tests/Command/CommandTest.php +++ b/Tests/Command/CommandTest.php @@ -406,9 +406,6 @@ public function testSetCodeWithStaticAnonymousFunction() $this->assertEquals('interact called'.\PHP_EOL.'not bound'.\PHP_EOL, $tester->getDisplay()); } - /** - * @requires PHP 8 - */ public function testCommandAttribute() { $this->assertSame('|foo|f', Php8Command::getDefaultName()); From ce494b9b8125407d615524d747b192da96251591 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Sch=C3=A4dlich?= Date: Thu, 20 May 2021 07:16:46 +0100 Subject: [PATCH 004/215] [Console] Remove console deprecations --- CHANGELOG.md | 8 +++++ Command/Command.php | 5 +-- DependencyInjection/AddConsoleCommandPass.php | 31 +++++-------------- Helper/Helper.php | 24 -------------- Tests/Command/CommandTest.php | 2 +- Tests/Fixtures/BarHiddenCommand.php | 2 +- Tests/Fixtures/DescriptorCommand3.php | 2 +- Tests/Fixtures/FooHiddenCommand.php | 2 +- composer.json | 1 - 9 files changed, 20 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 880856386..9b39f52c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ CHANGELOG ========= +6.0 +--- + + * `Command::setHidden()` has a default value (`true`) for `$hidden` parameter and is final + * Remove `Helper::strlen()`, use `Helper::width()` instead + * Remove `Helper::strlenWithoutDecoration()`, use `Helper::removeDecoration()` instead + * `AddConsoleCommandPass` can not be configured anymore + 5.3 --- diff --git a/Command/Command.php b/Command/Command.php index e35ae51eb..8ffa95fc1 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -495,13 +495,10 @@ public function getName() /** * @param bool $hidden Whether or not the command should be hidden from the list of commands - * The default value will be true in Symfony 6.0 * * @return Command The current instance - * - * @final since Symfony 5.1 */ - public function setHidden(bool $hidden /*= true*/) + final public function setHidden(bool $hidden = true): static { $this->hidden = $hidden; diff --git a/DependencyInjection/AddConsoleCommandPass.php b/DependencyInjection/AddConsoleCommandPass.php index 743e306d0..efaf39a2c 100644 --- a/DependencyInjection/AddConsoleCommandPass.php +++ b/DependencyInjection/AddConsoleCommandPass.php @@ -29,33 +29,16 @@ */ class AddConsoleCommandPass implements CompilerPassInterface { - private $commandLoaderServiceId; - private $commandTag; - private $noPreloadTag; - private $privateTagName; - - public function __construct(string $commandLoaderServiceId = 'console.command_loader', string $commandTag = 'console.command', string $noPreloadTag = 'container.no_preload', string $privateTagName = 'container.private') - { - if (0 < \func_num_args()) { - trigger_deprecation('symfony/console', '5.3', 'Configuring "%s" is deprecated.', __CLASS__); - } - - $this->commandLoaderServiceId = $commandLoaderServiceId; - $this->commandTag = $commandTag; - $this->noPreloadTag = $noPreloadTag; - $this->privateTagName = $privateTagName; - } - public function process(ContainerBuilder $container) { - $commandServices = $container->findTaggedServiceIds($this->commandTag, true); + $commandServices = $container->findTaggedServiceIds('console.command', true); $lazyCommandMap = []; $lazyCommandRefs = []; $serviceIds = []; foreach ($commandServices as $id => $tags) { $definition = $container->getDefinition($id); - $definition->addTag($this->noPreloadTag); + $definition->addTag('container.no_preload'); $class = $container->getParameterBag()->resolveValue($definition->getClass()); if (isset($tags[0]['command'])) { @@ -65,7 +48,7 @@ public function process(ContainerBuilder $container) throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); } if (!$r->isSubclassOf(Command::class)) { - throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); + throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, 'console.command', Command::class)); } $aliases = $class::getDefaultName(); } @@ -78,7 +61,7 @@ public function process(ContainerBuilder $container) } if (null === $commandName) { - if (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag($this->privateTagName)) { + if (!$definition->isPublic() || $definition->isPrivate() || $definition->hasTag('container.private')) { $commandId = 'console.command.public_alias.'.$id; $container->setAlias($commandId, $id)->setPublic(true); $id = $commandId; @@ -122,7 +105,7 @@ public function process(ContainerBuilder $container) throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id)); } if (!$r->isSubclassOf(Command::class)) { - throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class)); + throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, 'console.command', Command::class)); } $description = $class::getDefaultDescription(); } @@ -138,9 +121,9 @@ public function process(ContainerBuilder $container) } $container - ->register($this->commandLoaderServiceId, ContainerCommandLoader::class) + ->register('console.command_loader', ContainerCommandLoader::class) ->setPublic(true) - ->addTag($this->noPreloadTag) + ->addTag('container.no_preload') ->setArguments([ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap]); $container->setParameter('console.command.ids', $serviceIds); diff --git a/Helper/Helper.php b/Helper/Helper.php index 881b4dc4f..320a73d80 100644 --- a/Helper/Helper.php +++ b/Helper/Helper.php @@ -39,20 +39,6 @@ public function getHelperSet() return $this->helperSet; } - /** - * Returns the length of a string, using mb_strwidth if it is available. - * - * @deprecated since 5.3 - * - * @return int The length of the string - */ - public static function strlen(?string $string) - { - trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::width() or Helper::length() instead.', __METHOD__); - - return self::width($string); - } - /** * Returns the width of a string, using mb_strwidth if it is available. * The width is how many characters positions the string will use. @@ -153,16 +139,6 @@ public static function formatMemory(int $memory) return sprintf('%d B', $memory); } - /** - * @deprecated since 5.3 - */ - public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, ?string $string) - { - trigger_deprecation('symfony/console', '5.3', 'Method "%s()" is deprecated and will be removed in Symfony 6.0. Use Helper::removeDecoration() instead.', __METHOD__); - - return self::width(self::removeDecoration($formatter, $string)); - } - public static function removeDecoration(OutputFormatterInterface $formatter, ?string $string) { $isDecorated = $formatter->isDecorated(); diff --git a/Tests/Command/CommandTest.php b/Tests/Command/CommandTest.php index fad1f3458..74c2708a7 100644 --- a/Tests/Command/CommandTest.php +++ b/Tests/Command/CommandTest.php @@ -96,7 +96,7 @@ public function testAddOption() public function testSetHidden() { $command = new \TestCommand(); - $command->setHidden(true); + $command->setHidden(); $this->assertTrue($command->isHidden()); } diff --git a/Tests/Fixtures/BarHiddenCommand.php b/Tests/Fixtures/BarHiddenCommand.php index 58af8d816..87add7f8e 100644 --- a/Tests/Fixtures/BarHiddenCommand.php +++ b/Tests/Fixtures/BarHiddenCommand.php @@ -11,7 +11,7 @@ protected function configure() $this ->setName('bar:hidden') ->setAliases(['abarhidden']) - ->setHidden(true) + ->setHidden() ; } diff --git a/Tests/Fixtures/DescriptorCommand3.php b/Tests/Fixtures/DescriptorCommand3.php index 77f92e233..5dbb4eb5d 100644 --- a/Tests/Fixtures/DescriptorCommand3.php +++ b/Tests/Fixtures/DescriptorCommand3.php @@ -21,7 +21,7 @@ protected function configure() ->setName('descriptor:command3') ->setDescription('command 3 description') ->setHelp('command 3 help') - ->setHidden(true) + ->setHidden() ; } } diff --git a/Tests/Fixtures/FooHiddenCommand.php b/Tests/Fixtures/FooHiddenCommand.php index 68e495b76..94c7d74ad 100644 --- a/Tests/Fixtures/FooHiddenCommand.php +++ b/Tests/Fixtures/FooHiddenCommand.php @@ -11,7 +11,7 @@ protected function configure() $this ->setName('foo:hidden') ->setAliases(['afoohidden']) - ->setHidden(true) + ->setHidden() ; } diff --git a/composer.json b/composer.json index 46f8a4403..ca1235a82 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,6 @@ ], "require": { "php": ">=8.0.2", - "symfony/deprecation-contracts": "^2.1", "symfony/polyfill-mbstring": "~1.0", "symfony/service-contracts": "^1.1|^2", "symfony/string": "^5.1|^6.0" From 6f75e5efff4cb0074b415e2a2b295e3609df81ef Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 28 May 2021 09:59:09 +0200 Subject: [PATCH 005/215] Leverage Stringable --- EventListener/ErrorListener.php | 2 +- Helper/Table.php | 2 +- Logger/ConsoleLogger.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/EventListener/ErrorListener.php b/EventListener/ErrorListener.php index 897d9853f..5f34ca4c0 100644 --- a/EventListener/ErrorListener.php +++ b/EventListener/ErrorListener.php @@ -82,7 +82,7 @@ private static function getInputString(ConsoleEvent $event): ?string $commandName = $event->getCommand() ? $event->getCommand()->getName() : null; $input = $event->getInput(); - if (method_exists($input, '__toString')) { + if ($input instanceof \Stringable) { if ($commandName) { return str_replace(["'$commandName'", "\"$commandName\""], $commandName, (string) $input); } diff --git a/Helper/Table.php b/Helper/Table.php index 4bf3ed396..c72ff2500 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -631,7 +631,7 @@ private function fillNextRows(array $rows, int $line): array { $unmergedRows = []; foreach ($rows[$line] as $column => $cell) { - if (null !== $cell && !$cell instanceof TableCell && !is_scalar($cell) && !(\is_object($cell) && method_exists($cell, '__toString'))) { + if (null !== $cell && !$cell instanceof TableCell && !is_scalar($cell) && !$cell instanceof \Stringable) { throw new InvalidArgumentException(sprintf('A cell must be a TableCell, a scalar or an object implementing "__toString()", "%s" given.', get_debug_type($cell))); } if ($cell instanceof TableCell && $cell->getRowspan() > 1) { diff --git a/Logger/ConsoleLogger.php b/Logger/ConsoleLogger.php index 4a0315656..0379b2036 100644 --- a/Logger/ConsoleLogger.php +++ b/Logger/ConsoleLogger.php @@ -110,7 +110,7 @@ private function interpolate(string $message, array $context): string $replacements = []; foreach ($context as $key => $val) { - if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) { + if (null === $val || is_scalar($val) || $val instanceof \Stringable) { $replacements["{{$key}}"] = $val; } elseif ($val instanceof \DateTimeInterface) { $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339); From 8148803b8f259706e90a2c494e1df4dfe6b7534e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Fri, 28 May 2021 17:52:26 +0200 Subject: [PATCH 006/215] Add return type to __toString() --- Helper/TableCell.php | 4 +--- Input/ArgvInput.php | 4 +--- Input/ArrayInput.php | 4 +--- Tests/Question/ChoiceQuestionTest.php | 2 +- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Helper/TableCell.php b/Helper/TableCell.php index 1a7bc6ede..6abeacb09 100644 --- a/Helper/TableCell.php +++ b/Helper/TableCell.php @@ -43,10 +43,8 @@ public function __construct(string $value = '', array $options = []) /** * Returns the cell value. - * - * @return string */ - public function __toString() + public function __toString(): string { return $this->value; } diff --git a/Input/ArgvInput.php b/Input/ArgvInput.php index 9dd4de780..eb486fa3a 100644 --- a/Input/ArgvInput.php +++ b/Input/ArgvInput.php @@ -349,10 +349,8 @@ public function getParameterOption($values, $default = false, bool $onlyParams = /** * Returns a stringified representation of the args passed to the command. - * - * @return string */ - public function __toString() + public function __toString(): string { $tokens = array_map(function ($token) { if (preg_match('{^(-[^=]+=)(.+)}', $token, $match)) { diff --git a/Input/ArrayInput.php b/Input/ArrayInput.php index 89a7f113f..5c2ae3dda 100644 --- a/Input/ArrayInput.php +++ b/Input/ArrayInput.php @@ -100,10 +100,8 @@ public function getParameterOption($values, $default = false, bool $onlyParams = /** * Returns a stringified representation of the args passed to the command. - * - * @return string */ - public function __toString() + public function __toString(): string { $params = []; foreach ($this->parameters as $param => $val) { diff --git a/Tests/Question/ChoiceQuestionTest.php b/Tests/Question/ChoiceQuestionTest.php index 18063eaac..8a48cfcf1 100644 --- a/Tests/Question/ChoiceQuestionTest.php +++ b/Tests/Question/ChoiceQuestionTest.php @@ -145,7 +145,7 @@ public function __construct(string $string) $this->string = $string; } - public function __toString() + public function __toString(): string { return $this->string; } From 5754a3d106f122b67cc7fe37ebdfe96d4175bc36 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 2 Jun 2021 18:09:43 +0200 Subject: [PATCH 007/215] Update phpunit.xml.dist files for phpunit >= 9.3 --- phpunit.xml.dist | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 15e7e52a9..0e96921be 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,7 +1,7 @@ - - + + ./ - - ./Resources - ./Tests - ./vendor - - - + + + ./Resources + ./Tests + ./vendor + + From fbe9fdcfd458d268caa122fd01ef1367cc017bcc Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 30 Jun 2021 09:01:18 +0200 Subject: [PATCH 008/215] [Console] add union types --- Command/Command.php | 18 +++++++------- Command/LazyCommand.php | 6 ++--- Descriptor/Descriptor.php | 2 +- Descriptor/MarkdownDescriptor.php | 2 +- Descriptor/TextDescriptor.php | 4 +--- Helper/Dumper.php | 2 +- Helper/FormatterHelper.php | 4 +--- Helper/Helper.php | 2 +- Helper/ProcessHelper.php | 12 ++-------- Helper/QuestionHelper.php | 4 +--- Helper/Table.php | 26 ++++++++------------ Input/ArgvInput.php | 8 +++---- Input/ArrayInput.php | 13 ++++------ Input/Input.php | 6 ++--- Input/InputArgument.php | 16 ++++++------- Input/InputDefinition.php | 8 ++----- Input/InputInterface.php | 20 ++++++---------- Input/InputOption.php | 16 +++++-------- Output/ConsoleSectionOutput.php | 6 ++--- Output/NullOutput.php | 4 ++-- Output/Output.php | 6 ++--- Output/OutputInterface.php | 12 ++++------ Output/TrimmedBufferOutput.php | 2 +- Question/ChoiceQuestion.php | 2 +- Question/Question.php | 10 +++----- Style/OutputStyle.php | 4 ++-- Style/StyleInterface.php | 28 ++++++---------------- Style/SymfonyStyle.php | 40 +++++++++++++------------------ 28 files changed, 106 insertions(+), 177 deletions(-) diff --git a/Command/Command.php b/Command/Command.php index 72213a839..946c31374 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -371,11 +371,9 @@ public function mergeApplicationDefinition(bool $mergeArgs = true) /** * Sets an array of argument and option instances. * - * @param array|InputDefinition $definition An array of argument and option instances or a definition instance - * * @return $this */ - public function setDefinition($definition) + public function setDefinition(array|InputDefinition $definition) { if ($definition instanceof InputDefinition) { $this->definition = $definition; @@ -420,14 +418,14 @@ public function getNativeDefinition() /** * Adds an argument. * - * @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) + * @param $mode The argument mode: InputArgument::REQUIRED or InputArgument::OPTIONAL + * @param $default The default value (for InputArgument::OPTIONAL mode only) * * @throws InvalidArgumentException When argument mode is not valid * * @return $this */ - public function addArgument(string $name, int $mode = null, string $description = '', $default = null) + public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null) { $this->definition->addArgument(new InputArgument($name, $mode, $description, $default)); if (null !== $this->fullDefinition) { @@ -440,15 +438,15 @@ public function addArgument(string $name, int $mode = null, string $description /** * Adds an option. * - * @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[]|bool|null $default The default value (must be null for InputOption::VALUE_NONE) + * @param $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts + * @param $mode The option mode: One of the InputOption::VALUE_* constants + * @param $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(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null) + public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null) { $this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default)); if (null !== $this->fullDefinition) { diff --git a/Command/LazyCommand.php b/Command/LazyCommand.php index 763133e81..5751be406 100644 --- a/Command/LazyCommand.php +++ b/Command/LazyCommand.php @@ -90,7 +90,7 @@ public function mergeApplicationDefinition(bool $mergeArgs = true): void /** * @return $this */ - public function setDefinition($definition): self + public function setDefinition(array|InputDefinition $definition): self { $this->getCommand()->setDefinition($definition); @@ -110,7 +110,7 @@ public function getNativeDefinition(): InputDefinition /** * @return $this */ - public function addArgument(string $name, int $mode = null, string $description = '', $default = null): self + public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null): self { $this->getCommand()->addArgument($name, $mode, $description, $default); @@ -120,7 +120,7 @@ public function addArgument(string $name, int $mode = null, string $description /** * @return $this */ - public function addOption(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null): self + public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null): self { $this->getCommand()->addOption($name, $shortcut, $mode, $description, $default); diff --git a/Descriptor/Descriptor.php b/Descriptor/Descriptor.php index 2ecc59e4e..a3648301f 100644 --- a/Descriptor/Descriptor.php +++ b/Descriptor/Descriptor.php @@ -34,7 +34,7 @@ abstract class Descriptor implements DescriptorInterface /** * {@inheritdoc} */ - public function describe(OutputInterface $output, $object, array $options = []) + public function describe(OutputInterface $output, object $object, array $options = []) { $this->output = $output; diff --git a/Descriptor/MarkdownDescriptor.php b/Descriptor/MarkdownDescriptor.php index 04d6c8a76..21ceca6c2 100644 --- a/Descriptor/MarkdownDescriptor.php +++ b/Descriptor/MarkdownDescriptor.php @@ -31,7 +31,7 @@ class MarkdownDescriptor extends Descriptor /** * {@inheritdoc} */ - public function describe(OutputInterface $output, $object, array $options = []) + public function describe(OutputInterface $output, object $object, array $options = []) { $decorated = $output->isDecorated(); $output->setDecorated(false); diff --git a/Descriptor/TextDescriptor.php b/Descriptor/TextDescriptor.php index fbb140ae7..3f309f5d4 100644 --- a/Descriptor/TextDescriptor.php +++ b/Descriptor/TextDescriptor.php @@ -273,10 +273,8 @@ private function getCommandAliasesText(Command $command): string /** * Formats input option/argument default value. - * - * @param mixed $default */ - private function formatDefaultValue($default): string + private function formatDefaultValue(mixed $default): string { if (\INF === $default) { return 'INF'; diff --git a/Helper/Dumper.php b/Helper/Dumper.php index b013b6c52..cc962e58d 100644 --- a/Helper/Dumper.php +++ b/Helper/Dumper.php @@ -57,7 +57,7 @@ public function __construct(OutputInterface $output, CliDumper $dumper = null, C } } - public function __invoke($var): string + public function __invoke(mixed $var): string { return ($this->handler)($var); } diff --git a/Helper/FormatterHelper.php b/Helper/FormatterHelper.php index a1c33c22d..b6c72b881 100644 --- a/Helper/FormatterHelper.php +++ b/Helper/FormatterHelper.php @@ -33,11 +33,9 @@ public function formatSection(string $section, string $message, string $style = /** * Formats a message as a block of text. * - * @param string|array $messages The message to write in the block - * * @return string The formatter message */ - public function formatBlock($messages, string $style, bool $large = false) + public function formatBlock(string|array $messages, string $style, bool $large = false) { if (!\is_array($messages)) { $messages = [$messages]; diff --git a/Helper/Helper.php b/Helper/Helper.php index 320a73d80..2ad664576 100644 --- a/Helper/Helper.php +++ b/Helper/Helper.php @@ -93,7 +93,7 @@ public static function substr(?string $string, int $from, int $length = null) return mb_substr($string, $from, $length, $encoding); } - public static function formatTime($secs) + public static function formatTime(int|float $secs) { static $timeFormats = [ [0, '< 1 sec'], diff --git a/Helper/ProcessHelper.php b/Helper/ProcessHelper.php index f82c16bae..1b427e8b7 100644 --- a/Helper/ProcessHelper.php +++ b/Helper/ProcessHelper.php @@ -31,10 +31,8 @@ class ProcessHelper extends Helper * @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, string $error = null, callable $callback = null, int $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE): Process + public function run(OutputInterface $output, array|Process $cmd, string $error = null, callable $callback = null, int $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE): Process { if (!class_exists(Process::class)) { throw new \LogicException('The ProcessHelper cannot be run as the Process component is not installed. Try running "compose require symfony/process".'); @@ -50,10 +48,6 @@ public function run(OutputInterface $output, $cmd, string $error = null, callabl $cmd = [$cmd]; } - if (!\is_array($cmd)) { - throw new \TypeError(sprintf('The "command" argument of "%s()" must be an array or a "%s" instance, "%s" given.', __METHOD__, Process::class, get_debug_type($cmd))); - } - if (\is_string($cmd[0] ?? null)) { $process = new Process($cmd); $cmd = []; @@ -96,13 +90,11 @@ public function run(OutputInterface $output, $cmd, string $error = null, callabl * @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 - * * @throws ProcessFailedException * * @see run() */ - public function mustRun(OutputInterface $output, $cmd, string $error = null, callable $callback = null): Process + public function mustRun(OutputInterface $output, string|Process $cmd, string $error = null, callable $callback = null): Process { $process = $this->run($output, $cmd, $error, $callback); diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index becd54019..091b4fd69 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -552,11 +552,9 @@ private function setIOCodepage(): int /** * Sets console I/O to the specified code page and converts the user input. * - * @param string|false $input - * * @return string|false */ - private function resetIOCodepage(int $cp, $input) + private function resetIOCodepage(int $cp, string|false $input) { if (0 !== $cp) { sapi_windows_cp_set($cp); diff --git a/Helper/Table.php b/Helper/Table.php index 680ecbaaf..8022e4fb3 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -133,11 +133,9 @@ public static function getStyleDefinition(string $name) /** * Sets table style. * - * @param TableStyle|string $name The style name or a TableStyle instance - * * @return $this */ - public function setStyle($name) + public function setStyle(TableStyle|string $name) { $this->style = $this->resolveStyle($name); @@ -161,7 +159,7 @@ public function getStyle() * * @return $this */ - public function setColumnStyle(int $columnIndex, $name) + public function setColumnStyle(int $columnIndex, TableStyle|string $name) { $this->columnStyles[$columnIndex] = $this->resolveStyle($name); @@ -254,7 +252,7 @@ public function addRows(array $rows) return $this; } - public function addRow($row) + public function addRow(TableSeparator|array $row) { if ($row instanceof TableSeparator) { $this->rows[] = $row; @@ -262,10 +260,6 @@ public function addRow($row) return $this; } - if (!\is_array($row)) { - throw new InvalidArgumentException('A row must be an array or a TableSeparator instance.'); - } - $this->rows[] = array_values($row); return $this; @@ -274,7 +268,7 @@ public function addRow($row) /** * Adds a row to the table, and re-renders the table. */ - public function appendRow($row): self + public function appendRow(TableSeparator|array $row): self { if (!$this->output instanceof ConsoleSectionOutput) { throw new RuntimeException(sprintf('Output should be an instance of "%s" when calling "%s".', ConsoleSectionOutput::class, __METHOD__)); @@ -290,7 +284,7 @@ public function appendRow($row): self return $this; } - public function setRow($column, array $row) + public function setRow(int|string $column, array $row) { $this->rows[$column] = $row; @@ -596,11 +590,11 @@ private function buildTableRows(array $rows): TableRows return new TableRows(function () use ($rows, $unmergedRows): \Traversable { foreach ($rows as $rowKey => $row) { - yield $this->fillCells($row); + yield $row instanceof TableSeparator ? $row : $this->fillCells($row); if (isset($unmergedRows[$rowKey])) { - foreach ($unmergedRows[$rowKey] as $unmergedRow) { - yield $this->fillCells($unmergedRow); + foreach ($unmergedRows[$rowKey] as $row) { + yield $row instanceof TableSeparator ? $row : $this->fillCells($row); } } } @@ -681,7 +675,7 @@ private function fillNextRows(array $rows, int $line): array /** * fill cells for a row that contains colspan > 1. */ - private function fillCells($row) + private function fillCells(iterable $row) { $newRow = []; @@ -848,7 +842,7 @@ private static function initStyles(): array ]; } - private function resolveStyle($name): TableStyle + private function resolveStyle(TableStyle|string $name): TableStyle { if ($name instanceof TableStyle) { return $name; diff --git a/Input/ArgvInput.php b/Input/ArgvInput.php index eb486fa3a..c114b0116 100644 --- a/Input/ArgvInput.php +++ b/Input/ArgvInput.php @@ -192,7 +192,7 @@ private function parseArgument(string $token) * * @throws RuntimeException When option given doesn't exist */ - private function addShortOption(string $shortcut, $value) + private function addShortOption(string $shortcut, mixed $value) { if (!$this->definition->hasShortcut($shortcut)) { throw new RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut)); @@ -206,7 +206,7 @@ private function addShortOption(string $shortcut, $value) * * @throws RuntimeException When option given doesn't exist */ - private function addLongOption(string $name, $value) + private function addLongOption(string $name, mixed $value) { if (!$this->definition->hasOption($name)) { if (!$this->definition->hasNegation($name)) { @@ -294,7 +294,7 @@ public function getFirstArgument() /** * {@inheritdoc} */ - public function hasParameterOption($values, bool $onlyParams = false) + public function hasParameterOption(string|array $values, bool $onlyParams = false) { $values = (array) $values; @@ -319,7 +319,7 @@ public function hasParameterOption($values, bool $onlyParams = false) /** * {@inheritdoc} */ - public function getParameterOption($values, $default = false, bool $onlyParams = false) + public function getParameterOption(string|array $values, mixed $default = false, bool $onlyParams = false) { $values = (array) $values; $tokens = $this->tokens; diff --git a/Input/ArrayInput.php b/Input/ArrayInput.php index 5c2ae3dda..c2adeea1e 100644 --- a/Input/ArrayInput.php +++ b/Input/ArrayInput.php @@ -53,7 +53,7 @@ public function getFirstArgument() /** * {@inheritdoc} */ - public function hasParameterOption($values, bool $onlyParams = false) + public function hasParameterOption(string|array $values, bool $onlyParams = false) { $values = (array) $values; @@ -77,7 +77,7 @@ public function hasParameterOption($values, bool $onlyParams = false) /** * {@inheritdoc} */ - public function getParameterOption($values, $default = false, bool $onlyParams = false) + public function getParameterOption(string|array $values, mixed $default = false, bool $onlyParams = false) { $values = (array) $values; @@ -146,7 +146,7 @@ protected function parse() * * @throws InvalidOptionException When option given doesn't exist */ - private function addShortOption(string $shortcut, $value) + private function addShortOption(string $shortcut, mixed $value) { if (!$this->definition->hasShortcut($shortcut)) { throw new InvalidOptionException(sprintf('The "-%s" option does not exist.', $shortcut)); @@ -161,7 +161,7 @@ private function addShortOption(string $shortcut, $value) * @throws InvalidOptionException When option given doesn't exist * @throws InvalidOptionException When a required value is missing */ - private function addLongOption(string $name, $value) + private function addLongOption(string $name, mixed $value) { if (!$this->definition->hasOption($name)) { if (!$this->definition->hasNegation($name)) { @@ -192,12 +192,9 @@ private function addLongOption(string $name, $value) /** * Adds an argument value. * - * @param string|int $name The argument name - * @param mixed $value The value for the argument - * * @throws InvalidArgumentException When argument given doesn't exist */ - private function addArgument($name, $value) + private function addArgument(string|int $name, mixed $value) { if (!$this->definition->hasArgument($name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); diff --git a/Input/Input.php b/Input/Input.php index 3b054c4b6..cebb3fa63 100644 --- a/Input/Input.php +++ b/Input/Input.php @@ -116,7 +116,7 @@ public function getArgument(string $name) /** * {@inheritdoc} */ - public function setArgument(string $name, $value) + public function setArgument(string $name, mixed $value) { if (!$this->definition->hasArgument($name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); @@ -128,7 +128,7 @@ public function setArgument(string $name, $value) /** * {@inheritdoc} */ - public function hasArgument($name) + public function hasArgument(string|int $name) { return $this->definition->hasArgument($name); } @@ -164,7 +164,7 @@ public function getOption(string $name) /** * {@inheritdoc} */ - public function setOption(string $name, $value) + public function setOption(string $name, mixed $value) { if ($this->definition->hasNegation($name)) { $this->options[$this->definition->negationToName($name)] = !$value; diff --git a/Input/InputArgument.php b/Input/InputArgument.php index 140c86d0e..333907228 100644 --- a/Input/InputArgument.php +++ b/Input/InputArgument.php @@ -31,14 +31,14 @@ class InputArgument private $description; /** - * @param string $name The argument name - * @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL - * @param string $description A description text - * @param string|string[]|null $default The default value (for self::OPTIONAL mode only) + * @param $name The argument name + * @param $mode The argument mode: self::REQUIRED or self::OPTIONAL + * @param $description A description text + * @param $default The default value (for self::OPTIONAL mode only) * * @throws InvalidArgumentException When argument mode is not valid */ - public function __construct(string $name, int $mode = null, string $description = '', $default = null) + public function __construct(string $name, int $mode = null, string $description = '', mixed $default = null) { if (null === $mode) { $mode = self::OPTIONAL; @@ -86,11 +86,9 @@ public function isArray() /** * Sets the default value. * - * @param string|string[]|null $default The default value - * * @throws LogicException When incorrect default value is given */ - public function setDefault($default = null) + public function setDefault(mixed $default = null) { if (self::REQUIRED === $this->mode && null !== $default) { throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.'); @@ -110,7 +108,7 @@ public function setDefault($default = null) /** * Returns the default value. * - * @return string|string[]|null The default value + * @return mixed */ public function getDefault() { diff --git a/Input/InputDefinition.php b/Input/InputDefinition.php index f8f8d250f..84f7b3f7d 100644 --- a/Input/InputDefinition.php +++ b/Input/InputDefinition.php @@ -124,13 +124,11 @@ public function addArgument(InputArgument $argument) /** * Returns an InputArgument by name or by position. * - * @param string|int $name The InputArgument name or position - * * @return InputArgument An InputArgument object * * @throws InvalidArgumentException When argument given doesn't exist */ - public function getArgument($name) + public function getArgument(string|int $name) { if (!$this->hasArgument($name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); @@ -144,11 +142,9 @@ public function getArgument($name) /** * Returns true if an InputArgument object exists by name or position. * - * @param string|int $name The InputArgument name or position - * * @return bool true if the InputArgument object exists, false otherwise */ - public function hasArgument($name) + public function hasArgument(string|int $name) { $arguments = \is_int($name) ? array_values($this->arguments) : $this->arguments; diff --git a/Input/InputInterface.php b/Input/InputInterface.php index f6ad722a0..4dd1f6a4e 100644 --- a/Input/InputInterface.php +++ b/Input/InputInterface.php @@ -41,7 +41,7 @@ public function getFirstArgument(); * * @return bool true if the value is contained in the raw parameters */ - public function hasParameterOption($values, bool $onlyParams = false); + public function hasParameterOption(string|array $values, bool $onlyParams = false); /** * Returns the value of a raw option (not parsed). @@ -57,7 +57,7 @@ public function hasParameterOption($values, bool $onlyParams = false); * * @return mixed The option value */ - public function getParameterOption($values, $default = false, bool $onlyParams = false); + public function getParameterOption(string|array $values, mixed $default = false, bool $onlyParams = false); /** * Binds the current Input instance with the given arguments and options. @@ -83,7 +83,7 @@ public function getArguments(); /** * Returns the argument value for a given argument name. * - * @return string|string[]|null The argument value + * @return mixed * * @throws InvalidArgumentException When argument given doesn't exist */ @@ -92,20 +92,16 @@ public function getArgument(string $name); /** * Sets an argument value by name. * - * @param string|string[]|null $value The argument value - * * @throws InvalidArgumentException When argument given doesn't exist */ - public function setArgument(string $name, $value); + public function setArgument(string $name, mixed $value); /** * Returns true if an InputArgument object exists by name or position. * - * @param string|int $name The InputArgument name or position - * * @return bool true if the InputArgument object exists, false otherwise */ - public function hasArgument($name); + public function hasArgument(string|int $name); /** * Returns all the given options merged with the default values. @@ -117,7 +113,7 @@ public function getOptions(); /** * Returns the option value for a given option name. * - * @return string|string[]|bool|null The option value + * @return mixed * * @throws InvalidArgumentException When option given doesn't exist */ @@ -126,11 +122,9 @@ public function getOption(string $name); /** * Sets an option value by name. * - * @param string|string[]|bool|null $value The option value - * * @throws InvalidArgumentException When option given doesn't exist */ - public function setOption(string $name, $value); + public function setOption(string $name, mixed $value); /** * Returns true if an InputOption object exists by name. diff --git a/Input/InputOption.php b/Input/InputOption.php index 04fd788a9..bf94782f8 100644 --- a/Input/InputOption.php +++ b/Input/InputOption.php @@ -53,15 +53,13 @@ class InputOption private $description; /** - * @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 VALUE_* constants - * @param string $description A description text - * @param string|string[]|bool|null $default The default value (must be null for self::VALUE_NONE) + * @param $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts + * @param $mode The option mode: One of the VALUE_* constants + * @param $default The default value (must be null for self::VALUE_NONE) * * @throws InvalidArgumentException If option mode is invalid or incompatible */ - public function __construct(string $name, $shortcut = null, int $mode = null, string $description = '', $default = null) + public function __construct(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null) { if (0 === strpos($name, '--')) { $name = substr($name, 2); @@ -177,11 +175,9 @@ public function isNegatable(): bool /** * Sets the default value. * - * @param string|string[]|bool|null $default The default value - * * @throws LogicException When incorrect default value is given */ - public function setDefault($default = null) + public function setDefault(mixed $default = null) { if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) { throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.'); @@ -201,7 +197,7 @@ public function setDefault($default = null) /** * Returns the default value. * - * @return string|string[]|bool|null The default value + * @return mixed */ public function getDefault() { diff --git a/Output/ConsoleSectionOutput.php b/Output/ConsoleSectionOutput.php index 30ddf9496..9d9f02df2 100644 --- a/Output/ConsoleSectionOutput.php +++ b/Output/ConsoleSectionOutput.php @@ -63,10 +63,8 @@ public function clear(int $lines = null) /** * Overwrites the previous output with a new message. - * - * @param array|string $message */ - public function overwrite($message) + public function overwrite(string|iterable $message) { $this->clear(); $this->writeln($message); @@ -92,7 +90,7 @@ public function addContent(string $input) /** * {@inheritdoc} */ - protected function doWrite($message, $newline) + protected function doWrite(string $message, bool $newline) { if (!$this->isDecorated()) { parent::doWrite($message, $newline); diff --git a/Output/NullOutput.php b/Output/NullOutput.php index 3bbe63ea0..4c6f715ac 100644 --- a/Output/NullOutput.php +++ b/Output/NullOutput.php @@ -113,7 +113,7 @@ public function isDebug() /** * {@inheritdoc} */ - public function writeln($messages, int $options = self::OUTPUT_NORMAL) + public function writeln(string|iterable $messages, int $options = self::OUTPUT_NORMAL) { // do nothing } @@ -121,7 +121,7 @@ public function writeln($messages, int $options = self::OUTPUT_NORMAL) /** * {@inheritdoc} */ - public function write($messages, bool $newline = false, int $options = self::OUTPUT_NORMAL) + public function write(string|iterable $messages, bool $newline = false, int $options = self::OUTPUT_NORMAL) { // do nothing } diff --git a/Output/Output.php b/Output/Output.php index 1b01472cd..8fd2cc370 100644 --- a/Output/Output.php +++ b/Output/Output.php @@ -127,7 +127,7 @@ public function isDebug() /** * {@inheritdoc} */ - public function writeln($messages, int $options = self::OUTPUT_NORMAL) + public function writeln(string|iterable $messages, int $options = self::OUTPUT_NORMAL) { $this->write($messages, true, $options); } @@ -135,7 +135,7 @@ public function writeln($messages, int $options = self::OUTPUT_NORMAL) /** * {@inheritdoc} */ - public function write($messages, bool $newline = false, int $options = self::OUTPUT_NORMAL) + public function write(string|iterable $messages, bool $newline = false, int $options = self::OUTPUT_NORMAL) { if (!is_iterable($messages)) { $messages = [$messages]; @@ -163,7 +163,7 @@ public function write($messages, bool $newline = false, int $options = self::OUT break; } - $this->doWrite($message, $newline); + $this->doWrite($message ?? '', $newline); } } diff --git a/Output/OutputInterface.php b/Output/OutputInterface.php index 99ba755fc..1278a1a71 100644 --- a/Output/OutputInterface.php +++ b/Output/OutputInterface.php @@ -33,19 +33,17 @@ interface OutputInterface /** * Writes a message to the output. * - * @param string|iterable $messages The message as an iterable of strings or a single string - * @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 + * @param $newline Whether to add a newline + * @param $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, bool $newline = false, int $options = 0); + public function write(string|iterable $messages, bool $newline = false, int $options = 0); /** * Writes a message to the output and adds a newline at the end. * - * @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 + * @param $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, int $options = 0); + public function writeln(string|iterable $messages, int $options = 0); /** * Sets the verbosity of the output. diff --git a/Output/TrimmedBufferOutput.php b/Output/TrimmedBufferOutput.php index a03aa835f..370f9888d 100644 --- a/Output/TrimmedBufferOutput.php +++ b/Output/TrimmedBufferOutput.php @@ -54,7 +54,7 @@ public function fetch() /** * {@inheritdoc} */ - protected function doWrite($message, $newline) + protected function doWrite(string $message, bool $newline) { $this->buffer .= $message; diff --git a/Question/ChoiceQuestion.php b/Question/ChoiceQuestion.php index 92b6e8663..6f7f6e735 100644 --- a/Question/ChoiceQuestion.php +++ b/Question/ChoiceQuestion.php @@ -30,7 +30,7 @@ class ChoiceQuestion extends Question * @param array $choices The list of available choices * @param mixed $default The default answer to return */ - public function __construct(string $question, array $choices, $default = null) + public function __construct(string $question, array $choices, mixed $default = null) { if (!$choices) { throw new \LogicException('Choice question must have at least 1 choice available.'); diff --git a/Question/Question.php b/Question/Question.php index 0b5eefd54..c93386125 100644 --- a/Question/Question.php +++ b/Question/Question.php @@ -36,7 +36,7 @@ class Question * @param string $question The question to ask to the user * @param mixed $default The default answer to return if the user enters nothing */ - public function __construct(string $question, $default = null) + public function __construct(string $question, mixed $default = null) { $this->question = $question; $this->default = $default; @@ -95,13 +95,11 @@ public function isHidden() /** * Sets whether the user response must be hidden or not. * - * @param bool $hidden - * * @return $this * * @throws LogicException In case the autocompleter is also used */ - public function setHidden($hidden) + public function setHidden(bool $hidden) { if ($this->autocompleterCallback) { throw new LogicException('A hidden question cannot use the autocompleter.'); @@ -125,11 +123,9 @@ public function isHiddenFallback() /** * Sets whether to fallback on non-hidden question if the response can not be hidden. * - * @param bool $fallback - * * @return $this */ - public function setHiddenFallback($fallback) + public function setHiddenFallback(bool $fallback) { $this->hiddenFallback = (bool) $fallback; diff --git a/Style/OutputStyle.php b/Style/OutputStyle.php index 67a98ff07..c1075aa4e 100644 --- a/Style/OutputStyle.php +++ b/Style/OutputStyle.php @@ -49,7 +49,7 @@ public function createProgressBar(int $max = 0) /** * {@inheritdoc} */ - public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) + public function write(string|iterable $messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) { $this->output->write($messages, $newline, $type); } @@ -57,7 +57,7 @@ public function write($messages, bool $newline = false, int $type = self::OUTPUT /** * {@inheritdoc} */ - public function writeln($messages, int $type = self::OUTPUT_NORMAL) + public function writeln(string|iterable $messages, int $type = self::OUTPUT_NORMAL) { $this->output->writeln($messages, $type); } diff --git a/Style/StyleInterface.php b/Style/StyleInterface.php index 38d23b77e..7b0a35927 100644 --- a/Style/StyleInterface.php +++ b/Style/StyleInterface.php @@ -35,45 +35,33 @@ public function listing(array $elements); /** * Formats informational text. - * - * @param string|array $message */ - public function text($message); + public function text(string|array $message); /** * Formats a success result bar. - * - * @param string|array $message */ - public function success($message); + public function success(string|array $message); /** * Formats an error result bar. - * - * @param string|array $message */ - public function error($message); + public function error(string|array $message); /** * Formats an warning result bar. - * - * @param string|array $message */ - public function warning($message); + public function warning(string|array $message); /** * Formats a note admonition. - * - * @param string|array $message */ - public function note($message); + public function note(string|array $message); /** * Formats a caution admonition. - * - * @param string|array $message */ - public function caution($message); + public function caution(string|array $message); /** * Formats a table. @@ -104,11 +92,9 @@ public function confirm(string $question, bool $default = true); /** * Asks a choice question. * - * @param string|int|null $default - * * @return mixed */ - public function choice(string $question, array $choices, $default = null); + public function choice(string $question, array $choices, mixed $default = null); /** * Add newline(s). diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php index 2caebe1a9..10aebf45d 100644 --- a/Style/SymfonyStyle.php +++ b/Style/SymfonyStyle.php @@ -56,10 +56,8 @@ public function __construct(InputInterface $input, OutputInterface $output) /** * Formats a message as a block of text. - * - * @param string|array $messages The message to write in the block */ - public function block($messages, string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true) + public function block(string|array $messages, ?string $type = null, string $style = null, string $prefix = ' ', bool $padding = false, bool $escape = true) { $messages = \is_array($messages) ? array_values($messages) : [$messages]; @@ -111,7 +109,7 @@ public function listing(array $elements) /** * {@inheritdoc} */ - public function text($message) + public function text(string|array $message) { $this->autoPrependText(); @@ -123,10 +121,8 @@ public function text($message) /** * Formats a command comment. - * - * @param string|array $message */ - public function comment($message) + public function comment(string|array $message) { $this->block($message, null, null, ' // ', false, false); } @@ -134,7 +130,7 @@ public function comment($message) /** * {@inheritdoc} */ - public function success($message) + public function success(string|array $message) { $this->block($message, 'OK', 'fg=black;bg=green', ' ', true); } @@ -142,7 +138,7 @@ public function success($message) /** * {@inheritdoc} */ - public function error($message) + public function error(string|array $message) { $this->block($message, 'ERROR', 'fg=white;bg=red', ' ', true); } @@ -150,7 +146,7 @@ public function error($message) /** * {@inheritdoc} */ - public function warning($message) + public function warning(string|array $message) { $this->block($message, 'WARNING', 'fg=black;bg=yellow', ' ', true); } @@ -158,17 +154,15 @@ public function warning($message) /** * {@inheritdoc} */ - public function note($message) + public function note(string|array $message) { $this->block($message, 'NOTE', 'fg=yellow', ' ! '); } /** * Formats an info message. - * - * @param string|array $message */ - public function info($message) + public function info(string|array $message) { $this->block($message, 'INFO', 'fg=green', ' ', true); } @@ -176,7 +170,7 @@ public function info($message) /** * {@inheritdoc} */ - public function caution($message) + public function caution(string|array $message) { $this->block($message, 'CAUTION', 'fg=white;bg=red', ' ! ', true); } @@ -223,10 +217,8 @@ public function horizontalTable(array $headers, array $rows) * * 'A title' * * ['key' => 'value'] * * new TableSeparator() - * - * @param string|array|TableSeparator ...$list */ - public function definitionList(...$list) + public function definitionList(string|array|TableSeparator ...$list) { $style = clone Table::getStyleDefinition('symfony-style-guide'); $style->setCellHeaderFormat('%s'); @@ -264,7 +256,7 @@ public function definitionList(...$list) /** * {@inheritdoc} */ - public function ask(string $question, string $default = null, $validator = null) + public function ask(string $question, string $default = null, callable $validator = null) { $question = new Question($question, $default); $question->setValidator($validator); @@ -275,7 +267,7 @@ public function ask(string $question, string $default = null, $validator = null) /** * {@inheritdoc} */ - public function askHidden(string $question, $validator = null) + public function askHidden(string $question, callable $validator = null) { $question = new Question($question); @@ -288,7 +280,7 @@ public function askHidden(string $question, $validator = null) /** * {@inheritdoc} */ - public function confirm($question, $default = true) + public function confirm(string $question, mixed $default = true) { return $this->askQuestion(new ConfirmationQuestion($question, $default)); } @@ -296,7 +288,7 @@ public function confirm($question, $default = true) /** * {@inheritdoc} */ - public function choice(string $question, array $choices, $default = null) + public function choice(string $question, array $choices, mixed $default = null) { if (null !== $default) { $values = array_flip($choices); @@ -375,7 +367,7 @@ public function askQuestion(Question $question) /** * {@inheritdoc} */ - public function writeln($messages, int $type = self::OUTPUT_NORMAL) + public function writeln(string|iterable $messages, int $type = self::OUTPUT_NORMAL) { if (!is_iterable($messages)) { $messages = [$messages]; @@ -390,7 +382,7 @@ public function writeln($messages, int $type = self::OUTPUT_NORMAL) /** * {@inheritdoc} */ - public function write($messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) + public function write(string|iterable $messages, bool $newline = false, int $type = self::OUTPUT_NORMAL) { if (!is_iterable($messages)) { $messages = [$messages]; From 553d4aa062ce6808dbccf3b38eb64b3edda13233 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 5 Jul 2021 08:27:11 +0200 Subject: [PATCH 009/215] [DependencyInjection][Console] tighten types --- Input/ArgvInput.php | 2 +- Input/ArrayInput.php | 2 +- Input/InputArgument.php | 14 +++++++------- Input/InputDefinition.php | 8 ++------ Input/InputInterface.php | 12 ++++++------ Input/InputOption.php | 17 ++++++----------- Question/Question.php | 8 ++++---- 7 files changed, 27 insertions(+), 36 deletions(-) diff --git a/Input/ArgvInput.php b/Input/ArgvInput.php index c114b0116..771e8daec 100644 --- a/Input/ArgvInput.php +++ b/Input/ArgvInput.php @@ -319,7 +319,7 @@ public function hasParameterOption(string|array $values, bool $onlyParams = fals /** * {@inheritdoc} */ - public function getParameterOption(string|array $values, mixed $default = false, bool $onlyParams = false) + public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false) { $values = (array) $values; $tokens = $this->tokens; diff --git a/Input/ArrayInput.php b/Input/ArrayInput.php index c2adeea1e..45d8d4b89 100644 --- a/Input/ArrayInput.php +++ b/Input/ArrayInput.php @@ -77,7 +77,7 @@ public function hasParameterOption(string|array $values, bool $onlyParams = fals /** * {@inheritdoc} */ - public function getParameterOption(string|array $values, mixed $default = false, bool $onlyParams = false) + public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false) { $values = (array) $values; diff --git a/Input/InputArgument.php b/Input/InputArgument.php index 3094b507e..db9024117 100644 --- a/Input/InputArgument.php +++ b/Input/InputArgument.php @@ -31,14 +31,14 @@ class InputArgument private $description; /** - * @param string $name The argument name - * @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL - * @param string $description A description text - * @param mixed $default The default value (for self::OPTIONAL mode only) + * @param string $name The argument name + * @param int|null $mode The argument mode: self::REQUIRED or self::OPTIONAL + * @param string $description A description text + * @param string|bool|int|float|array|null $default The default value (for self::OPTIONAL mode only) * * @throws InvalidArgumentException When argument mode is not valid */ - public function __construct(string $name, int $mode = null, string $description = '', mixed $default = null) + public function __construct(string $name, int $mode = null, string $description = '', string|bool|int|float|array $default = null) { if (null === $mode) { $mode = self::OPTIONAL; @@ -88,7 +88,7 @@ public function isArray() * * @throws LogicException When incorrect default value is given */ - public function setDefault(mixed $default = null) + public function setDefault(string|bool|int|float|array $default = null) { if (self::REQUIRED === $this->mode && null !== $default) { throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.'); @@ -108,7 +108,7 @@ public function setDefault(mixed $default = null) /** * Returns the default value. * - * @return mixed + * @return string|bool|int|float|array|null */ public function getDefault() { diff --git a/Input/InputDefinition.php b/Input/InputDefinition.php index 84f7b3f7d..cc9ff3515 100644 --- a/Input/InputDefinition.php +++ b/Input/InputDefinition.php @@ -182,9 +182,7 @@ public function getArgumentRequiredCount() } /** - * Gets the default values. - * - * @return array An array of default values + * @return array */ public function getArgumentDefaults() { @@ -325,9 +323,7 @@ public function getOptionForShortcut(string $shortcut) } /** - * Gets an array of default values. - * - * @return array An array of all default values + * @return array */ public function getOptionDefaults() { diff --git a/Input/InputInterface.php b/Input/InputInterface.php index ce0acbd72..f67366fd0 100644 --- a/Input/InputInterface.php +++ b/Input/InputInterface.php @@ -51,13 +51,13 @@ public function hasParameterOption(string|array $values, bool $onlyParams = fals * Does not necessarily return the correct result for short options * when multiple flags are combined in the same option. * - * @param string|array $values The value(s) to look for in the raw parameters (can be an array) - * @param mixed $default The default value to return if no result is found - * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal + * @param string|array $values The value(s) to look for in the raw parameters (can be an array) + * @param string|bool|int|float|array|null $default The default value to return if no result is found + * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal * * @return mixed The option value */ - public function getParameterOption(string|array $values, mixed $default = false, bool $onlyParams = false); + public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false); /** * Binds the current Input instance with the given arguments and options. @@ -76,7 +76,7 @@ public function validate(); /** * Returns all the given arguments merged with the default values. * - * @return array + * @return array */ public function getArguments(); @@ -106,7 +106,7 @@ public function hasArgument(string $name); /** * Returns all the given options merged with the default values. * - * @return array + * @return array */ public function getOptions(); diff --git a/Input/InputOption.php b/Input/InputOption.php index 3039ae509..b99d49acd 100644 --- a/Input/InputOption.php +++ b/Input/InputOption.php @@ -53,13 +53,13 @@ class InputOption private $description; /** - * @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 VALUE_* constants - * @param mixed $default The default value (must be null for self::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 VALUE_* constants + * @param string|bool|int|float|array|null $default The default value (must be null for self::VALUE_NONE) * * @throws InvalidArgumentException If option mode is invalid or incompatible */ - public function __construct(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null) + public function __construct(string $name, string|array $shortcut = null, int $mode = null, string $description = '', string|bool|int|float|array $default = null) { if (0 === strpos($name, '--')) { $name = substr($name, 2); @@ -172,12 +172,7 @@ public function isNegatable(): bool return self::VALUE_NEGATABLE === (self::VALUE_NEGATABLE & $this->mode); } - /** - * Sets the default value. - * - * @throws LogicException When incorrect default value is given - */ - public function setDefault(mixed $default = null) + public function setDefault(string|bool|int|float|array $default = null) { if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) { throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.'); @@ -197,7 +192,7 @@ public function setDefault(mixed $default = null) /** * Returns the default value. * - * @return mixed + * @return string|bool|int|float|array|null */ public function getDefault() { diff --git a/Question/Question.php b/Question/Question.php index c93386125..654fc5472 100644 --- a/Question/Question.php +++ b/Question/Question.php @@ -33,10 +33,10 @@ class Question private $multiline = false; /** - * @param string $question The question to ask to the user - * @param mixed $default The default answer to return if the user enters nothing + * @param string $question The question to ask to the user + * @param string|bool|int|float|null $default The default answer to return if the user enters nothing */ - public function __construct(string $question, mixed $default = null) + public function __construct(string $question, string|bool|int|float $default = null) { $this->question = $question; $this->default = $default; @@ -55,7 +55,7 @@ public function getQuestion() /** * Returns the default answer. * - * @return mixed + * @return string|bool|int|float|null */ public function getDefault() { From 523e053c92beba9eb3b0d4c90f45b383006093b5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 12 Jul 2021 11:26:55 +0200 Subject: [PATCH 010/215] Add return types, round 1 --- Command/LazyCommand.php | 5 +---- Helper/QuestionHelper.php | 18 +++--------------- Terminal.php | 4 +--- Tests/ApplicationTest.php | 15 +-------------- .../Descriptor/ApplicationDescriptionTest.php | 2 +- Tests/EventListener/ErrorListenerTest.php | 2 +- 6 files changed, 8 insertions(+), 38 deletions(-) diff --git a/Command/LazyCommand.php b/Command/LazyCommand.php index 5751be406..4defc0a87 100644 --- a/Command/LazyCommand.php +++ b/Command/LazyCommand.php @@ -177,10 +177,7 @@ public function getUsages(): array return $this->getCommand()->getUsages(); } - /** - * @return mixed - */ - public function getHelper(string $name) + public function getHelper(string $name): mixed { return $this->getCommand()->getHelper($name); } diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index 091b4fd69..cf8382754 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -99,11 +99,9 @@ public static function disableStty() /** * Asks the question to the user. * - * @return mixed - * * @throws RuntimeException In case the fallback is deactivated and the response cannot be hidden */ - private function doAsk(OutputInterface $output, Question $question) + private function doAsk(OutputInterface $output, Question $question): mixed { $this->writePrompt($output, $question); @@ -150,10 +148,7 @@ private function doAsk(OutputInterface $output, Question $question) return $ret; } - /** - * @return mixed - */ - private function getDefaultAnswer(Question $question) + private function getDefaultAnswer(Question $question): mixed { $default = $question->getDefault(); @@ -446,11 +441,9 @@ private function getHiddenResponse(OutputInterface $output, $inputStream, bool $ * * @param callable $interviewer A callable that will ask for a question and return the result * - * @return mixed The validated response - * * @throws \Exception In case the max number of attempts has been reached and no valid response has been given */ - private function validateAttempts(callable $interviewer, OutputInterface $output, Question $question) + private function validateAttempts(callable $interviewer, OutputInterface $output, Question $question): mixed { $error = null; $attempts = $question->getMaxAttempts(); @@ -532,11 +525,6 @@ private function readInput($inputStream, Question $question) return $this->resetIOCodepage($cp, $ret); } - /** - * Sets console I/O to the host code page. - * - * @return int Previous code page in IBM/EBCDIC format - */ private function setIOCodepage(): int { if (\function_exists('sapi_windows_cp_set')) { diff --git a/Terminal.php b/Terminal.php index 5e5a3c2f7..08c53535b 100644 --- a/Terminal.php +++ b/Terminal.php @@ -57,10 +57,8 @@ public function getHeight() /** * @internal - * - * @return bool */ - public static function hasSttyAvailable() + public static function hasSttyAvailable(): bool { if (null !== self::$stty) { return self::$stty; diff --git a/Tests/ApplicationTest.php b/Tests/ApplicationTest.php index 361e174cd..292614049 100644 --- a/Tests/ApplicationTest.php +++ b/Tests/ApplicationTest.php @@ -1867,21 +1867,11 @@ public function testSignal() class CustomApplication extends Application { - /** - * Overwrites the default input definition. - * - * @return InputDefinition An InputDefinition instance - */ protected function getDefaultInputDefinition(): InputDefinition { return new InputDefinition([new InputOption('--custom', '-c', InputOption::VALUE_NONE, 'Set the custom input definition.')]); } - /** - * Gets the default helper set with the helpers that should always be available. - * - * @return HelperSet A HelperSet instance - */ protected function getDefaultHelperSet(): HelperSet { return new HelperSet([new FormatterHelper()]); @@ -1890,9 +1880,6 @@ protected function getDefaultHelperSet(): HelperSet class CustomDefaultCommandApplication extends Application { - /** - * Overwrites the constructor in order to set a different default command. - */ public function __construct() { parent::__construct(); @@ -1938,7 +1925,7 @@ public function handleSignal(int $signal): void $this->signaled = true; } - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { for ($i = 0; $i < $this->loop; ++$i) { usleep(100); diff --git a/Tests/Descriptor/ApplicationDescriptionTest.php b/Tests/Descriptor/ApplicationDescriptionTest.php index 33d5c3840..b3ba9d848 100644 --- a/Tests/Descriptor/ApplicationDescriptionTest.php +++ b/Tests/Descriptor/ApplicationDescriptionTest.php @@ -46,7 +46,7 @@ final class TestApplication extends Application /** * {@inheritdoc} */ - protected function getDefaultCommands() + protected function getDefaultCommands(): array { return []; } diff --git a/Tests/EventListener/ErrorListenerTest.php b/Tests/EventListener/ErrorListenerTest.php index 2bafab040..becc9e540 100644 --- a/Tests/EventListener/ErrorListenerTest.php +++ b/Tests/EventListener/ErrorListenerTest.php @@ -136,7 +136,7 @@ public function hasParameterOption($values, $onlyParams = false): bool { } - public function getParameterOption($values, $default = false, $onlyParams = false) + public function getParameterOption($values, $default = false, $onlyParams = false): mixed { } From efe6a926704c9e4f942c63d0d81e13f636585215 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 13 Jul 2021 13:47:05 +0200 Subject: [PATCH 011/215] [Contracts] add return types and bump to v3 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 5a67952f6..6ffb8e2a4 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "require": { "php": ">=8.0.2", "symfony/polyfill-mbstring": "~1.0", - "symfony/service-contracts": "^1.1|^2", + "symfony/service-contracts": "^1.1|^2.0|^3.0", "symfony/string": "^5.4|^6.0" }, "require-dev": { From 99a08c369960e5a5c394b50c359272dada301e60 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sun, 18 Jul 2021 18:39:07 +0200 Subject: [PATCH 012/215] Implement psr/log 3 Signed-off-by: Alexander M. Turek --- Logger/ConsoleLogger.php | 4 +--- composer.json | 5 ++--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Logger/ConsoleLogger.php b/Logger/ConsoleLogger.php index 0379b2036..2c1e57cba 100644 --- a/Logger/ConsoleLogger.php +++ b/Logger/ConsoleLogger.php @@ -61,10 +61,8 @@ public function __construct(OutputInterface $output, array $verbosityLevelMap = /** * {@inheritdoc} - * - * @return void */ - public function log($level, $message, array $context = []) + public function log($level, $message, array $context = []): void { if (!isset($this->verbosityLevelMap[$level])) { throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level)); diff --git a/composer.json b/composer.json index 7cc224827..9ecb8ffd1 100644 --- a/composer.json +++ b/composer.json @@ -28,10 +28,10 @@ "symfony/lock": "^5.4|^6.0", "symfony/process": "^5.4|^6.0", "symfony/var-dumper": "^5.4|^6.0", - "psr/log": "^1|^2" + "psr/log": "^1|^2|^3" }, "provide": { - "psr/log-implementation": "1.0|2.0" + "psr/log-implementation": "1.0|2.0|3.0" }, "suggest": { "symfony/event-dispatcher": "", @@ -40,7 +40,6 @@ "psr/log": "For using the console logger" }, "conflict": { - "psr/log": ">=3", "symfony/dependency-injection": "<5.4", "symfony/dotenv": "<5.4", "symfony/event-dispatcher": "<5.4", From 0835f92393498a0ef002daaff180b7f81465ee1b Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 20 Jul 2021 15:07:23 +0200 Subject: [PATCH 013/215] Add return type unions to private/internal/final/test methods --- Helper/QuestionHelper.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index d87afb3aa..d937f40e5 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -496,10 +496,8 @@ private function isInteractiveInput($inputStream): bool * * @param resource $inputStream The handler resource * @param Question $question The question being asked - * - * @return string|false The input received, false in case input could not be read */ - private function readInput($inputStream, Question $question) + private function readInput($inputStream, Question $question): string|false { if (!$question->isMultiline()) { $cp = $this->setIOCodepage(); @@ -539,10 +537,8 @@ private function setIOCodepage(): int /** * Sets console I/O to the specified code page and converts the user input. - * - * @return string|false */ - private function resetIOCodepage(int $cp, string|false $input) + private function resetIOCodepage(int $cp, string|false $input): string|false { if (0 !== $cp) { sapi_windows_cp_set($cp); From d098ec35e458f6f1a674dcdae27534131d1482ed Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 21 Jul 2021 12:04:28 +0200 Subject: [PATCH 014/215] Narrow existing return types on private/internal/final/test methods --- Command/LazyCommand.php | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) diff --git a/Command/LazyCommand.php b/Command/LazyCommand.php index 4defc0a87..930cee0be 100644 --- a/Command/LazyCommand.php +++ b/Command/LazyCommand.php @@ -69,10 +69,7 @@ public function run(InputInterface $input, OutputInterface $output): int return $this->getCommand()->run($input, $output); } - /** - * @return $this - */ - public function setCode(callable $code): self + public function setCode(callable $code): static { $this->getCommand()->setCode($code); @@ -87,10 +84,7 @@ public function mergeApplicationDefinition(bool $mergeArgs = true): void $this->getCommand()->mergeApplicationDefinition($mergeArgs); } - /** - * @return $this - */ - public function setDefinition(array|InputDefinition $definition): self + public function setDefinition(array|InputDefinition $definition): static { $this->getCommand()->setDefinition($definition); @@ -107,40 +101,28 @@ public function getNativeDefinition(): InputDefinition return $this->getCommand()->getNativeDefinition(); } - /** - * @return $this - */ - public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null): self + public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null): static { $this->getCommand()->addArgument($name, $mode, $description, $default); return $this; } - /** - * @return $this - */ - public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null): self + public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null): static { $this->getCommand()->addOption($name, $shortcut, $mode, $description, $default); return $this; } - /** - * @return $this - */ - public function setProcessTitle(string $title): self + public function setProcessTitle(string $title): static { $this->getCommand()->setProcessTitle($title); return $this; } - /** - * @return $this - */ - public function setHelp(string $help): self + public function setHelp(string $help): static { $this->getCommand()->setHelp($help); @@ -162,10 +144,7 @@ public function getSynopsis(bool $short = false): string return $this->getCommand()->getSynopsis($short); } - /** - * @return $this - */ - public function addUsage(string $usage): self + public function addUsage(string $usage): static { $this->getCommand()->addUsage($usage); From 595354ab6262999032b1b10d1f3d6fff7b976b06 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Thu, 5 Aug 2021 00:33:39 +0200 Subject: [PATCH 015/215] Remove ReturnTypeWillChange Signed-off-by: Alexander M. Turek --- Helper/HelperSet.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Helper/HelperSet.php b/Helper/HelperSet.php index 679dceab1..ca627a52d 100644 --- a/Helper/HelperSet.php +++ b/Helper/HelperSet.php @@ -89,10 +89,9 @@ public function getCommand() } /** - * @return \Traversable + * @return \Traversable */ - #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): \Traversable { return new \ArrayIterator($this->helpers); } From a1ee9d3cdcb41e70f7dc83b4e43fa5af0106de3f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 12 Aug 2021 18:00:10 +0200 Subject: [PATCH 016/215] Add return types - batch 4/n --- Application.php | 40 ++++++++--------- Command/Command.php | 50 ++++++++++----------- Command/HelpCommand.php | 2 +- Command/ListCommand.php | 2 +- CommandLoader/CommandLoaderInterface.php | 6 +-- CommandLoader/ContainerCommandLoader.php | 7 +-- CommandLoader/FactoryCommandLoader.php | 7 +-- Event/ConsoleEvent.php | 6 +-- EventListener/ErrorListener.php | 2 +- Exception/CommandNotFoundException.php | 2 +- Formatter/OutputFormatter.php | 12 ++--- Formatter/OutputFormatterInterface.php | 8 ++-- Formatter/OutputFormatterStyle.php | 2 +- Formatter/OutputFormatterStyleInterface.php | 2 +- Formatter/OutputFormatterStyleStack.php | 8 ++-- Helper/DebugFormatterHelper.php | 8 ++-- Helper/DescriptorHelper.php | 4 +- Helper/FormatterHelper.php | 8 ++-- Helper/Helper.php | 4 +- Helper/HelperInterface.php | 6 +-- Helper/HelperSet.php | 6 +-- Helper/ProgressIndicator.php | 4 +- Helper/QuestionHelper.php | 6 +-- Helper/Table.php | 16 +++---- Helper/TableCell.php | 4 +- Helper/TableCellStyle.php | 2 +- Helper/TableStyle.php | 26 +++++------ Input/ArgvInput.php | 6 +-- Input/ArrayInput.php | 6 +-- Input/Input.php | 16 +++---- Input/InputArgument.php | 10 ++--- Input/InputDefinition.php | 26 +++++------ Input/InputInterface.php | 20 ++++----- Input/InputOption.php | 18 ++++---- Logger/ConsoleLogger.php | 2 +- Output/BufferedOutput.php | 2 +- Output/ConsoleOutput.php | 6 +-- Output/ConsoleOutputInterface.php | 2 +- Output/NullOutput.php | 14 +++--- Output/Output.php | 14 +++--- Output/OutputInterface.php | 14 +++--- Output/StreamOutput.php | 2 +- Output/TrimmedBufferOutput.php | 2 +- Question/ChoiceQuestion.php | 12 ++--- Question/Question.php | 34 +++++++------- Style/OutputStyle.php | 16 +++---- Style/StyleInterface.php | 8 ++-- Style/SymfonyStyle.php | 16 +++---- Terminal.php | 4 +- Tester/ApplicationTester.php | 2 +- Tester/CommandTester.php | 2 +- Tester/TesterTrait.php | 12 ++--- 52 files changed, 256 insertions(+), 260 deletions(-) diff --git a/Application.php b/Application.php index 477121bbc..17006bccc 100644 --- a/Application.php +++ b/Application.php @@ -130,7 +130,7 @@ public function setSignalsToDispatchEvent(int ...$signalsToDispatchEvent) * * @throws \Exception When running fails. Bypass this when {@link setCatchExceptions()}. */ - public function run(InputInterface $input = null, OutputInterface $output = null) + public function run(InputInterface $input = null, OutputInterface $output = null): int { if (\function_exists('putenv')) { @putenv('LINES='.$this->terminal->getHeight()); @@ -315,7 +315,7 @@ public function setHelperSet(HelperSet $helperSet) * * @return HelperSet */ - public function getHelperSet() + public function getHelperSet(): HelperSet { if (!$this->helperSet) { $this->helperSet = $this->getDefaultHelperSet(); @@ -334,7 +334,7 @@ public function setDefinition(InputDefinition $definition) * * @return InputDefinition */ - public function getDefinition() + public function getDefinition(): InputDefinition { if (!$this->definition) { $this->definition = $this->getDefaultInputDefinition(); @@ -355,7 +355,7 @@ public function getDefinition() * * @return string A help message */ - public function getHelp() + public function getHelp(): string { return $this->getLongVersion(); } @@ -365,7 +365,7 @@ public function getHelp() * * @return bool Whether to catch exceptions or not during commands execution */ - public function areExceptionsCaught() + public function areExceptionsCaught(): bool { return $this->catchExceptions; } @@ -383,7 +383,7 @@ public function setCatchExceptions(bool $boolean) * * @return bool Whether to automatically exit after a command execution or not */ - public function isAutoExitEnabled() + public function isAutoExitEnabled(): bool { return $this->autoExit; } @@ -401,7 +401,7 @@ public function setAutoExit(bool $boolean) * * @return string The application name */ - public function getName() + public function getName(): string { return $this->name; } @@ -419,7 +419,7 @@ public function setName(string $name) * * @return string The application version */ - public function getVersion() + public function getVersion(): string { return $this->version; } @@ -455,7 +455,7 @@ public function getLongVersion() * * @return Command The newly created command */ - public function register(string $name) + public function register(string $name): Command { return $this->add(new Command($name)); } @@ -551,7 +551,7 @@ public function get(string $name) * * @return bool true if the command exists, false otherwise */ - public function has(string $name) + public function has(string $name): bool { $this->init(); @@ -565,7 +565,7 @@ public function has(string $name) * * @return string[] An array of namespaces */ - public function getNamespaces() + public function getNamespaces(): array { $namespaces = []; foreach ($this->all() as $command) { @@ -590,7 +590,7 @@ public function getNamespaces() * * @throws NamespaceNotFoundException When namespace is incorrect or ambiguous */ - public function findNamespace(string $namespace) + public function findNamespace(string $namespace): string { $allNamespaces = $this->getNamespaces(); $expr = implode('[^:]*:', array_map('preg_quote', explode(':', $namespace))).'[^:]*'; @@ -782,7 +782,7 @@ public function all(string $namespace = null) * * @return string[][] An array of abbreviations */ - public static function getAbbreviations(array $names) + public static function getAbbreviations(array $names): array { $abbrevs = []; foreach ($names as $name) { @@ -1022,7 +1022,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI * * @return string|null */ - protected function getCommandName(InputInterface $input) + protected function getCommandName(InputInterface $input): ?string { return $this->singleCommand ? $this->defaultCommand : $input->getFirstArgument(); } @@ -1032,7 +1032,7 @@ protected function getCommandName(InputInterface $input) * * @return InputDefinition */ - protected function getDefaultInputDefinition() + protected function getDefaultInputDefinition(): InputDefinition { return new InputDefinition([ new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'), @@ -1050,7 +1050,7 @@ protected function getDefaultInputDefinition() * * @return Command[] */ - protected function getDefaultCommands() + protected function getDefaultCommands(): array { return [new HelpCommand(), new ListCommand()]; } @@ -1060,7 +1060,7 @@ protected function getDefaultCommands() * * @return HelperSet */ - protected function getDefaultHelperSet() + protected function getDefaultHelperSet(): HelperSet { return new HelperSet([ new FormatterHelper(), @@ -1085,7 +1085,7 @@ private function getAbbreviationSuggestions(array $abbrevs): string * * @return string The namespace of the command */ - public function extractNamespace(string $name, int $limit = null) + public function extractNamespace(string $name, int $limit = null): string { $parts = explode(':', $name, -1); @@ -1142,10 +1142,8 @@ private function findAlternatives(string $name, iterable $collection): array /** * Sets the default Command name. - * - * @return self */ - public function setDefaultCommand(string $commandName, bool $isSingleCommand = false) + public function setDefaultCommand(string $commandName, bool $isSingleCommand = false): static { $this->defaultCommand = explode('|', ltrim($commandName, '|'))[0]; diff --git a/Command/Command.php b/Command/Command.php index ea44f88f2..d11b84dd9 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -63,7 +63,7 @@ class Command /** * @return string|null The default command name or null when no default name is set */ - public static function getDefaultName() + public static function getDefaultName(): ?string { $class = static::class; @@ -155,7 +155,7 @@ public function setHelperSet(HelperSet $helperSet) * * @return HelperSet|null */ - public function getHelperSet() + public function getHelperSet(): ?HelperSet { return $this->helperSet; } @@ -165,7 +165,7 @@ public function getHelperSet() * * @return Application|null */ - public function getApplication() + public function getApplication(): ?Application { return $this->application; } @@ -248,7 +248,7 @@ protected function initialize(InputInterface $input, OutputInterface $output) * @see setCode() * @see execute() */ - public function run(InputInterface $input, OutputInterface $output) + public function run(InputInterface $input, OutputInterface $output): int { // add the application arguments and options $this->mergeApplicationDefinition(); @@ -320,7 +320,7 @@ public function run(InputInterface $input, OutputInterface $output) * * @see execute() */ - public function setCode(callable $code) + public function setCode(callable $code): static { if ($code instanceof \Closure) { $r = new \ReflectionFunction($code); @@ -373,7 +373,7 @@ public function mergeApplicationDefinition(bool $mergeArgs = true) * * @return $this */ - public function setDefinition(array|InputDefinition $definition) + public function setDefinition(array|InputDefinition $definition): static { if ($definition instanceof InputDefinition) { $this->definition = $definition; @@ -391,7 +391,7 @@ public function setDefinition(array|InputDefinition $definition) * * @return InputDefinition */ - public function getDefinition() + public function getDefinition(): InputDefinition { return $this->fullDefinition ?? $this->getNativeDefinition(); } @@ -406,7 +406,7 @@ public function getDefinition() * * @return InputDefinition */ - public function getNativeDefinition() + public function getNativeDefinition(): InputDefinition { if (null === $this->definition) { throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', static::class)); @@ -425,7 +425,7 @@ public function getNativeDefinition() * * @return $this */ - public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null) + public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null): static { $this->definition->addArgument(new InputArgument($name, $mode, $description, $default)); if (null !== $this->fullDefinition) { @@ -446,7 +446,7 @@ public function addArgument(string $name, int $mode = null, string $description * * @return $this */ - public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null) + public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null): static { $this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default)); if (null !== $this->fullDefinition) { @@ -468,7 +468,7 @@ public function addOption(string $name, string|array $shortcut = null, int $mode * * @throws InvalidArgumentException When the name is invalid */ - public function setName(string $name) + public function setName(string $name): static { $this->validateName($name); @@ -485,7 +485,7 @@ public function setName(string $name) * * @return $this */ - public function setProcessTitle(string $title) + public function setProcessTitle(string $title): static { $this->processTitle = $title; @@ -497,7 +497,7 @@ public function setProcessTitle(string $title) * * @return string|null */ - public function getName() + public function getName(): ?string { return $this->name; } @@ -517,7 +517,7 @@ public function setHidden(bool $hidden = true): static /** * @return bool whether the command should be publicly shown or not */ - public function isHidden() + public function isHidden(): bool { return $this->hidden; } @@ -527,7 +527,7 @@ public function isHidden() * * @return $this */ - public function setDescription(string $description) + public function setDescription(string $description): static { $this->description = $description; @@ -539,7 +539,7 @@ public function setDescription(string $description) * * @return string The description for the command */ - public function getDescription() + public function getDescription(): string { return $this->description; } @@ -549,7 +549,7 @@ public function getDescription() * * @return $this */ - public function setHelp(string $help) + public function setHelp(string $help): static { $this->help = $help; @@ -561,7 +561,7 @@ public function setHelp(string $help) * * @return string The help for the command */ - public function getHelp() + public function getHelp(): string { return $this->help; } @@ -572,7 +572,7 @@ public function getHelp() * * @return string The processed help for the command */ - public function getProcessedHelp() + public function getProcessedHelp(): string { $name = $this->name; $isSingleCommand = $this->application && $this->application->isSingleCommand(); @@ -598,7 +598,7 @@ public function getProcessedHelp() * * @throws InvalidArgumentException When an alias is invalid */ - public function setAliases(iterable $aliases) + public function setAliases(iterable $aliases): static { $list = []; @@ -617,7 +617,7 @@ public function setAliases(iterable $aliases) * * @return array An array of aliases for the command */ - public function getAliases() + public function getAliases(): array { return $this->aliases; } @@ -629,7 +629,7 @@ public function getAliases() * * @return string The synopsis */ - public function getSynopsis(bool $short = false) + public function getSynopsis(bool $short = false): string { $key = $short ? 'short' : 'long'; @@ -645,7 +645,7 @@ public function getSynopsis(bool $short = false) * * @return $this */ - public function addUsage(string $usage) + public function addUsage(string $usage): static { if (!str_starts_with($usage, $this->name)) { $usage = sprintf('%s %s', $this->name, $usage); @@ -661,7 +661,7 @@ public function addUsage(string $usage) * * @return array */ - public function getUsages() + public function getUsages(): array { return $this->usages; } @@ -674,7 +674,7 @@ public function getUsages() * @throws LogicException if no HelperSet is defined * @throws InvalidArgumentException if the helper is not defined */ - public function getHelper(string $name) + public function getHelper(string $name): mixed { 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)); diff --git a/Command/HelpCommand.php b/Command/HelpCommand.php index 9bcd7764d..72a079292 100644 --- a/Command/HelpCommand.php +++ b/Command/HelpCommand.php @@ -64,7 +64,7 @@ public function setCommand(Command $command) /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { if (null === $this->command) { $this->command = $this->getApplication()->find($input->getArgument('command_name')); diff --git a/Command/ListCommand.php b/Command/ListCommand.php index a19228512..ef9873e74 100644 --- a/Command/ListCommand.php +++ b/Command/ListCommand.php @@ -62,7 +62,7 @@ protected function configure() /** * {@inheritdoc} */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { $helper = new DescriptorHelper(); $helper->describe($output, $this->getApplication(), [ diff --git a/CommandLoader/CommandLoaderInterface.php b/CommandLoader/CommandLoaderInterface.php index d4f44e88f..d297ceb24 100644 --- a/CommandLoader/CommandLoaderInterface.php +++ b/CommandLoader/CommandLoaderInterface.php @@ -26,17 +26,17 @@ interface CommandLoaderInterface * * @throws CommandNotFoundException */ - public function get(string $name); + public function get(string $name): Command; /** * Checks if a command exists. * * @return bool */ - public function has(string $name); + public function has(string $name): bool; /** * @return string[] All registered command names */ - public function getNames(); + public function getNames(): array; } diff --git a/CommandLoader/ContainerCommandLoader.php b/CommandLoader/ContainerCommandLoader.php index ddccb3d45..ede9096f5 100644 --- a/CommandLoader/ContainerCommandLoader.php +++ b/CommandLoader/ContainerCommandLoader.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Console\CommandLoader; +use Symfony\Component\Console\Command\Command; use Psr\Container\ContainerInterface; use Symfony\Component\Console\Exception\CommandNotFoundException; @@ -36,7 +37,7 @@ public function __construct(ContainerInterface $container, array $commandMap) /** * {@inheritdoc} */ - public function get(string $name) + public function get(string $name): Command { if (!$this->has($name)) { throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); @@ -48,7 +49,7 @@ public function get(string $name) /** * {@inheritdoc} */ - public function has(string $name) + public function has(string $name): bool { return isset($this->commandMap[$name]) && $this->container->has($this->commandMap[$name]); } @@ -56,7 +57,7 @@ public function has(string $name) /** * {@inheritdoc} */ - public function getNames() + public function getNames(): array { return array_keys($this->commandMap); } diff --git a/CommandLoader/FactoryCommandLoader.php b/CommandLoader/FactoryCommandLoader.php index 7e2db3464..1c64bb872 100644 --- a/CommandLoader/FactoryCommandLoader.php +++ b/CommandLoader/FactoryCommandLoader.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Console\CommandLoader; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\CommandNotFoundException; /** @@ -33,7 +34,7 @@ public function __construct(array $factories) /** * {@inheritdoc} */ - public function has(string $name) + public function has(string $name): bool { return isset($this->factories[$name]); } @@ -41,7 +42,7 @@ public function has(string $name) /** * {@inheritdoc} */ - public function get(string $name) + public function get(string $name): Command { if (!isset($this->factories[$name])) { throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name)); @@ -55,7 +56,7 @@ public function get(string $name) /** * {@inheritdoc} */ - public function getNames() + public function getNames(): array { return array_keys($this->factories); } diff --git a/Event/ConsoleEvent.php b/Event/ConsoleEvent.php index fba4d28fb..b63e756b2 100644 --- a/Event/ConsoleEvent.php +++ b/Event/ConsoleEvent.php @@ -40,7 +40,7 @@ public function __construct(Command $command = null, InputInterface $input, Outp * * @return Command|null */ - public function getCommand() + public function getCommand(): ?Command { return $this->command; } @@ -50,7 +50,7 @@ public function getCommand() * * @return InputInterface */ - public function getInput() + public function getInput(): InputInterface { return $this->input; } @@ -60,7 +60,7 @@ public function getInput() * * @return OutputInterface */ - public function getOutput() + public function getOutput(): OutputInterface { return $this->output; } diff --git a/EventListener/ErrorListener.php b/EventListener/ErrorListener.php index 5f34ca4c0..61bd9d344 100644 --- a/EventListener/ErrorListener.php +++ b/EventListener/ErrorListener.php @@ -69,7 +69,7 @@ public function onConsoleTerminate(ConsoleTerminateEvent $event) $this->logger->debug('Command "{command}" exited with code "{code}"', ['command' => $inputString, 'code' => $exitCode]); } - public static function getSubscribedEvents() + public static function getSubscribedEvents(): array { return [ ConsoleEvents::ERROR => ['onConsoleError', -128], diff --git a/Exception/CommandNotFoundException.php b/Exception/CommandNotFoundException.php index 590a71c77..9aca96c77 100644 --- a/Exception/CommandNotFoundException.php +++ b/Exception/CommandNotFoundException.php @@ -36,7 +36,7 @@ public function __construct(string $message, array $alternatives = [], int $code /** * @return string[] A list of similar defined names */ - public function getAlternatives() + public function getAlternatives(): array { return $this->alternatives; } diff --git a/Formatter/OutputFormatter.php b/Formatter/OutputFormatter.php index 80d59b3b4..5cc1fb307 100644 --- a/Formatter/OutputFormatter.php +++ b/Formatter/OutputFormatter.php @@ -38,7 +38,7 @@ public function __clone() * * @return string Escaped text */ - public static function escape(string $text) + public static function escape(string $text): string { $text = preg_replace('/([^\\\\]?)decorated; } @@ -110,7 +110,7 @@ public function setStyle(string $name, OutputFormatterStyleInterface $style) /** * {@inheritdoc} */ - public function hasStyle(string $name) + public function hasStyle(string $name): bool { return isset($this->styles[strtolower($name)]); } @@ -118,7 +118,7 @@ public function hasStyle(string $name) /** * {@inheritdoc} */ - public function getStyle(string $name) + public function getStyle(string $name): OutputFormatterStyleInterface { if (!$this->hasStyle($name)) { throw new InvalidArgumentException(sprintf('Undefined style: "%s".', $name)); @@ -130,7 +130,7 @@ public function getStyle(string $name) /** * {@inheritdoc} */ - public function format(?string $message) + public function format(?string $message): ?string { return $this->formatAndWrap($message, 0); } @@ -188,7 +188,7 @@ public function formatAndWrap(?string $message, int $width) /** * @return OutputFormatterStyleStack */ - public function getStyleStack() + public function getStyleStack(): OutputFormatterStyleStack { return $this->styleStack; } diff --git a/Formatter/OutputFormatterInterface.php b/Formatter/OutputFormatterInterface.php index 41474eacd..c6b9ab62f 100644 --- a/Formatter/OutputFormatterInterface.php +++ b/Formatter/OutputFormatterInterface.php @@ -28,7 +28,7 @@ public function setDecorated(bool $decorated); * * @return bool true if the output will decorate messages, false otherwise */ - public function isDecorated(); + public function isDecorated(): bool; /** * Sets a new style. @@ -40,7 +40,7 @@ public function setStyle(string $name, OutputFormatterStyleInterface $style); * * @return bool */ - public function hasStyle(string $name); + public function hasStyle(string $name): bool; /** * Gets style options from style with specified name. @@ -49,12 +49,12 @@ public function hasStyle(string $name); * * @throws \InvalidArgumentException When style isn't defined */ - public function getStyle(string $name); + public function getStyle(string $name): OutputFormatterStyleInterface; /** * Formats a message according to the given styles. * * @return string|null */ - public function format(?string $message); + public function format(?string $message): ?string; } diff --git a/Formatter/OutputFormatterStyle.php b/Formatter/OutputFormatterStyle.php index 0fb36ac63..6514549a7 100644 --- a/Formatter/OutputFormatterStyle.php +++ b/Formatter/OutputFormatterStyle.php @@ -92,7 +92,7 @@ public function setOptions(array $options) /** * {@inheritdoc} */ - public function apply(string $text) + public function apply(string $text): string { if (null === $this->handlesHrefGracefully) { $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') diff --git a/Formatter/OutputFormatterStyleInterface.php b/Formatter/OutputFormatterStyleInterface.php index b30560d22..120759f29 100644 --- a/Formatter/OutputFormatterStyleInterface.php +++ b/Formatter/OutputFormatterStyleInterface.php @@ -48,5 +48,5 @@ public function setOptions(array $options); * * @return string */ - public function apply(string $text); + public function apply(string $text): string; } diff --git a/Formatter/OutputFormatterStyleStack.php b/Formatter/OutputFormatterStyleStack.php index fc48dc0e1..a5695b1a5 100644 --- a/Formatter/OutputFormatterStyleStack.php +++ b/Formatter/OutputFormatterStyleStack.php @@ -55,7 +55,7 @@ public function push(OutputFormatterStyleInterface $style) * * @throws InvalidArgumentException When style tags incorrectly nested */ - public function pop(OutputFormatterStyleInterface $style = null) + public function pop(OutputFormatterStyleInterface $style = null): OutputFormatterStyleInterface { if (empty($this->styles)) { return $this->emptyStyle; @@ -81,7 +81,7 @@ public function pop(OutputFormatterStyleInterface $style = null) * * @return OutputFormatterStyle */ - public function getCurrent() + public function getCurrent(): OutputFormatterStyle { if (empty($this->styles)) { return $this->emptyStyle; @@ -93,7 +93,7 @@ public function getCurrent() /** * @return $this */ - public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) + public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle): static { $this->emptyStyle = $emptyStyle; @@ -103,7 +103,7 @@ public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle) /** * @return OutputFormatterStyleInterface */ - public function getEmptyStyle() + public function getEmptyStyle(): OutputFormatterStyleInterface { return $this->emptyStyle; } diff --git a/Helper/DebugFormatterHelper.php b/Helper/DebugFormatterHelper.php index 9d07ec244..c1c281b21 100644 --- a/Helper/DebugFormatterHelper.php +++ b/Helper/DebugFormatterHelper.php @@ -29,7 +29,7 @@ class DebugFormatterHelper extends Helper * * @return string */ - public function start(string $id, string $message, string $prefix = 'RUN') + public function start(string $id, string $message, string $prefix = 'RUN'): string { $this->started[$id] = ['border' => ++$this->count % \count($this->colors)]; @@ -41,7 +41,7 @@ public function start(string $id, string $message, string $prefix = 'RUN') * * @return string */ - public function progress(string $id, string $buffer, bool $error = false, string $prefix = 'OUT', string $errorPrefix = 'ERR') + public function progress(string $id, string $buffer, bool $error = false, string $prefix = 'OUT', string $errorPrefix = 'ERR'): string { $message = ''; @@ -77,7 +77,7 @@ public function progress(string $id, string $buffer, bool $error = false, string * * @return string */ - public function stop(string $id, string $message, bool $successful, string $prefix = 'RES') + public function stop(string $id, string $message, bool $successful, string $prefix = 'RES'): string { $trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : ''; @@ -100,7 +100,7 @@ private function getBorder(string $id): string /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return 'debug_formatter'; } diff --git a/Helper/DescriptorHelper.php b/Helper/DescriptorHelper.php index f2ad9db7a..e975edbdc 100644 --- a/Helper/DescriptorHelper.php +++ b/Helper/DescriptorHelper.php @@ -70,7 +70,7 @@ public function describe(OutputInterface $output, ?object $object, array $option * * @return $this */ - public function register(string $format, DescriptorInterface $descriptor) + public function register(string $format, DescriptorInterface $descriptor): static { $this->descriptors[$format] = $descriptor; @@ -80,7 +80,7 @@ public function register(string $format, DescriptorInterface $descriptor) /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return 'descriptor'; } diff --git a/Helper/FormatterHelper.php b/Helper/FormatterHelper.php index b6c72b881..6a6f26848 100644 --- a/Helper/FormatterHelper.php +++ b/Helper/FormatterHelper.php @@ -25,7 +25,7 @@ class FormatterHelper extends Helper * * @return string The format section */ - public function formatSection(string $section, string $message, string $style = 'info') + public function formatSection(string $section, string $message, string $style = 'info'): string { return sprintf('<%s>[%s] %s', $style, $section, $style, $message); } @@ -35,7 +35,7 @@ public function formatSection(string $section, string $message, string $style = * * @return string The formatter message */ - public function formatBlock(string|array $messages, string $style, bool $large = false) + public function formatBlock(string|array $messages, string $style, bool $large = false): string { if (!\is_array($messages)) { $messages = [$messages]; @@ -69,7 +69,7 @@ public function formatBlock(string|array $messages, string $style, bool $large = * * @return string */ - public function truncate(string $message, int $length, string $suffix = '...') + public function truncate(string $message, int $length, string $suffix = '...'): string { $computedLength = $length - self::width($suffix); @@ -83,7 +83,7 @@ public function truncate(string $message, int $length, string $suffix = '...') /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return 'formatter'; } diff --git a/Helper/Helper.php b/Helper/Helper.php index bd408fa61..aa2c8adff 100644 --- a/Helper/Helper.php +++ b/Helper/Helper.php @@ -34,7 +34,7 @@ public function setHelperSet(HelperSet $helperSet = null) /** * {@inheritdoc} */ - public function getHelperSet() + public function getHelperSet(): ?HelperSet { return $this->helperSet; } @@ -82,7 +82,7 @@ public static function length(?string $string): int * * @return string The string subset */ - public static function substr(?string $string, int $from, int $length = null) + public static function substr(?string $string, int $from, int $length = null): string { $string ?? $string = ''; diff --git a/Helper/HelperInterface.php b/Helper/HelperInterface.php index e3b7f9256..a87065a0f 100644 --- a/Helper/HelperInterface.php +++ b/Helper/HelperInterface.php @@ -25,15 +25,13 @@ public function setHelperSet(HelperSet $helperSet = null); /** * Gets the helper set associated with this helper. - * - * @return HelperSet|null */ - public function getHelperSet(); + public function getHelperSet(): ?HelperSet; /** * Returns the canonical name of this helper. * * @return string The canonical name */ - public function getName(); + public function getName(): string; } diff --git a/Helper/HelperSet.php b/Helper/HelperSet.php index 471acf58f..ebe9e5aff 100644 --- a/Helper/HelperSet.php +++ b/Helper/HelperSet.php @@ -52,7 +52,7 @@ public function set(HelperInterface $helper, string $alias = null) * * @return bool true if the helper is defined, false otherwise */ - public function has(string $name) + public function has(string $name): bool { return isset($this->helpers[$name]); } @@ -64,7 +64,7 @@ public function has(string $name) * * @throws InvalidArgumentException if the helper is not defined */ - public function get(string $name) + public function get(string $name): HelperInterface { if (!$this->has($name)) { throw new InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name)); @@ -83,7 +83,7 @@ public function setCommand(Command $command = null) * * @return Command */ - public function getCommand() + public function getCommand(): Command { return $this->command; } diff --git a/Helper/ProgressIndicator.php b/Helper/ProgressIndicator.php index 2d8774201..cbe9a88fe 100644 --- a/Helper/ProgressIndicator.php +++ b/Helper/ProgressIndicator.php @@ -136,7 +136,7 @@ public function finish(string $message) * * @return string|null A format string */ - public static function getFormatDefinition(string $name) + public static function getFormatDefinition(string $name): ?string { if (!self::$formats) { self::$formats = self::initFormats(); @@ -164,7 +164,7 @@ public static function setPlaceholderFormatterDefinition(string $name, callable * * @return callable|null A PHP callable */ - public static function getPlaceholderFormatterDefinition(string $name) + public static function getPlaceholderFormatterDefinition(string $name): ?callable { if (!self::$formatters) { self::$formatters = self::initPlaceholderFormatters(); diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index 6423b50e4..170cecc51 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -45,7 +45,7 @@ class QuestionHelper extends Helper * * @throws RuntimeException If there is no data to read in the input stream */ - public function ask(InputInterface $input, OutputInterface $output, Question $question) + public function ask(InputInterface $input, OutputInterface $output, Question $question): mixed { if ($output instanceof ConsoleOutputInterface) { $output = $output->getErrorOutput(); @@ -83,7 +83,7 @@ public function ask(InputInterface $input, OutputInterface $output, Question $qu /** * {@inheritdoc} */ - public function getName() + public function getName(): string { return 'question'; } @@ -196,7 +196,7 @@ protected function writePrompt(OutputInterface $output, Question $question) /** * @return string[] */ - protected function formatChoiceQuestionChoices(ChoiceQuestion $question, string $tag) + protected function formatChoiceQuestionChoices(ChoiceQuestion $question, string $tag): array { $messages = []; diff --git a/Helper/Table.php b/Helper/Table.php index 146c1410b..8f94bc5e9 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -117,7 +117,7 @@ public static function setStyleDefinition(string $name, TableStyle $style) * * @return TableStyle */ - public static function getStyleDefinition(string $name) + public static function getStyleDefinition(string $name): TableStyle { if (!self::$styles) { self::$styles = self::initStyles(); @@ -135,7 +135,7 @@ public static function getStyleDefinition(string $name) * * @return $this */ - public function setStyle(TableStyle|string $name) + public function setStyle(TableStyle|string $name): static { $this->style = $this->resolveStyle($name); @@ -147,7 +147,7 @@ public function setStyle(TableStyle|string $name) * * @return TableStyle */ - public function getStyle() + public function getStyle(): TableStyle { return $this->style; } @@ -159,7 +159,7 @@ public function getStyle() * * @return $this */ - public function setColumnStyle(int $columnIndex, TableStyle|string $name) + public function setColumnStyle(int $columnIndex, TableStyle|string $name): static { $this->columnStyles[$columnIndex] = $this->resolveStyle($name); @@ -173,7 +173,7 @@ public function setColumnStyle(int $columnIndex, TableStyle|string $name) * * @return TableStyle */ - public function getColumnStyle(int $columnIndex) + public function getColumnStyle(int $columnIndex): TableStyle { return $this->columnStyles[$columnIndex] ?? $this->getStyle(); } @@ -183,7 +183,7 @@ public function getColumnStyle(int $columnIndex) * * @return $this */ - public function setColumnWidth(int $columnIndex, int $width) + public function setColumnWidth(int $columnIndex, int $width): static { $this->columnWidths[$columnIndex] = $width; @@ -195,7 +195,7 @@ public function setColumnWidth(int $columnIndex, int $width) * * @return $this */ - public function setColumnWidths(array $widths) + public function setColumnWidths(array $widths): static { $this->columnWidths = []; foreach ($widths as $index => $width) { @@ -213,7 +213,7 @@ public function setColumnWidths(array $widths) * * @return $this */ - public function setColumnMaxWidth(int $columnIndex, int $width): self + public function setColumnMaxWidth(int $columnIndex, int $width): static { if (!$this->output->getFormatter() instanceof WrappableOutputFormatterInterface) { throw new \LogicException(sprintf('Setting a maximum column width is only supported when using a "%s" formatter, got "%s".', WrappableOutputFormatterInterface::class, get_debug_type($this->output->getFormatter()))); diff --git a/Helper/TableCell.php b/Helper/TableCell.php index 6abeacb09..2897319b1 100644 --- a/Helper/TableCell.php +++ b/Helper/TableCell.php @@ -54,7 +54,7 @@ public function __toString(): string * * @return int */ - public function getColspan() + public function getColspan(): int { return (int) $this->options['colspan']; } @@ -64,7 +64,7 @@ public function getColspan() * * @return int */ - public function getRowspan() + public function getRowspan(): int { return (int) $this->options['rowspan']; } diff --git a/Helper/TableCellStyle.php b/Helper/TableCellStyle.php index ad9aea83b..c2ff198b2 100644 --- a/Helper/TableCellStyle.php +++ b/Helper/TableCellStyle.php @@ -63,7 +63,7 @@ public function getOptions(): array * * @return string[] */ - public function getTagOptions() + public function getTagOptions(): array { return array_filter( $this->getOptions(), diff --git a/Helper/TableStyle.php b/Helper/TableStyle.php index 07265b467..c260fd9d7 100644 --- a/Helper/TableStyle.php +++ b/Helper/TableStyle.php @@ -53,7 +53,7 @@ class TableStyle * * @return $this */ - public function setPaddingChar(string $paddingChar) + public function setPaddingChar(string $paddingChar): static { if (!$paddingChar) { throw new LogicException('The padding char must not be empty.'); @@ -69,7 +69,7 @@ public function setPaddingChar(string $paddingChar) * * @return string */ - public function getPaddingChar() + public function getPaddingChar(): string { return $this->paddingChar; } @@ -196,7 +196,7 @@ public function setDefaultCrossingChar(string $char): self * * @return string */ - public function getCrossingChar() + public function getCrossingChar(): string { return $this->crossingChar; } @@ -229,7 +229,7 @@ public function getCrossingChars(): array * * @return $this */ - public function setCellHeaderFormat(string $cellHeaderFormat) + public function setCellHeaderFormat(string $cellHeaderFormat): static { $this->cellHeaderFormat = $cellHeaderFormat; @@ -241,7 +241,7 @@ public function setCellHeaderFormat(string $cellHeaderFormat) * * @return string */ - public function getCellHeaderFormat() + public function getCellHeaderFormat(): string { return $this->cellHeaderFormat; } @@ -251,7 +251,7 @@ public function getCellHeaderFormat() * * @return $this */ - public function setCellRowFormat(string $cellRowFormat) + public function setCellRowFormat(string $cellRowFormat): static { $this->cellRowFormat = $cellRowFormat; @@ -263,7 +263,7 @@ public function setCellRowFormat(string $cellRowFormat) * * @return string */ - public function getCellRowFormat() + public function getCellRowFormat(): string { return $this->cellRowFormat; } @@ -273,7 +273,7 @@ public function getCellRowFormat() * * @return $this */ - public function setCellRowContentFormat(string $cellRowContentFormat) + public function setCellRowContentFormat(string $cellRowContentFormat): static { $this->cellRowContentFormat = $cellRowContentFormat; @@ -285,7 +285,7 @@ public function setCellRowContentFormat(string $cellRowContentFormat) * * @return string */ - public function getCellRowContentFormat() + public function getCellRowContentFormat(): string { return $this->cellRowContentFormat; } @@ -295,7 +295,7 @@ public function getCellRowContentFormat() * * @return $this */ - public function setBorderFormat(string $borderFormat) + public function setBorderFormat(string $borderFormat): static { $this->borderFormat = $borderFormat; @@ -307,7 +307,7 @@ public function setBorderFormat(string $borderFormat) * * @return string */ - public function getBorderFormat() + public function getBorderFormat(): string { return $this->borderFormat; } @@ -317,7 +317,7 @@ public function getBorderFormat() * * @return $this */ - public function setPadType(int $padType) + public function setPadType(int $padType): static { 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).'); @@ -333,7 +333,7 @@ public function setPadType(int $padType) * * @return int */ - public function getPadType() + public function getPadType(): int { return $this->padType; } diff --git a/Input/ArgvInput.php b/Input/ArgvInput.php index 67323b536..62acac895 100644 --- a/Input/ArgvInput.php +++ b/Input/ArgvInput.php @@ -259,7 +259,7 @@ private function addLongOption(string $name, mixed $value) /** * {@inheritdoc} */ - public function getFirstArgument() + public function getFirstArgument(): ?string { $isOption = false; foreach ($this->tokens as $i => $token) { @@ -294,7 +294,7 @@ public function getFirstArgument() /** * {@inheritdoc} */ - public function hasParameterOption(string|array $values, bool $onlyParams = false) + public function hasParameterOption(string|array $values, bool $onlyParams = false): bool { $values = (array) $values; @@ -319,7 +319,7 @@ public function hasParameterOption(string|array $values, bool $onlyParams = fals /** * {@inheritdoc} */ - public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false) + public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false): mixed { $values = (array) $values; $tokens = $this->tokens; diff --git a/Input/ArrayInput.php b/Input/ArrayInput.php index cd2ae7797..4c423b08b 100644 --- a/Input/ArrayInput.php +++ b/Input/ArrayInput.php @@ -37,7 +37,7 @@ public function __construct(array $parameters, InputDefinition $definition = nul /** * {@inheritdoc} */ - public function getFirstArgument() + public function getFirstArgument(): ?string { foreach ($this->parameters as $param => $value) { if ($param && \is_string($param) && '-' === $param[0]) { @@ -53,7 +53,7 @@ public function getFirstArgument() /** * {@inheritdoc} */ - public function hasParameterOption(string|array $values, bool $onlyParams = false) + public function hasParameterOption(string|array $values, bool $onlyParams = false): bool { $values = (array) $values; @@ -77,7 +77,7 @@ public function hasParameterOption(string|array $values, bool $onlyParams = fals /** * {@inheritdoc} */ - public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false) + public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false): mixed { $values = (array) $values; diff --git a/Input/Input.php b/Input/Input.php index e8b30b9c6..c77885b22 100644 --- a/Input/Input.php +++ b/Input/Input.php @@ -80,7 +80,7 @@ public function validate() /** * {@inheritdoc} */ - public function isInteractive() + public function isInteractive(): bool { return $this->interactive; } @@ -96,7 +96,7 @@ public function setInteractive(bool $interactive) /** * {@inheritdoc} */ - public function getArguments() + public function getArguments(): array { return array_merge($this->definition->getArgumentDefaults(), $this->arguments); } @@ -104,7 +104,7 @@ public function getArguments() /** * {@inheritdoc} */ - public function getArgument(string $name) + public function getArgument(string $name): mixed { if (!$this->definition->hasArgument($name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); @@ -128,7 +128,7 @@ public function setArgument(string $name, mixed $value) /** * {@inheritdoc} */ - public function hasArgument(string $name) + public function hasArgument(string $name): bool { return $this->definition->hasArgument($name); } @@ -136,7 +136,7 @@ public function hasArgument(string $name) /** * {@inheritdoc} */ - public function getOptions() + public function getOptions(): array { return array_merge($this->definition->getOptionDefaults(), $this->options); } @@ -144,7 +144,7 @@ public function getOptions() /** * {@inheritdoc} */ - public function getOption(string $name) + public function getOption(string $name): mixed { if ($this->definition->hasNegation($name)) { if (null === $value = $this->getOption($this->definition->negationToName($name))) { @@ -180,7 +180,7 @@ public function setOption(string $name, mixed $value) /** * {@inheritdoc} */ - public function hasOption(string $name) + public function hasOption(string $name): bool { return $this->definition->hasOption($name) || $this->definition->hasNegation($name); } @@ -190,7 +190,7 @@ public function hasOption(string $name) * * @return string */ - public function escapeToken(string $token) + public function escapeToken(string $token): string { return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token); } diff --git a/Input/InputArgument.php b/Input/InputArgument.php index db9024117..1fb20e7a9 100644 --- a/Input/InputArgument.php +++ b/Input/InputArgument.php @@ -58,7 +58,7 @@ public function __construct(string $name, int $mode = null, string $description * * @return string The argument name */ - public function getName() + public function getName(): string { return $this->name; } @@ -68,7 +68,7 @@ public function getName() * * @return bool true if parameter mode is self::REQUIRED, false otherwise */ - public function isRequired() + public function isRequired(): bool { return self::REQUIRED === (self::REQUIRED & $this->mode); } @@ -78,7 +78,7 @@ public function isRequired() * * @return bool true if mode is self::IS_ARRAY, false otherwise */ - public function isArray() + public function isArray(): bool { return self::IS_ARRAY === (self::IS_ARRAY & $this->mode); } @@ -110,7 +110,7 @@ public function setDefault(string|bool|int|float|array $default = null) * * @return string|bool|int|float|array|null */ - public function getDefault() + public function getDefault(): string|bool|int|float|array|null { return $this->default; } @@ -120,7 +120,7 @@ public function getDefault() * * @return string The description text */ - public function getDescription() + public function getDescription(): string { return $this->description; } diff --git a/Input/InputDefinition.php b/Input/InputDefinition.php index cc9ff3515..0e1a910e1 100644 --- a/Input/InputDefinition.php +++ b/Input/InputDefinition.php @@ -128,7 +128,7 @@ public function addArgument(InputArgument $argument) * * @throws InvalidArgumentException When argument given doesn't exist */ - public function getArgument(string|int $name) + public function getArgument(string|int $name): InputArgument { if (!$this->hasArgument($name)) { throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name)); @@ -144,7 +144,7 @@ public function getArgument(string|int $name) * * @return bool true if the InputArgument object exists, false otherwise */ - public function hasArgument(string|int $name) + public function hasArgument(string|int $name): bool { $arguments = \is_int($name) ? array_values($this->arguments) : $this->arguments; @@ -156,7 +156,7 @@ public function hasArgument(string|int $name) * * @return InputArgument[] An array of InputArgument objects */ - public function getArguments() + public function getArguments(): array { return $this->arguments; } @@ -166,7 +166,7 @@ public function getArguments() * * @return int The number of InputArguments */ - public function getArgumentCount() + public function getArgumentCount(): int { return null !== $this->lastArrayArgument ? \PHP_INT_MAX : \count($this->arguments); } @@ -176,7 +176,7 @@ public function getArgumentCount() * * @return int The number of required InputArguments */ - public function getArgumentRequiredCount() + public function getArgumentRequiredCount(): int { return $this->requiredCount; } @@ -184,7 +184,7 @@ public function getArgumentRequiredCount() /** * @return array */ - public function getArgumentDefaults() + public function getArgumentDefaults(): array { $values = []; foreach ($this->arguments as $argument) { @@ -262,7 +262,7 @@ public function addOption(InputOption $option) * * @throws InvalidArgumentException When option given doesn't exist */ - public function getOption(string $name) + public function getOption(string $name): InputOption { if (!$this->hasOption($name)) { throw new InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name)); @@ -279,7 +279,7 @@ public function getOption(string $name) * * @return bool true if the InputOption object exists, false otherwise */ - public function hasOption(string $name) + public function hasOption(string $name): bool { return isset($this->options[$name]); } @@ -289,7 +289,7 @@ public function hasOption(string $name) * * @return InputOption[] An array of InputOption objects */ - public function getOptions() + public function getOptions(): array { return $this->options; } @@ -299,7 +299,7 @@ public function getOptions() * * @return bool true if the InputOption object exists, false otherwise */ - public function hasShortcut(string $name) + public function hasShortcut(string $name): bool { return isset($this->shortcuts[$name]); } @@ -317,7 +317,7 @@ public function hasNegation(string $name): bool * * @return InputOption An InputOption object */ - public function getOptionForShortcut(string $shortcut) + public function getOptionForShortcut(string $shortcut): InputOption { return $this->getOption($this->shortcutToName($shortcut)); } @@ -325,7 +325,7 @@ public function getOptionForShortcut(string $shortcut) /** * @return array */ - public function getOptionDefaults() + public function getOptionDefaults(): array { $values = []; foreach ($this->options as $option) { @@ -372,7 +372,7 @@ public function negationToName(string $negation): string * * @return string The synopsis */ - public function getSynopsis(bool $short = false) + public function getSynopsis(bool $short = false): string { $elements = []; diff --git a/Input/InputInterface.php b/Input/InputInterface.php index f67366fd0..0825cd8c5 100644 --- a/Input/InputInterface.php +++ b/Input/InputInterface.php @@ -26,7 +26,7 @@ interface InputInterface * * @return string|null The value of the first argument or null otherwise */ - public function getFirstArgument(); + public function getFirstArgument(): ?string; /** * Returns true if the raw parameters (not parsed) contain a value. @@ -41,7 +41,7 @@ public function getFirstArgument(); * * @return bool true if the value is contained in the raw parameters */ - public function hasParameterOption(string|array $values, bool $onlyParams = false); + public function hasParameterOption(string|array $values, bool $onlyParams = false): bool; /** * Returns the value of a raw option (not parsed). @@ -57,7 +57,7 @@ public function hasParameterOption(string|array $values, bool $onlyParams = fals * * @return mixed The option value */ - public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false); + public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false): mixed; /** * Binds the current Input instance with the given arguments and options. @@ -78,7 +78,7 @@ public function validate(); * * @return array */ - public function getArguments(); + public function getArguments(): array; /** * Returns the argument value for a given argument name. @@ -87,7 +87,7 @@ public function getArguments(); * * @throws InvalidArgumentException When argument given doesn't exist */ - public function getArgument(string $name); + public function getArgument(string $name): mixed; /** * Sets an argument value by name. @@ -101,14 +101,14 @@ public function setArgument(string $name, mixed $value); * * @return bool true if the InputArgument object exists, false otherwise */ - public function hasArgument(string $name); + public function hasArgument(string $name): bool; /** * Returns all the given options merged with the default values. * * @return array */ - public function getOptions(); + public function getOptions(): array; /** * Returns the option value for a given option name. @@ -117,7 +117,7 @@ public function getOptions(); * * @throws InvalidArgumentException When option given doesn't exist */ - public function getOption(string $name); + public function getOption(string $name): mixed; /** * Sets an option value by name. @@ -131,14 +131,14 @@ public function setOption(string $name, mixed $value); * * @return bool true if the InputOption object exists, false otherwise */ - public function hasOption(string $name); + public function hasOption(string $name): bool; /** * Is this input means interactive? * * @return bool */ - public function isInteractive(); + public function isInteractive(): bool; /** * Sets the input interactivity. diff --git a/Input/InputOption.php b/Input/InputOption.php index 5bc94a348..8f50ecf98 100644 --- a/Input/InputOption.php +++ b/Input/InputOption.php @@ -112,7 +112,7 @@ public function __construct(string $name, string|array $shortcut = null, int $mo * * @return string|null The shortcut */ - public function getShortcut() + public function getShortcut(): ?string { return $this->shortcut; } @@ -122,7 +122,7 @@ public function getShortcut() * * @return string The name */ - public function getName() + public function getName(): string { return $this->name; } @@ -132,7 +132,7 @@ public function getName() * * @return bool true if value mode is not self::VALUE_NONE, false otherwise */ - public function acceptValue() + public function acceptValue(): bool { return $this->isValueRequired() || $this->isValueOptional(); } @@ -142,7 +142,7 @@ public function acceptValue() * * @return bool true if value mode is self::VALUE_REQUIRED, false otherwise */ - public function isValueRequired() + public function isValueRequired(): bool { return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode); } @@ -152,7 +152,7 @@ public function isValueRequired() * * @return bool true if value mode is self::VALUE_OPTIONAL, false otherwise */ - public function isValueOptional() + public function isValueOptional(): bool { return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode); } @@ -162,7 +162,7 @@ public function isValueOptional() * * @return bool true if mode is self::VALUE_IS_ARRAY, false otherwise */ - public function isArray() + public function isArray(): bool { return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode); } @@ -194,7 +194,7 @@ public function setDefault(string|bool|int|float|array $default = null) * * @return string|bool|int|float|array|null */ - public function getDefault() + public function getDefault(): string|bool|int|float|array|null { return $this->default; } @@ -204,7 +204,7 @@ public function getDefault() * * @return string The description text */ - public function getDescription() + public function getDescription(): string { return $this->description; } @@ -214,7 +214,7 @@ public function getDescription() * * @return bool */ - public function equals(self $option) + public function equals(self $option): bool { return $option->getName() === $this->getName() && $option->getShortcut() === $this->getShortcut() diff --git a/Logger/ConsoleLogger.php b/Logger/ConsoleLogger.php index ab9ade0a1..74b41485e 100644 --- a/Logger/ConsoleLogger.php +++ b/Logger/ConsoleLogger.php @@ -90,7 +90,7 @@ public function log($level, $message, array $context = []): void * * @return bool */ - public function hasErrored() + public function hasErrored(): bool { return $this->errored; } diff --git a/Output/BufferedOutput.php b/Output/BufferedOutput.php index d37c6e323..bd1105650 100644 --- a/Output/BufferedOutput.php +++ b/Output/BufferedOutput.php @@ -23,7 +23,7 @@ class BufferedOutput extends Output * * @return string */ - public function fetch() + public function fetch(): string { $content = $this->buffer; $this->buffer = ''; diff --git a/Output/ConsoleOutput.php b/Output/ConsoleOutput.php index 2cda213a0..b88414ffc 100644 --- a/Output/ConsoleOutput.php +++ b/Output/ConsoleOutput.php @@ -94,7 +94,7 @@ public function setVerbosity(int $level) /** * {@inheritdoc} */ - public function getErrorOutput() + public function getErrorOutput(): OutputInterface { return $this->stderr; } @@ -113,7 +113,7 @@ public function setErrorOutput(OutputInterface $error) * * @return bool */ - protected function hasStdoutSupport() + protected function hasStdoutSupport(): bool { return false === $this->isRunningOS400(); } @@ -124,7 +124,7 @@ protected function hasStdoutSupport() * * @return bool */ - protected function hasStderrSupport() + protected function hasStderrSupport(): bool { return false === $this->isRunningOS400(); } diff --git a/Output/ConsoleOutputInterface.php b/Output/ConsoleOutputInterface.php index 6b6635f58..4c7c86051 100644 --- a/Output/ConsoleOutputInterface.php +++ b/Output/ConsoleOutputInterface.php @@ -24,7 +24,7 @@ interface ConsoleOutputInterface extends OutputInterface * * @return OutputInterface */ - public function getErrorOutput(); + public function getErrorOutput(): OutputInterface; public function setErrorOutput(OutputInterface $error); diff --git a/Output/NullOutput.php b/Output/NullOutput.php index 4c6f715ac..982f3c396 100644 --- a/Output/NullOutput.php +++ b/Output/NullOutput.php @@ -37,7 +37,7 @@ public function setFormatter(OutputFormatterInterface $formatter) /** * {@inheritdoc} */ - public function getFormatter() + public function getFormatter(): OutputFormatterInterface { if ($this->formatter) { return $this->formatter; @@ -57,7 +57,7 @@ public function setDecorated(bool $decorated) /** * {@inheritdoc} */ - public function isDecorated() + public function isDecorated(): bool { return false; } @@ -73,7 +73,7 @@ public function setVerbosity(int $level) /** * {@inheritdoc} */ - public function getVerbosity() + public function getVerbosity(): int { return self::VERBOSITY_QUIET; } @@ -81,7 +81,7 @@ public function getVerbosity() /** * {@inheritdoc} */ - public function isQuiet() + public function isQuiet(): bool { return true; } @@ -89,7 +89,7 @@ public function isQuiet() /** * {@inheritdoc} */ - public function isVerbose() + public function isVerbose(): bool { return false; } @@ -97,7 +97,7 @@ public function isVerbose() /** * {@inheritdoc} */ - public function isVeryVerbose() + public function isVeryVerbose(): bool { return false; } @@ -105,7 +105,7 @@ public function isVeryVerbose() /** * {@inheritdoc} */ - public function isDebug() + public function isDebug(): bool { return false; } diff --git a/Output/Output.php b/Output/Output.php index 8fd2cc370..27b2b9b5f 100644 --- a/Output/Output.php +++ b/Output/Output.php @@ -55,7 +55,7 @@ public function setFormatter(OutputFormatterInterface $formatter) /** * {@inheritdoc} */ - public function getFormatter() + public function getFormatter(): OutputFormatterInterface { return $this->formatter; } @@ -71,7 +71,7 @@ public function setDecorated(bool $decorated) /** * {@inheritdoc} */ - public function isDecorated() + public function isDecorated(): bool { return $this->formatter->isDecorated(); } @@ -87,7 +87,7 @@ public function setVerbosity(int $level) /** * {@inheritdoc} */ - public function getVerbosity() + public function getVerbosity(): int { return $this->verbosity; } @@ -95,7 +95,7 @@ public function getVerbosity() /** * {@inheritdoc} */ - public function isQuiet() + public function isQuiet(): bool { return self::VERBOSITY_QUIET === $this->verbosity; } @@ -103,7 +103,7 @@ public function isQuiet() /** * {@inheritdoc} */ - public function isVerbose() + public function isVerbose(): bool { return self::VERBOSITY_VERBOSE <= $this->verbosity; } @@ -111,7 +111,7 @@ public function isVerbose() /** * {@inheritdoc} */ - public function isVeryVerbose() + public function isVeryVerbose(): bool { return self::VERBOSITY_VERY_VERBOSE <= $this->verbosity; } @@ -119,7 +119,7 @@ public function isVeryVerbose() /** * {@inheritdoc} */ - public function isDebug() + public function isDebug(): bool { return self::VERBOSITY_DEBUG <= $this->verbosity; } diff --git a/Output/OutputInterface.php b/Output/OutputInterface.php index 1278a1a71..1295f4655 100644 --- a/Output/OutputInterface.php +++ b/Output/OutputInterface.php @@ -55,35 +55,35 @@ public function setVerbosity(int $level); * * @return int The current level of verbosity (one of the VERBOSITY constants) */ - public function getVerbosity(); + public function getVerbosity(): int; /** * Returns whether verbosity is quiet (-q). * * @return bool true if verbosity is set to VERBOSITY_QUIET, false otherwise */ - public function isQuiet(); + public function isQuiet(): bool; /** * Returns whether verbosity is verbose (-v). * * @return bool true if verbosity is set to VERBOSITY_VERBOSE, false otherwise */ - public function isVerbose(); + public function isVerbose(): bool; /** * Returns whether verbosity is very verbose (-vv). * * @return bool true if verbosity is set to VERBOSITY_VERY_VERBOSE, false otherwise */ - public function isVeryVerbose(); + public function isVeryVerbose(): bool; /** * Returns whether verbosity is debug (-vvv). * * @return bool true if verbosity is set to VERBOSITY_DEBUG, false otherwise */ - public function isDebug(); + public function isDebug(): bool; /** * Sets the decorated flag. @@ -95,7 +95,7 @@ public function setDecorated(bool $decorated); * * @return bool true if the output will decorate messages, false otherwise */ - public function isDecorated(); + public function isDecorated(): bool; public function setFormatter(OutputFormatterInterface $formatter); @@ -104,5 +104,5 @@ public function setFormatter(OutputFormatterInterface $formatter); * * @return OutputFormatterInterface */ - public function getFormatter(); + public function getFormatter(): OutputFormatterInterface; } diff --git a/Output/StreamOutput.php b/Output/StreamOutput.php index ea434527b..fdcb4d190 100644 --- a/Output/StreamOutput.php +++ b/Output/StreamOutput.php @@ -91,7 +91,7 @@ protected function doWrite(string $message, bool $newline) * * @return bool true if the stream supports colorization, false otherwise */ - protected function hasColorSupport() + protected function hasColorSupport(): bool { // Follow https://no-color.org/ if (isset($_SERVER['NO_COLOR']) || false !== getenv('NO_COLOR')) { diff --git a/Output/TrimmedBufferOutput.php b/Output/TrimmedBufferOutput.php index 5455c5b47..79332007f 100644 --- a/Output/TrimmedBufferOutput.php +++ b/Output/TrimmedBufferOutput.php @@ -38,7 +38,7 @@ public function __construct(int $maxLength, ?int $verbosity = self::VERBOSITY_NO * * @return string */ - public function fetch() + public function fetch(): string { $content = $this->buffer; $this->buffer = ''; diff --git a/Question/ChoiceQuestion.php b/Question/ChoiceQuestion.php index 6f7f6e735..85df8975b 100644 --- a/Question/ChoiceQuestion.php +++ b/Question/ChoiceQuestion.php @@ -48,7 +48,7 @@ public function __construct(string $question, array $choices, mixed $default = n * * @return array */ - public function getChoices() + public function getChoices(): array { return $this->choices; } @@ -60,7 +60,7 @@ public function getChoices() * * @return $this */ - public function setMultiselect(bool $multiselect) + public function setMultiselect(bool $multiselect): static { $this->multiselect = $multiselect; $this->setValidator($this->getDefaultValidator()); @@ -73,7 +73,7 @@ public function setMultiselect(bool $multiselect) * * @return bool */ - public function isMultiselect() + public function isMultiselect(): bool { return $this->multiselect; } @@ -83,7 +83,7 @@ public function isMultiselect() * * @return string */ - public function getPrompt() + public function getPrompt(): string { return $this->prompt; } @@ -93,7 +93,7 @@ public function getPrompt() * * @return $this */ - public function setPrompt(string $prompt) + public function setPrompt(string $prompt): static { $this->prompt = $prompt; @@ -107,7 +107,7 @@ public function setPrompt(string $prompt) * * @return $this */ - public function setErrorMessage(string $errorMessage) + public function setErrorMessage(string $errorMessage): static { $this->errorMessage = $errorMessage; $this->setValidator($this->getDefaultValidator()); diff --git a/Question/Question.php b/Question/Question.php index 654fc5472..8215ca9e2 100644 --- a/Question/Question.php +++ b/Question/Question.php @@ -47,7 +47,7 @@ public function __construct(string $question, string|bool|int|float $default = n * * @return string */ - public function getQuestion() + public function getQuestion(): string { return $this->question; } @@ -57,7 +57,7 @@ public function getQuestion() * * @return string|bool|int|float|null */ - public function getDefault() + public function getDefault(): string|bool|int|float|null { return $this->default; } @@ -75,7 +75,7 @@ public function isMultiline(): bool * * @return $this */ - public function setMultiline(bool $multiline): self + public function setMultiline(bool $multiline): static { $this->multiline = $multiline; @@ -87,7 +87,7 @@ public function setMultiline(bool $multiline): self * * @return bool */ - public function isHidden() + public function isHidden(): bool { return $this->hidden; } @@ -99,7 +99,7 @@ public function isHidden() * * @throws LogicException In case the autocompleter is also used */ - public function setHidden(bool $hidden) + public function setHidden(bool $hidden): static { if ($this->autocompleterCallback) { throw new LogicException('A hidden question cannot use the autocompleter.'); @@ -115,7 +115,7 @@ public function setHidden(bool $hidden) * * @return bool */ - public function isHiddenFallback() + public function isHiddenFallback(): bool { return $this->hiddenFallback; } @@ -125,7 +125,7 @@ public function isHiddenFallback() * * @return $this */ - public function setHiddenFallback(bool $fallback) + public function setHiddenFallback(bool $fallback): static { $this->hiddenFallback = (bool) $fallback; @@ -137,7 +137,7 @@ public function setHiddenFallback(bool $fallback) * * @return iterable|null */ - public function getAutocompleterValues() + public function getAutocompleterValues(): ?iterable { $callback = $this->getAutocompleterCallback(); @@ -151,7 +151,7 @@ public function getAutocompleterValues() * * @throws LogicException */ - public function setAutocompleterValues(?iterable $values) + public function setAutocompleterValues(?iterable $values): static { if (\is_array($values)) { $values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values); @@ -186,7 +186,7 @@ public function getAutocompleterCallback(): ?callable * * @return $this */ - public function setAutocompleterCallback(callable $callback = null): self + public function setAutocompleterCallback(callable $callback = null): static { if ($this->hidden && null !== $callback) { throw new LogicException('A hidden question cannot use the autocompleter.'); @@ -202,7 +202,7 @@ public function setAutocompleterCallback(callable $callback = null): self * * @return $this */ - public function setValidator(callable $validator = null) + public function setValidator(callable $validator = null): static { $this->validator = $validator; @@ -214,7 +214,7 @@ public function setValidator(callable $validator = null) * * @return callable|null */ - public function getValidator() + public function getValidator(): ?callable { return $this->validator; } @@ -228,7 +228,7 @@ public function getValidator() * * @throws InvalidArgumentException in case the number of attempts is invalid */ - public function setMaxAttempts(?int $attempts) + public function setMaxAttempts(?int $attempts): static { if (null !== $attempts) { $attempts = (int) $attempts; @@ -249,7 +249,7 @@ public function setMaxAttempts(?int $attempts) * * @return int|null */ - public function getMaxAttempts() + public function getMaxAttempts(): ?int { return $this->attempts; } @@ -261,7 +261,7 @@ public function getMaxAttempts() * * @return $this */ - public function setNormalizer(callable $normalizer) + public function setNormalizer(callable $normalizer): static { $this->normalizer = $normalizer; @@ -275,7 +275,7 @@ public function setNormalizer(callable $normalizer) * * @return callable|null */ - public function getNormalizer() + public function getNormalizer(): ?callable { return $this->normalizer; } @@ -293,7 +293,7 @@ public function isTrimmable(): bool /** * @return $this */ - public function setTrimmable(bool $trimmable): self + public function setTrimmable(bool $trimmable): static { $this->trimmable = $trimmable; diff --git a/Style/OutputStyle.php b/Style/OutputStyle.php index c1075aa4e..15e595fd1 100644 --- a/Style/OutputStyle.php +++ b/Style/OutputStyle.php @@ -41,7 +41,7 @@ public function newLine(int $count = 1) /** * @return ProgressBar */ - public function createProgressBar(int $max = 0) + public function createProgressBar(int $max = 0): ProgressBar { return new ProgressBar($this->output, $max); } @@ -73,7 +73,7 @@ public function setVerbosity(int $level) /** * {@inheritdoc} */ - public function getVerbosity() + public function getVerbosity(): int { return $this->output->getVerbosity(); } @@ -89,7 +89,7 @@ public function setDecorated(bool $decorated) /** * {@inheritdoc} */ - public function isDecorated() + public function isDecorated(): bool { return $this->output->isDecorated(); } @@ -105,7 +105,7 @@ public function setFormatter(OutputFormatterInterface $formatter) /** * {@inheritdoc} */ - public function getFormatter() + public function getFormatter(): OutputFormatterInterface { return $this->output->getFormatter(); } @@ -113,7 +113,7 @@ public function getFormatter() /** * {@inheritdoc} */ - public function isQuiet() + public function isQuiet(): bool { return $this->output->isQuiet(); } @@ -121,7 +121,7 @@ public function isQuiet() /** * {@inheritdoc} */ - public function isVerbose() + public function isVerbose(): bool { return $this->output->isVerbose(); } @@ -129,7 +129,7 @@ public function isVerbose() /** * {@inheritdoc} */ - public function isVeryVerbose() + public function isVeryVerbose(): bool { return $this->output->isVeryVerbose(); } @@ -137,7 +137,7 @@ public function isVeryVerbose() /** * {@inheritdoc} */ - public function isDebug() + public function isDebug(): bool { return $this->output->isDebug(); } diff --git a/Style/StyleInterface.php b/Style/StyleInterface.php index 7b0a35927..aeb69d774 100644 --- a/Style/StyleInterface.php +++ b/Style/StyleInterface.php @@ -73,28 +73,28 @@ public function table(array $headers, array $rows); * * @return mixed */ - public function ask(string $question, string $default = null, callable $validator = null); + public function ask(string $question, string $default = null, callable $validator = null): mixed; /** * Asks a question with the user input hidden. * * @return mixed */ - public function askHidden(string $question, callable $validator = null); + public function askHidden(string $question, callable $validator = null): mixed; /** * Asks for confirmation. * * @return bool */ - public function confirm(string $question, bool $default = true); + public function confirm(string $question, bool $default = true): bool; /** * Asks a choice question. * * @return mixed */ - public function choice(string $question, array $choices, mixed $default = null); + public function choice(string $question, array $choices, mixed $default = null): mixed; /** * Add newline(s). diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php index d5eb795aa..d1b1ec08d 100644 --- a/Style/SymfonyStyle.php +++ b/Style/SymfonyStyle.php @@ -256,7 +256,7 @@ public function definitionList(string|array|TableSeparator ...$list) /** * {@inheritdoc} */ - public function ask(string $question, string $default = null, callable $validator = null) + public function ask(string $question, string $default = null, callable $validator = null): mixed { $question = new Question($question, $default); $question->setValidator($validator); @@ -267,7 +267,7 @@ public function ask(string $question, string $default = null, callable $validato /** * {@inheritdoc} */ - public function askHidden(string $question, callable $validator = null) + public function askHidden(string $question, callable $validator = null): mixed { $question = new Question($question); @@ -280,7 +280,7 @@ public function askHidden(string $question, callable $validator = null) /** * {@inheritdoc} */ - public function confirm(string $question, bool $default = true) + public function confirm(string $question, bool $default = true): bool { return $this->askQuestion(new ConfirmationQuestion($question, $default)); } @@ -288,7 +288,7 @@ public function confirm(string $question, bool $default = true) /** * {@inheritdoc} */ - public function choice(string $question, array $choices, mixed $default = null) + public function choice(string $question, array $choices, mixed $default = null): mixed { if (null !== $default) { $values = array_flip($choices); @@ -328,7 +328,7 @@ public function progressFinish() /** * {@inheritdoc} */ - public function createProgressBar(int $max = 0) + public function createProgressBar(int $max = 0): ProgressBar { $progressBar = parent::createProgressBar($max); @@ -344,7 +344,7 @@ public function createProgressBar(int $max = 0) /** * @return mixed */ - public function askQuestion(Question $question) + public function askQuestion(Question $question): mixed { if ($this->input->isInteractive()) { $this->autoPrependBlock(); @@ -405,10 +405,8 @@ public function newLine(int $count = 1) /** * Returns a new instance which makes use of stderr if available. - * - * @return self */ - public function getErrorStyle() + public function getErrorStyle(): self { return new self($this->input, $this->getErrorOutput()); } diff --git a/Terminal.php b/Terminal.php index 08c53535b..5a0542782 100644 --- a/Terminal.php +++ b/Terminal.php @@ -22,7 +22,7 @@ class Terminal * * @return int */ - public function getWidth() + public function getWidth(): int { $width = getenv('COLUMNS'); if (false !== $width) { @@ -41,7 +41,7 @@ public function getWidth() * * @return int */ - public function getHeight() + public function getHeight(): int { $height = getenv('LINES'); if (false !== $height) { diff --git a/Tester/ApplicationTester.php b/Tester/ApplicationTester.php index d021c1435..82a7b282e 100644 --- a/Tester/ApplicationTester.php +++ b/Tester/ApplicationTester.php @@ -49,7 +49,7 @@ public function __construct(Application $application) * * @return int The command exit code */ - public function run(array $input, array $options = []) + public function run(array $input, array $options = []): int { $this->input = new ArrayInput($input); if (isset($options['interactive'])) { diff --git a/Tester/CommandTester.php b/Tester/CommandTester.php index 57efc9a67..fa55ce00e 100644 --- a/Tester/CommandTester.php +++ b/Tester/CommandTester.php @@ -48,7 +48,7 @@ public function __construct(Command $command) * * @return int The command exit code */ - public function execute(array $input, array $options = []) + public function execute(array $input, array $options = []): int { // set the command name automatically if the application requires // this argument and no command name was passed diff --git a/Tester/TesterTrait.php b/Tester/TesterTrait.php index 462e8a1f7..c33e59983 100644 --- a/Tester/TesterTrait.php +++ b/Tester/TesterTrait.php @@ -35,7 +35,7 @@ trait TesterTrait * * @return string The display */ - public function getDisplay(bool $normalize = false) + public function getDisplay(bool $normalize = false): string { if (null === $this->output) { throw new \RuntimeException('Output not initialized, did you execute the command before requesting the display?'); @@ -59,7 +59,7 @@ public function getDisplay(bool $normalize = false) * * @return string */ - public function getErrorOutput(bool $normalize = false) + public function getErrorOutput(bool $normalize = false): string { if (!$this->captureStreamsIndependently) { throw new \LogicException('The error output is not available when the tester is run without "capture_stderr_separately" option set.'); @@ -81,7 +81,7 @@ public function getErrorOutput(bool $normalize = false) * * @return InputInterface */ - public function getInput() + public function getInput(): InputInterface { return $this->input; } @@ -91,7 +91,7 @@ public function getInput() * * @return OutputInterface */ - public function getOutput() + public function getOutput(): OutputInterface { return $this->output; } @@ -103,7 +103,7 @@ public function getOutput() * * @return int The status code */ - public function getStatusCode() + public function getStatusCode(): int { if (null === $this->statusCode) { throw new \RuntimeException('Status code not initialized, did you execute the command before requesting the status code?'); @@ -125,7 +125,7 @@ public function assertCommandIsSuccessful(string $message = ''): void * * @return $this */ - public function setInputs(array $inputs) + public function setInputs(array $inputs): static { $this->inputs = $inputs; From 13d267b64d75b2cea03c8541d2321ae03d0dc80e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 16 Aug 2021 18:31:32 +0200 Subject: [PATCH 017/215] Run php-cs-fixer --- Application.php | 10 ---------- Command/Command.php | 12 ------------ CommandLoader/CommandLoaderInterface.php | 4 ---- CommandLoader/ContainerCommandLoader.php | 2 +- Event/ConsoleEvent.php | 6 ------ Formatter/OutputFormatter.php | 3 --- Formatter/OutputFormatterInterface.php | 6 ------ Formatter/OutputFormatterStyleInterface.php | 2 -- Formatter/OutputFormatterStyleStack.php | 7 ------- Helper/DebugFormatterHelper.php | 6 ------ Helper/FormatterHelper.php | 2 -- Helper/HelperSet.php | 4 ---- Helper/Table.php | 6 ------ Helper/TableCell.php | 4 ---- Helper/TableStyle.php | 14 -------------- Input/Input.php | 2 -- Input/InputInterface.php | 6 ------ Input/InputOption.php | 2 -- Logger/ConsoleLogger.php | 2 -- Output/BufferedOutput.php | 2 -- Output/ConsoleOutput.php | 4 ---- Output/ConsoleOutputInterface.php | 2 -- Output/OutputInterface.php | 2 -- Output/TrimmedBufferOutput.php | 2 -- Question/ChoiceQuestion.php | 6 ------ Question/Question.php | 14 -------------- Style/OutputStyle.php | 3 --- Style/StyleInterface.php | 8 -------- Style/SymfonyStyle.php | 3 --- Terminal.php | 4 ---- Tester/TesterTrait.php | 6 ------ 31 files changed, 1 insertion(+), 155 deletions(-) diff --git a/Application.php b/Application.php index 17006bccc..cbede10c2 100644 --- a/Application.php +++ b/Application.php @@ -312,8 +312,6 @@ public function setHelperSet(HelperSet $helperSet) /** * Get the helper set associated with the command. - * - * @return HelperSet */ public function getHelperSet(): HelperSet { @@ -331,8 +329,6 @@ public function setDefinition(InputDefinition $definition) /** * Gets the InputDefinition related to this Application. - * - * @return InputDefinition */ public function getDefinition(): InputDefinition { @@ -1019,8 +1015,6 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI /** * Gets the name of the command based on input. - * - * @return string|null */ protected function getCommandName(InputInterface $input): ?string { @@ -1029,8 +1023,6 @@ protected function getCommandName(InputInterface $input): ?string /** * Gets the default input definition. - * - * @return InputDefinition */ protected function getDefaultInputDefinition(): InputDefinition { @@ -1057,8 +1049,6 @@ protected function getDefaultCommands(): array /** * Gets the default helper set with the helpers that should always be available. - * - * @return HelperSet */ protected function getDefaultHelperSet(): HelperSet { diff --git a/Command/Command.php b/Command/Command.php index d11b84dd9..64fcd61f6 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -152,8 +152,6 @@ public function setHelperSet(HelperSet $helperSet) /** * Gets the helper set. - * - * @return HelperSet|null */ public function getHelperSet(): ?HelperSet { @@ -162,8 +160,6 @@ public function getHelperSet(): ?HelperSet /** * Gets the application instance for this command. - * - * @return Application|null */ public function getApplication(): ?Application { @@ -388,8 +384,6 @@ public function setDefinition(array|InputDefinition $definition): static /** * Gets the InputDefinition attached to this Command. - * - * @return InputDefinition */ public function getDefinition(): InputDefinition { @@ -403,8 +397,6 @@ public function getDefinition(): InputDefinition * be changed by merging with the application InputDefinition. * * This method is not part of public API and should not be used directly. - * - * @return InputDefinition */ public function getNativeDefinition(): InputDefinition { @@ -494,8 +486,6 @@ public function setProcessTitle(string $title): static /** * Returns the command name. - * - * @return string|null */ public function getName(): ?string { @@ -658,8 +648,6 @@ public function addUsage(string $usage): static /** * Returns alternative usages of the command. - * - * @return array */ public function getUsages(): array { diff --git a/CommandLoader/CommandLoaderInterface.php b/CommandLoader/CommandLoaderInterface.php index d297ceb24..3fc98e011 100644 --- a/CommandLoader/CommandLoaderInterface.php +++ b/CommandLoader/CommandLoaderInterface.php @@ -22,16 +22,12 @@ interface CommandLoaderInterface /** * Loads a command. * - * @return Command - * * @throws CommandNotFoundException */ public function get(string $name): Command; /** * Checks if a command exists. - * - * @return bool */ public function has(string $name): bool; diff --git a/CommandLoader/ContainerCommandLoader.php b/CommandLoader/ContainerCommandLoader.php index ede9096f5..d931dfa10 100644 --- a/CommandLoader/ContainerCommandLoader.php +++ b/CommandLoader/ContainerCommandLoader.php @@ -11,8 +11,8 @@ namespace Symfony\Component\Console\CommandLoader; -use Symfony\Component\Console\Command\Command; use Psr\Container\ContainerInterface; +use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\CommandNotFoundException; /** diff --git a/Event/ConsoleEvent.php b/Event/ConsoleEvent.php index b63e756b2..6d1412579 100644 --- a/Event/ConsoleEvent.php +++ b/Event/ConsoleEvent.php @@ -37,8 +37,6 @@ public function __construct(Command $command = null, InputInterface $input, Outp /** * Gets the command that is executed. - * - * @return Command|null */ public function getCommand(): ?Command { @@ -47,8 +45,6 @@ public function getCommand(): ?Command /** * Gets the input instance. - * - * @return InputInterface */ public function getInput(): InputInterface { @@ -57,8 +53,6 @@ public function getInput(): InputInterface /** * Gets the output instance. - * - * @return OutputInterface */ public function getOutput(): OutputInterface { diff --git a/Formatter/OutputFormatter.php b/Formatter/OutputFormatter.php index 5cc1fb307..989232838 100644 --- a/Formatter/OutputFormatter.php +++ b/Formatter/OutputFormatter.php @@ -185,9 +185,6 @@ public function formatAndWrap(?string $message, int $width) return str_replace('\\<', '<', $output); } - /** - * @return OutputFormatterStyleStack - */ public function getStyleStack(): OutputFormatterStyleStack { return $this->styleStack; diff --git a/Formatter/OutputFormatterInterface.php b/Formatter/OutputFormatterInterface.php index c6b9ab62f..751f25ec0 100644 --- a/Formatter/OutputFormatterInterface.php +++ b/Formatter/OutputFormatterInterface.php @@ -37,24 +37,18 @@ public function setStyle(string $name, OutputFormatterStyleInterface $style); /** * Checks if output formatter has style with specified name. - * - * @return bool */ public function hasStyle(string $name): bool; /** * Gets style options from style with specified name. * - * @return OutputFormatterStyleInterface - * * @throws \InvalidArgumentException When style isn't defined */ public function getStyle(string $name): OutputFormatterStyleInterface; /** * Formats a message according to the given styles. - * - * @return string|null */ public function format(?string $message): ?string; } diff --git a/Formatter/OutputFormatterStyleInterface.php b/Formatter/OutputFormatterStyleInterface.php index 120759f29..91d50aad2 100644 --- a/Formatter/OutputFormatterStyleInterface.php +++ b/Formatter/OutputFormatterStyleInterface.php @@ -45,8 +45,6 @@ public function setOptions(array $options); /** * Applies the style to a given text. - * - * @return string */ public function apply(string $text): string; } diff --git a/Formatter/OutputFormatterStyleStack.php b/Formatter/OutputFormatterStyleStack.php index a5695b1a5..1329b0e11 100644 --- a/Formatter/OutputFormatterStyleStack.php +++ b/Formatter/OutputFormatterStyleStack.php @@ -51,8 +51,6 @@ public function push(OutputFormatterStyleInterface $style) /** * Pops a style from the stack. * - * @return OutputFormatterStyleInterface - * * @throws InvalidArgumentException When style tags incorrectly nested */ public function pop(OutputFormatterStyleInterface $style = null): OutputFormatterStyleInterface @@ -78,8 +76,6 @@ public function pop(OutputFormatterStyleInterface $style = null): OutputFormatte /** * Computes current style with stacks top codes. - * - * @return OutputFormatterStyle */ public function getCurrent(): OutputFormatterStyle { @@ -100,9 +96,6 @@ public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle): static return $this; } - /** - * @return OutputFormatterStyleInterface - */ public function getEmptyStyle(): OutputFormatterStyleInterface { return $this->emptyStyle; diff --git a/Helper/DebugFormatterHelper.php b/Helper/DebugFormatterHelper.php index c1c281b21..7de5c19f8 100644 --- a/Helper/DebugFormatterHelper.php +++ b/Helper/DebugFormatterHelper.php @@ -26,8 +26,6 @@ class DebugFormatterHelper extends Helper /** * Starts a debug formatting session. - * - * @return string */ public function start(string $id, string $message, string $prefix = 'RUN'): string { @@ -38,8 +36,6 @@ public function start(string $id, string $message, string $prefix = 'RUN'): stri /** * Adds progress to a formatting session. - * - * @return string */ public function progress(string $id, string $buffer, bool $error = false, string $prefix = 'OUT', string $errorPrefix = 'ERR'): string { @@ -74,8 +70,6 @@ public function progress(string $id, string $buffer, bool $error = false, string /** * Stops a formatting session. - * - * @return string */ public function stop(string $id, string $message, bool $successful, string $prefix = 'RES'): string { diff --git a/Helper/FormatterHelper.php b/Helper/FormatterHelper.php index 6a6f26848..d2ece4f8d 100644 --- a/Helper/FormatterHelper.php +++ b/Helper/FormatterHelper.php @@ -66,8 +66,6 @@ public function formatBlock(string|array $messages, string $style, bool $large = /** * Truncates a message to the given length. - * - * @return string */ public function truncate(string $message, int $length, string $suffix = '...'): string { diff --git a/Helper/HelperSet.php b/Helper/HelperSet.php index ebe9e5aff..e4d8db6bf 100644 --- a/Helper/HelperSet.php +++ b/Helper/HelperSet.php @@ -60,8 +60,6 @@ public function has(string $name): bool /** * Gets a helper value. * - * @return HelperInterface - * * @throws InvalidArgumentException if the helper is not defined */ public function get(string $name): HelperInterface @@ -80,8 +78,6 @@ public function setCommand(Command $command = null) /** * Gets the command associated with this helper set. - * - * @return Command */ public function getCommand(): Command { diff --git a/Helper/Table.php b/Helper/Table.php index 8f94bc5e9..685353aef 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -114,8 +114,6 @@ public static function setStyleDefinition(string $name, TableStyle $style) /** * Gets a style definition by name. - * - * @return TableStyle */ public static function getStyleDefinition(string $name): TableStyle { @@ -144,8 +142,6 @@ public function setStyle(TableStyle|string $name): static /** * Gets the current table style. - * - * @return TableStyle */ public function getStyle(): TableStyle { @@ -170,8 +166,6 @@ public function setColumnStyle(int $columnIndex, TableStyle|string $name): stati * Gets the current style for a column. * * If style was not set, it returns the global table style. - * - * @return TableStyle */ public function getColumnStyle(int $columnIndex): TableStyle { diff --git a/Helper/TableCell.php b/Helper/TableCell.php index 2897319b1..0ddf92c5b 100644 --- a/Helper/TableCell.php +++ b/Helper/TableCell.php @@ -51,8 +51,6 @@ public function __toString(): string /** * Gets number of colspan. - * - * @return int */ public function getColspan(): int { @@ -61,8 +59,6 @@ public function getColspan(): int /** * Gets number of rowspan. - * - * @return int */ public function getRowspan(): int { diff --git a/Helper/TableStyle.php b/Helper/TableStyle.php index c260fd9d7..f30b6020e 100644 --- a/Helper/TableStyle.php +++ b/Helper/TableStyle.php @@ -66,8 +66,6 @@ public function setPaddingChar(string $paddingChar): static /** * Gets padding character, used for cell padding. - * - * @return string */ public function getPaddingChar(): string { @@ -193,8 +191,6 @@ public function setDefaultCrossingChar(string $char): self /** * Gets crossing character. - * - * @return string */ public function getCrossingChar(): string { @@ -238,8 +234,6 @@ public function setCellHeaderFormat(string $cellHeaderFormat): static /** * Gets header cell format. - * - * @return string */ public function getCellHeaderFormat(): string { @@ -260,8 +254,6 @@ public function setCellRowFormat(string $cellRowFormat): static /** * Gets row cell format. - * - * @return string */ public function getCellRowFormat(): string { @@ -282,8 +274,6 @@ public function setCellRowContentFormat(string $cellRowContentFormat): static /** * Gets row cell content format. - * - * @return string */ public function getCellRowContentFormat(): string { @@ -304,8 +294,6 @@ public function setBorderFormat(string $borderFormat): static /** * Gets table border format. - * - * @return string */ public function getBorderFormat(): string { @@ -330,8 +318,6 @@ public function setPadType(int $padType): static /** * Gets cell padding type. - * - * @return int */ public function getPadType(): int { diff --git a/Input/Input.php b/Input/Input.php index c77885b22..1db503cb2 100644 --- a/Input/Input.php +++ b/Input/Input.php @@ -187,8 +187,6 @@ public function hasOption(string $name): bool /** * Escapes a token through escapeshellarg if it contains unsafe chars. - * - * @return string */ public function escapeToken(string $token): string { diff --git a/Input/InputInterface.php b/Input/InputInterface.php index 0825cd8c5..fc26269ab 100644 --- a/Input/InputInterface.php +++ b/Input/InputInterface.php @@ -83,8 +83,6 @@ public function getArguments(): array; /** * Returns the argument value for a given argument name. * - * @return mixed - * * @throws InvalidArgumentException When argument given doesn't exist */ public function getArgument(string $name): mixed; @@ -113,8 +111,6 @@ public function getOptions(): array; /** * Returns the option value for a given option name. * - * @return mixed - * * @throws InvalidArgumentException When option given doesn't exist */ public function getOption(string $name): mixed; @@ -135,8 +131,6 @@ public function hasOption(string $name): bool; /** * Is this input means interactive? - * - * @return bool */ public function isInteractive(): bool; diff --git a/Input/InputOption.php b/Input/InputOption.php index 8f50ecf98..415411492 100644 --- a/Input/InputOption.php +++ b/Input/InputOption.php @@ -211,8 +211,6 @@ public function getDescription(): string /** * Checks whether the given option equals this one. - * - * @return bool */ public function equals(self $option): bool { diff --git a/Logger/ConsoleLogger.php b/Logger/ConsoleLogger.php index 74b41485e..4bf5f31a9 100644 --- a/Logger/ConsoleLogger.php +++ b/Logger/ConsoleLogger.php @@ -87,8 +87,6 @@ public function log($level, $message, array $context = []): void /** * Returns true when any messages have been logged at error levels. - * - * @return bool */ public function hasErrored(): bool { diff --git a/Output/BufferedOutput.php b/Output/BufferedOutput.php index bd1105650..7235b1f6b 100644 --- a/Output/BufferedOutput.php +++ b/Output/BufferedOutput.php @@ -20,8 +20,6 @@ class BufferedOutput extends Output /** * Empties buffer and returns its content. - * - * @return string */ public function fetch(): string { diff --git a/Output/ConsoleOutput.php b/Output/ConsoleOutput.php index b88414ffc..39c12d2c9 100644 --- a/Output/ConsoleOutput.php +++ b/Output/ConsoleOutput.php @@ -110,8 +110,6 @@ public function setErrorOutput(OutputInterface $error) /** * Returns true if current environment supports writing console output to * STDOUT. - * - * @return bool */ protected function hasStdoutSupport(): bool { @@ -121,8 +119,6 @@ protected function hasStdoutSupport(): bool /** * Returns true if current environment supports writing console output to * STDERR. - * - * @return bool */ protected function hasStderrSupport(): bool { diff --git a/Output/ConsoleOutputInterface.php b/Output/ConsoleOutputInterface.php index 4c7c86051..6b4babc6d 100644 --- a/Output/ConsoleOutputInterface.php +++ b/Output/ConsoleOutputInterface.php @@ -21,8 +21,6 @@ interface ConsoleOutputInterface extends OutputInterface { /** * Gets the OutputInterface for errors. - * - * @return OutputInterface */ public function getErrorOutput(): OutputInterface; diff --git a/Output/OutputInterface.php b/Output/OutputInterface.php index 1295f4655..a5deaa95c 100644 --- a/Output/OutputInterface.php +++ b/Output/OutputInterface.php @@ -101,8 +101,6 @@ public function setFormatter(OutputFormatterInterface $formatter); /** * Returns current output formatter instance. - * - * @return OutputFormatterInterface */ public function getFormatter(): OutputFormatterInterface; } diff --git a/Output/TrimmedBufferOutput.php b/Output/TrimmedBufferOutput.php index 2fa99720d..2c547a3f0 100644 --- a/Output/TrimmedBufferOutput.php +++ b/Output/TrimmedBufferOutput.php @@ -36,8 +36,6 @@ public function __construct(int $maxLength, ?int $verbosity = self::VERBOSITY_NO /** * Empties buffer and returns its content. - * - * @return string */ public function fetch(): string { diff --git a/Question/ChoiceQuestion.php b/Question/ChoiceQuestion.php index 85df8975b..bbba24ef1 100644 --- a/Question/ChoiceQuestion.php +++ b/Question/ChoiceQuestion.php @@ -45,8 +45,6 @@ public function __construct(string $question, array $choices, mixed $default = n /** * Returns available choices. - * - * @return array */ public function getChoices(): array { @@ -70,8 +68,6 @@ public function setMultiselect(bool $multiselect): static /** * Returns whether the choices are multiselect. - * - * @return bool */ public function isMultiselect(): bool { @@ -80,8 +76,6 @@ public function isMultiselect(): bool /** * Gets the prompt for choices. - * - * @return string */ public function getPrompt(): string { diff --git a/Question/Question.php b/Question/Question.php index 8215ca9e2..e851b485d 100644 --- a/Question/Question.php +++ b/Question/Question.php @@ -44,8 +44,6 @@ public function __construct(string $question, string|bool|int|float $default = n /** * Returns the question. - * - * @return string */ public function getQuestion(): string { @@ -84,8 +82,6 @@ public function setMultiline(bool $multiline): static /** * Returns whether the user response must be hidden. - * - * @return bool */ public function isHidden(): bool { @@ -112,8 +108,6 @@ public function setHidden(bool $hidden): static /** * In case the response can not be hidden, whether to fallback on non-hidden question or not. - * - * @return bool */ public function isHiddenFallback(): bool { @@ -134,8 +128,6 @@ public function setHiddenFallback(bool $fallback): static /** * Gets values for the autocompleter. - * - * @return iterable|null */ public function getAutocompleterValues(): ?iterable { @@ -211,8 +203,6 @@ public function setValidator(callable $validator = null): static /** * Gets the validator for the question. - * - * @return callable|null */ public function getValidator(): ?callable { @@ -246,8 +236,6 @@ public function setMaxAttempts(?int $attempts): static * Gets the maximum number of attempts. * * Null means an unlimited number of attempts. - * - * @return int|null */ public function getMaxAttempts(): ?int { @@ -272,8 +260,6 @@ public function setNormalizer(callable $normalizer): static * Gets the normalizer for the response. * * The normalizer can ba a callable (a string), a closure or a class implementing __invoke. - * - * @return callable|null */ public function getNormalizer(): ?callable { diff --git a/Style/OutputStyle.php b/Style/OutputStyle.php index 15e595fd1..0b2ded36c 100644 --- a/Style/OutputStyle.php +++ b/Style/OutputStyle.php @@ -38,9 +38,6 @@ public function newLine(int $count = 1) $this->output->write(str_repeat(\PHP_EOL, $count)); } - /** - * @return ProgressBar - */ public function createProgressBar(int $max = 0): ProgressBar { return new ProgressBar($this->output, $max); diff --git a/Style/StyleInterface.php b/Style/StyleInterface.php index aeb69d774..0bb123394 100644 --- a/Style/StyleInterface.php +++ b/Style/StyleInterface.php @@ -70,29 +70,21 @@ public function table(array $headers, array $rows); /** * Asks a question. - * - * @return mixed */ public function ask(string $question, string $default = null, callable $validator = null): mixed; /** * Asks a question with the user input hidden. - * - * @return mixed */ public function askHidden(string $question, callable $validator = null): mixed; /** * Asks for confirmation. - * - * @return bool */ public function confirm(string $question, bool $default = true): bool; /** * Asks a choice question. - * - * @return mixed */ public function choice(string $question, array $choices, mixed $default = null): mixed; diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php index d1b1ec08d..bea443c08 100644 --- a/Style/SymfonyStyle.php +++ b/Style/SymfonyStyle.php @@ -341,9 +341,6 @@ public function createProgressBar(int $max = 0): ProgressBar return $progressBar; } - /** - * @return mixed - */ public function askQuestion(Question $question): mixed { if ($this->input->isInteractive()) { diff --git a/Terminal.php b/Terminal.php index 5a0542782..953d6491e 100644 --- a/Terminal.php +++ b/Terminal.php @@ -19,8 +19,6 @@ class Terminal /** * Gets the terminal width. - * - * @return int */ public function getWidth(): int { @@ -38,8 +36,6 @@ public function getWidth(): int /** * Gets the terminal height. - * - * @return int */ public function getHeight(): int { diff --git a/Tester/TesterTrait.php b/Tester/TesterTrait.php index c33e59983..57e186894 100644 --- a/Tester/TesterTrait.php +++ b/Tester/TesterTrait.php @@ -56,8 +56,6 @@ public function getDisplay(bool $normalize = false): string * Gets the output written to STDERR by the application. * * @param bool $normalize Whether to normalize end of lines to \n or not - * - * @return string */ public function getErrorOutput(bool $normalize = false): string { @@ -78,8 +76,6 @@ public function getErrorOutput(bool $normalize = false): string /** * Gets the input instance used by the last execution of the command or application. - * - * @return InputInterface */ public function getInput(): InputInterface { @@ -88,8 +84,6 @@ public function getInput(): InputInterface /** * Gets the output instance used by the last execution of the command or application. - * - * @return OutputInterface */ public function getOutput(): OutputInterface { From ab93e72840badb0f84c842fd9203c56ded7503c2 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 18 Aug 2021 23:07:56 +0200 Subject: [PATCH 018/215] Remove HelperSet::setCommand() and getCommand() Signed-off-by: Alexander M. Turek --- CHANGELOG.md | 1 + Helper/HelperSet.php | 24 ------------------------ Tests/Helper/HelperSetTest.php | 30 ------------------------------ 3 files changed, 1 insertion(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 129a2ed82..fe6689757 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ CHANGELOG * Remove `Helper::strlen()`, use `Helper::width()` instead * Remove `Helper::strlenWithoutDecoration()`, use `Helper::removeDecoration()` instead * `AddConsoleCommandPass` can not be configured anymore + * Remove `HelperSet::setCommand()` and `getCommand()` without replacement 5.4 --- diff --git a/Helper/HelperSet.php b/Helper/HelperSet.php index 21d1fc796..0627381b6 100644 --- a/Helper/HelperSet.php +++ b/Helper/HelperSet.php @@ -11,7 +11,6 @@ namespace Symfony\Component\Console\Helper; -use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\InvalidArgumentException; /** @@ -25,7 +24,6 @@ class HelperSet implements \IteratorAggregate * @var Helper[] */ private $helpers = []; - private $command; /** * @param Helper[] $helpers An array of helper @@ -69,28 +67,6 @@ public function get(string $name): HelperInterface return $this->helpers[$name]; } - /** - * @deprecated since Symfony 5.4 - */ - public function setCommand(Command $command = null) - { - trigger_deprecation('symfony/console', '5.4', 'Method "%s()" is deprecated.', __METHOD__); - - $this->command = $command; - } - - /** - * Gets the command associated with this helper set. - * - * @deprecated since Symfony 5.4 - */ - public function getCommand(): Command - { - trigger_deprecation('symfony/console', '5.4', 'Method "%s()" is deprecated.', __METHOD__); - - return $this->command; - } - /** * @return \Traversable */ diff --git a/Tests/Helper/HelperSetTest.php b/Tests/Helper/HelperSetTest.php index 78d22939c..9fbb9afca 100644 --- a/Tests/Helper/HelperSetTest.php +++ b/Tests/Helper/HelperSetTest.php @@ -12,7 +12,6 @@ namespace Symfony\Component\Console\Tests\Helper; use PHPUnit\Framework\TestCase; -use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Exception\ExceptionInterface; use Symfony\Component\Console\Helper\HelperInterface; use Symfony\Component\Console\Helper\HelperSet; @@ -74,35 +73,6 @@ public function testGet() } } - /** - * @group legacy - */ - public function testSetCommand() - { - $cmd_01 = new Command('foo'); - $cmd_02 = new Command('bar'); - - $helperset = new HelperSet(); - $helperset->setCommand($cmd_01); - $this->assertEquals($cmd_01, $helperset->getCommand(), '->setCommand() stores given command'); - - $helperset = new HelperSet(); - $helperset->setCommand($cmd_01); - $helperset->setCommand($cmd_02); - $this->assertEquals($cmd_02, $helperset->getCommand(), '->setCommand() overwrites stored command with consecutive calls'); - } - - /** - * @group legacy - */ - public function testGetCommand() - { - $cmd = new Command('foo'); - $helperset = new HelperSet(); - $helperset->setCommand($cmd); - $this->assertEquals($cmd, $helperset->getCommand(), '->getCommand() retrieves stored command'); - } - public function testIteration() { $helperset = new HelperSet(); From 8e7ca3b0f2872fcd8c6591f63637aac911ea8455 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 26 Aug 2021 10:51:19 +0200 Subject: [PATCH 019/215] [Console] fix missing return type --- Helper/TableCellStyle.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Helper/TableCellStyle.php b/Helper/TableCellStyle.php index b99191251..833f22479 100644 --- a/Helper/TableCellStyle.php +++ b/Helper/TableCellStyle.php @@ -74,10 +74,7 @@ function ($key) { ); } - /** - * @return int - */ - public function getPadByAlign() + public function getPadByAlign(): int { return self::ALIGN_MAP[$this->getOptions()['align']]; } From ce7d4dab6dce087983fc7926c569e9686398e8cc Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Wed, 18 Aug 2021 22:47:30 +0200 Subject: [PATCH 020/215] [Console] Add types to private properties Signed-off-by: Alexander M. Turek --- Application.php | 44 +++++------ CI/GithubActionReporter.php | 2 +- Color.php | 6 +- Command/Command.php | 36 +++++---- Command/HelpCommand.php | 8 +- Command/LazyCommand.php | 4 +- Command/LockableTrait.php | 3 +- CommandLoader/ContainerCommandLoader.php | 4 +- CommandLoader/FactoryCommandLoader.php | 2 +- Cursor.php | 2 +- Descriptor/ApplicationDescription.php | 20 ++--- Event/ConsoleCommandEvent.php | 2 +- Event/ConsoleErrorEvent.php | 4 +- Event/ConsoleEvent.php | 4 +- Event/ConsoleSignalEvent.php | 2 +- Event/ConsoleTerminateEvent.php | 2 +- EventListener/ErrorListener.php | 2 +- Exception/CommandNotFoundException.php | 2 +- Formatter/NullOutputFormatter.php | 2 +- Formatter/OutputFormatter.php | 6 +- Formatter/OutputFormatterStyle.php | 18 ++--- Formatter/OutputFormatterStyleStack.php | 4 +- Helper/DebugFormatterHelper.php | 4 +- Helper/DescriptorHelper.php | 2 +- Helper/Dumper.php | 8 +- Helper/HelperSet.php | 2 +- Helper/ProgressBar.php | 70 ++++++++--------- Helper/ProgressIndicator.php | 31 ++++---- Helper/QuestionHelper.php | 6 +- Helper/Table.php | 96 ++++++------------------ Helper/TableCell.php | 4 +- Helper/TableCellStyle.php | 2 +- Helper/TableRows.php | 2 +- Helper/TableStyle.php | 48 ++++++------ Input/ArgvInput.php | 4 +- Input/ArrayInput.php | 2 +- Input/InputArgument.php | 8 +- Input/InputDefinition.php | 14 ++-- Input/InputOption.php | 10 +-- Logger/ConsoleLogger.php | 8 +- Output/BufferedOutput.php | 2 +- Output/ConsoleOutput.php | 4 +- Output/ConsoleSectionOutput.php | 8 +- Output/NullOutput.php | 7 +- Output/Output.php | 4 +- Output/TrimmedBufferOutput.php | 4 +- Question/ChoiceQuestion.php | 8 +- Question/ConfirmationQuestion.php | 2 +- Question/Question.php | 26 +++---- SignalRegistry/SignalRegistry.php | 2 +- SingleCommandApplication.php | 6 +- Style/OutputStyle.php | 2 +- Style/SymfonyStyle.php | 23 +++--- Terminal.php | 6 +- Tester/ApplicationTester.php | 2 +- Tester/CommandTester.php | 2 +- Tester/TesterTrait.php | 21 ++---- 57 files changed, 268 insertions(+), 361 deletions(-) diff --git a/Application.php b/Application.php index 801575e8f..dbea417c2 100644 --- a/Application.php +++ b/Application.php @@ -66,23 +66,23 @@ */ class Application implements ResetInterface { - private $commands = []; - private $wantHelps = false; - private $runningCommand; - private $name; - private $version; - private $commandLoader; - private $catchExceptions = true; - private $autoExit = true; - private $definition; - private $helperSet; - private $dispatcher; - private $terminal; - private $defaultCommand; - private $singleCommand = false; - private $initialized; - private $signalRegistry; - private $signalsToDispatchEvent = []; + private array $commands = []; + private bool $wantHelps = false; + private ?Command $runningCommand = null; + private string $name; + private string $version; + private ?CommandLoaderInterface $commandLoader = null; + private bool $catchExceptions = true; + private bool $autoExit = true; + private InputDefinition $definition; + private HelperSet $helperSet; + private ?EventDispatcherInterface $dispatcher = null; + private Terminal $terminal; + private string $defaultCommand; + private bool $singleCommand = false; + private bool $initialized = false; + private SignalRegistry $signalRegistry; + private array $signalsToDispatchEvent = []; public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN') { @@ -315,11 +315,7 @@ public function setHelperSet(HelperSet $helperSet) */ public function getHelperSet(): HelperSet { - if (!$this->helperSet) { - $this->helperSet = $this->getDefaultHelperSet(); - } - - return $this->helperSet; + return $this->helperSet ??= $this->getDefaultHelperSet(); } public function setDefinition(InputDefinition $definition) @@ -332,9 +328,7 @@ public function setDefinition(InputDefinition $definition) */ public function getDefinition(): InputDefinition { - if (!$this->definition) { - $this->definition = $this->getDefaultInputDefinition(); - } + $this->definition ??= $this->getDefaultInputDefinition(); if ($this->singleCommand) { $inputDefinition = $this->definition; diff --git a/CI/GithubActionReporter.php b/CI/GithubActionReporter.php index a15c1ff18..7e5565469 100644 --- a/CI/GithubActionReporter.php +++ b/CI/GithubActionReporter.php @@ -20,7 +20,7 @@ */ class GithubActionReporter { - private $output; + private OutputInterface $output; /** * @see https://github.com/actions/toolkit/blob/5e5e1b7aacba68a53836a34db4a288c3c1c1585b/packages/core/src/command.ts#L80-L85 diff --git a/Color.php b/Color.php index 22a4ce9ff..7fcc50707 100644 --- a/Color.php +++ b/Color.php @@ -49,9 +49,9 @@ final class Color 'conceal' => ['set' => 8, 'unset' => 28], ]; - private $foreground; - private $background; - private $options = []; + private string $foreground; + private string $background; + private array $options = []; public function __construct(string $foreground = '', string $background = '', array $options = []) { diff --git a/Command/Command.php b/Command/Command.php index 761b31d0d..782f79d6f 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -45,20 +45,20 @@ class Command */ protected static $defaultDescription; - private $application; - private $name; - private $processTitle; - private $aliases = []; - private $definition; - private $hidden = false; - private $help = ''; - private $description = ''; - private $fullDefinition; - private $ignoreValidationErrors = false; - private $code; - private $synopsis = []; - private $usages = []; - private $helperSet; + private ?Application $application = null; + private ?string $name = null; + private ?string $processTitle = null; + private array $aliases = []; + private InputDefinition $definition; + private bool $hidden = false; + private string $help = ''; + private string $description = ''; + private ?InputDefinition $fullDefinition = null; + private bool $ignoreValidationErrors = false; + private ?\Closure $code = null; + private array $synopsis = []; + private array $usages = []; + private ?HelperSet $helperSet = null; public static function getDefaultName(): ?string { @@ -324,6 +324,8 @@ public function setCode(callable $code): static restore_error_handler(); } } + } else { + $code = \Closure::fromCallable($code); } $this->code = $code; @@ -394,11 +396,7 @@ public function getDefinition(): InputDefinition */ public function getNativeDefinition(): InputDefinition { - if (null === $this->definition) { - throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', static::class)); - } - - return $this->definition; + return $this->definition ?? throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', static::class)); } /** diff --git a/Command/HelpCommand.php b/Command/HelpCommand.php index 72a079292..ccd5114fb 100644 --- a/Command/HelpCommand.php +++ b/Command/HelpCommand.php @@ -24,7 +24,7 @@ */ class HelpCommand extends Command { - private $command; + private Command $command; /** * {@inheritdoc} @@ -66,9 +66,7 @@ public function setCommand(Command $command) */ protected function execute(InputInterface $input, OutputInterface $output): int { - if (null === $this->command) { - $this->command = $this->getApplication()->find($input->getArgument('command_name')); - } + $this->command ??= $this->getApplication()->find($input->getArgument('command_name')); $helper = new DescriptorHelper(); $helper->describe($output, $this->command, [ @@ -76,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int 'raw_text' => $input->getOption('raw'), ]); - $this->command = null; + unset($this->command); return 0; } diff --git a/Command/LazyCommand.php b/Command/LazyCommand.php index 930cee0be..a0a4ce0aa 100644 --- a/Command/LazyCommand.php +++ b/Command/LazyCommand.php @@ -22,8 +22,8 @@ */ final class LazyCommand extends Command { - private $command; - private $isEnabled; + private \Closure|Command $command; + private ?bool $isEnabled; public function __construct(string $name, array $aliases, string $description, bool $isHidden, \Closure $commandFactory, ?bool $isEnabled = true) { diff --git a/Command/LockableTrait.php b/Command/LockableTrait.php index b1856dca7..67923a9e8 100644 --- a/Command/LockableTrait.php +++ b/Command/LockableTrait.php @@ -24,8 +24,7 @@ */ trait LockableTrait { - /** @var LockInterface|null */ - private $lock; + private ?LockInterface $lock = null; /** * Locks a command. diff --git a/CommandLoader/ContainerCommandLoader.php b/CommandLoader/ContainerCommandLoader.php index d931dfa10..651fb665e 100644 --- a/CommandLoader/ContainerCommandLoader.php +++ b/CommandLoader/ContainerCommandLoader.php @@ -22,8 +22,8 @@ */ class ContainerCommandLoader implements CommandLoaderInterface { - private $container; - private $commandMap; + private ContainerInterface $container; + private array $commandMap; /** * @param array $commandMap An array with command names as keys and service ids as values diff --git a/CommandLoader/FactoryCommandLoader.php b/CommandLoader/FactoryCommandLoader.php index 1c64bb872..c55dc1d02 100644 --- a/CommandLoader/FactoryCommandLoader.php +++ b/CommandLoader/FactoryCommandLoader.php @@ -21,7 +21,7 @@ */ class FactoryCommandLoader implements CommandLoaderInterface { - private $factories; + private array $factories; /** * @param callable[] $factories Indexed by command names diff --git a/Cursor.php b/Cursor.php index 202e28822..6ef2a212d 100644 --- a/Cursor.php +++ b/Cursor.php @@ -18,7 +18,7 @@ */ final class Cursor { - private $output; + private OutputInterface $output; private $input; /** diff --git a/Descriptor/ApplicationDescription.php b/Descriptor/ApplicationDescription.php index fac01ad37..5f32173ae 100644 --- a/Descriptor/ApplicationDescription.php +++ b/Descriptor/ApplicationDescription.php @@ -24,24 +24,20 @@ class ApplicationDescription { public const GLOBAL_NAMESPACE = '_global'; - private $application; - private $namespace; - private $showHidden; - - /** - * @var array - */ - private $namespaces; + private Application $application; + private ?string $namespace; + private bool $showHidden; + private array $namespaces; /** * @var array */ - private $commands; + private array $commands; /** * @var array */ - private $aliases; + private array $aliases = []; public function __construct(Application $application, string $namespace = null, bool $showHidden = false) { @@ -52,7 +48,7 @@ public function __construct(Application $application, string $namespace = null, public function getNamespaces(): array { - if (null === $this->namespaces) { + if (!isset($this->namespaces)) { $this->inspectApplication(); } @@ -64,7 +60,7 @@ public function getNamespaces(): array */ public function getCommands(): array { - if (null === $this->commands) { + if (!isset($this->commands)) { $this->inspectApplication(); } diff --git a/Event/ConsoleCommandEvent.php b/Event/ConsoleCommandEvent.php index 08bd18fd1..31c9ee99a 100644 --- a/Event/ConsoleCommandEvent.php +++ b/Event/ConsoleCommandEvent.php @@ -26,7 +26,7 @@ final class ConsoleCommandEvent extends ConsoleEvent /** * Indicates if the command should be run or skipped. */ - private $commandShouldRun = true; + private bool $commandShouldRun = true; /** * Disables the command, so it won't be run. diff --git a/Event/ConsoleErrorEvent.php b/Event/ConsoleErrorEvent.php index 57d9b38ba..19bd4bfdd 100644 --- a/Event/ConsoleErrorEvent.php +++ b/Event/ConsoleErrorEvent.php @@ -22,8 +22,8 @@ */ final class ConsoleErrorEvent extends ConsoleEvent { - private $error; - private $exitCode; + private \Throwable $error; + private int $exitCode; public function __construct(InputInterface $input, OutputInterface $output, \Throwable $error, Command $command = null) { diff --git a/Event/ConsoleEvent.php b/Event/ConsoleEvent.php index 56b8a9a60..6ba1615fe 100644 --- a/Event/ConsoleEvent.php +++ b/Event/ConsoleEvent.php @@ -25,8 +25,8 @@ class ConsoleEvent extends Event { protected $command; - private $input; - private $output; + private InputInterface $input; + private OutputInterface $output; public function __construct(?Command $command, InputInterface $input, OutputInterface $output) { diff --git a/Event/ConsoleSignalEvent.php b/Event/ConsoleSignalEvent.php index ef13ed2f5..766af691a 100644 --- a/Event/ConsoleSignalEvent.php +++ b/Event/ConsoleSignalEvent.php @@ -20,7 +20,7 @@ */ final class ConsoleSignalEvent extends ConsoleEvent { - private $handlingSignal; + private int $handlingSignal; public function __construct(Command $command, InputInterface $input, OutputInterface $output, int $handlingSignal) { diff --git a/Event/ConsoleTerminateEvent.php b/Event/ConsoleTerminateEvent.php index 190038d1a..de63c8ffa 100644 --- a/Event/ConsoleTerminateEvent.php +++ b/Event/ConsoleTerminateEvent.php @@ -22,7 +22,7 @@ */ final class ConsoleTerminateEvent extends ConsoleEvent { - private $exitCode; + private int $exitCode; public function __construct(Command $command, InputInterface $input, OutputInterface $output, int $exitCode) { diff --git a/EventListener/ErrorListener.php b/EventListener/ErrorListener.php index 61bd9d344..bcd918331 100644 --- a/EventListener/ErrorListener.php +++ b/EventListener/ErrorListener.php @@ -24,7 +24,7 @@ */ class ErrorListener implements EventSubscriberInterface { - private $logger; + private ?LoggerInterface $logger; public function __construct(LoggerInterface $logger = null) { diff --git a/Exception/CommandNotFoundException.php b/Exception/CommandNotFoundException.php index 78eee8762..1e9f1c793 100644 --- a/Exception/CommandNotFoundException.php +++ b/Exception/CommandNotFoundException.php @@ -18,7 +18,7 @@ */ class CommandNotFoundException extends \InvalidArgumentException implements ExceptionInterface { - private $alternatives; + private array $alternatives; /** * @param string $message Exception message to throw diff --git a/Formatter/NullOutputFormatter.php b/Formatter/NullOutputFormatter.php index d770e1465..d14db326a 100644 --- a/Formatter/NullOutputFormatter.php +++ b/Formatter/NullOutputFormatter.php @@ -16,7 +16,7 @@ */ final class NullOutputFormatter implements OutputFormatterInterface { - private $style; + private NullOutputFormatterStyle $style; /** * {@inheritdoc} diff --git a/Formatter/OutputFormatter.php b/Formatter/OutputFormatter.php index 339a4e052..bc47f6e10 100644 --- a/Formatter/OutputFormatter.php +++ b/Formatter/OutputFormatter.php @@ -21,9 +21,9 @@ */ class OutputFormatter implements WrappableOutputFormatterInterface { - private $decorated; - private $styles = []; - private $styleStack; + private bool $decorated; + private array $styles = []; + private OutputFormatterStyleStack $styleStack; public function __clone() { diff --git a/Formatter/OutputFormatterStyle.php b/Formatter/OutputFormatterStyle.php index 6514549a7..9e8ea967e 100644 --- a/Formatter/OutputFormatterStyle.php +++ b/Formatter/OutputFormatterStyle.php @@ -20,12 +20,12 @@ */ class OutputFormatterStyle implements OutputFormatterStyleInterface { - private $color; - private $foreground; - private $background; - private $options; - private $href; - private $handlesHrefGracefully; + private Color $color; + private string $foreground; + private string $background; + private array $options; + private ?string $href = null; + private bool $handlesHrefGracefully; /** * Initializes output formatter style. @@ -94,10 +94,8 @@ public function setOptions(array $options) */ public function apply(string $text): string { - if (null === $this->handlesHrefGracefully) { - $this->handlesHrefGracefully = 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') - && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100); - } + $this->handlesHrefGracefully ??= 'JetBrains-JediTerm' !== getenv('TERMINAL_EMULATOR') + && (!getenv('KONSOLE_VERSION') || (int) getenv('KONSOLE_VERSION') > 201100); if (null !== $this->href && $this->handlesHrefGracefully) { $text = "\033]8;;$this->href\033\\$text\033]8;;\033\\"; diff --git a/Formatter/OutputFormatterStyleStack.php b/Formatter/OutputFormatterStyleStack.php index 1329b0e11..e72b641ba 100644 --- a/Formatter/OutputFormatterStyleStack.php +++ b/Formatter/OutputFormatterStyleStack.php @@ -22,9 +22,9 @@ class OutputFormatterStyleStack implements ResetInterface /** * @var OutputFormatterStyleInterface[] */ - private $styles; + private array $styles = []; - private $emptyStyle; + private OutputFormatterStyleInterface $emptyStyle; public function __construct(OutputFormatterStyleInterface $emptyStyle = null) { diff --git a/Helper/DebugFormatterHelper.php b/Helper/DebugFormatterHelper.php index 4387d6a52..64c7cffff 100644 --- a/Helper/DebugFormatterHelper.php +++ b/Helper/DebugFormatterHelper.php @@ -21,8 +21,8 @@ class DebugFormatterHelper extends Helper { private const COLORS = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default']; - private $started = []; - private $count = -1; + private array $started = []; + private int $count = -1; /** * Starts a debug formatting session. diff --git a/Helper/DescriptorHelper.php b/Helper/DescriptorHelper.php index e975edbdc..2b09fe6d8 100644 --- a/Helper/DescriptorHelper.php +++ b/Helper/DescriptorHelper.php @@ -29,7 +29,7 @@ class DescriptorHelper extends Helper /** * @var DescriptorInterface[] */ - private $descriptors = []; + private array $descriptors = []; public function __construct() { diff --git a/Helper/Dumper.php b/Helper/Dumper.php index cc962e58d..76b76c0a4 100644 --- a/Helper/Dumper.php +++ b/Helper/Dumper.php @@ -21,10 +21,10 @@ */ final class Dumper { - private $output; - private $dumper; - private $cloner; - private $handler; + private OutputInterface $output; + private ?CliDumper $dumper; + private ?ClonerInterface $cloner; + private \Closure $handler; public function __construct(OutputInterface $output, CliDumper $dumper = null, ClonerInterface $cloner = null) { diff --git a/Helper/HelperSet.php b/Helper/HelperSet.php index 0627381b6..820ac4d5f 100644 --- a/Helper/HelperSet.php +++ b/Helper/HelperSet.php @@ -23,7 +23,7 @@ class HelperSet implements \IteratorAggregate /** * @var Helper[] */ - private $helpers = []; + private array $helpers = []; /** * @param Helper[] $helpers An array of helper diff --git a/Helper/ProgressBar.php b/Helper/ProgressBar.php index b1fb213b6..b087b4b92 100644 --- a/Helper/ProgressBar.php +++ b/Helper/ProgressBar.php @@ -36,32 +36,32 @@ final class ProgressBar private const FORMAT_DEBUG_NOMAX = 'debug_nomax'; private const FORMAT_NORMAL_NOMAX = 'normal_nomax'; - private $barWidth = 28; - private $barChar; - private $emptyBarChar = '-'; - private $progressChar = '>'; - private $format; - private $internalFormat; - private $redrawFreq = 1; - private $writeCount; - private $lastWriteTime; - private $minSecondsBetweenRedraws = 0; - private $maxSecondsBetweenRedraws = 1; - private $output; - private $step = 0; - private $max; - private $startTime; - private $stepWidth; - private $percent = 0.0; - private $formatLineCount; - private $messages = []; - private $overwrite = true; - private $terminal; - private $previousMessage; - private $cursor; - - private static $formatters; - private static $formats; + private int $barWidth = 28; + private string $barChar; + private string $emptyBarChar = '-'; + private string $progressChar = '>'; + private ?string $format = null; + private ?string $internalFormat = null; + private ?int $redrawFreq = 1; + private int $writeCount = 0; + private float $lastWriteTime = 0; + private float $minSecondsBetweenRedraws = 0; + private float $maxSecondsBetweenRedraws = 1; + private OutputInterface $output; + private int $step = 0; + private ?int $max = null; + private int $startTime; + private int $stepWidth; + private float $percent = 0.0; + private int $formatLineCount; + private array $messages = []; + private bool $overwrite = true; + private Terminal $terminal; + private ?string $previousMessage = null; + private Cursor $cursor; + + private static array $formatters; + private static array $formats; /** * @param int $max Maximum steps (0 if unknown) @@ -103,9 +103,7 @@ public function __construct(OutputInterface $output, int $max = 0, float $minSec */ public static function setPlaceholderFormatterDefinition(string $name, callable $callable): void { - if (!self::$formatters) { - self::$formatters = self::initPlaceholderFormatters(); - } + self::$formatters ??= self::initPlaceholderFormatters(); self::$formatters[$name] = $callable; } @@ -117,9 +115,7 @@ public static function setPlaceholderFormatterDefinition(string $name, callable */ public static function getPlaceholderFormatterDefinition(string $name): ?callable { - if (!self::$formatters) { - self::$formatters = self::initPlaceholderFormatters(); - } + self::$formatters ??= self::initPlaceholderFormatters(); return self::$formatters[$name] ?? null; } @@ -134,9 +130,7 @@ public static function getPlaceholderFormatterDefinition(string $name): ?callabl */ public static function setFormatDefinition(string $name, string $format): void { - if (!self::$formats) { - self::$formats = self::initFormats(); - } + self::$formats ??= self::initFormats(); self::$formats[$name] = $format; } @@ -148,9 +142,7 @@ public static function setFormatDefinition(string $name, string $format): void */ public static function getFormatDefinition(string $name): ?string { - if (!self::$formats) { - self::$formats = self::initFormats(); - } + self::$formats ??= self::initFormats(); return self::$formats[$name] ?? null; } @@ -574,6 +566,8 @@ private static function initFormats(): array private function buildLine(): string { + \assert(null !== $this->format); + $regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i"; $callback = function ($matches) { if ($formatter = $this::getPlaceholderFormatterDefinition($matches[1])) { diff --git a/Helper/ProgressIndicator.php b/Helper/ProgressIndicator.php index 135ead716..9ca24e942 100644 --- a/Helper/ProgressIndicator.php +++ b/Helper/ProgressIndicator.php @@ -31,20 +31,20 @@ class ProgressIndicator 'very_verbose_no_ansi' => ' %message% (%elapsed:6s%, %memory:6s%)', ]; - private $output; - private $startTime; - private $format; - private $message; - private $indicatorValues; - private $indicatorCurrent; - private $indicatorChangeInterval; - private $indicatorUpdateTime; - private $started = false; + private OutputInterface $output; + private int $startTime; + private ?string $format = null; + private ?string $message = null; + private array $indicatorValues; + private int $indicatorCurrent; + private int $indicatorChangeInterval; + private float $indicatorUpdateTime; + private bool $started = false; /** * @var array */ - private static $formatters; + private static array $formatters; /** * @param int $indicatorChangeInterval Change interval in milliseconds @@ -159,9 +159,7 @@ public static function getFormatDefinition(string $name): ?string */ public static function setPlaceholderFormatterDefinition(string $name, callable $callable) { - if (!self::$formatters) { - self::$formatters = self::initPlaceholderFormatters(); - } + self::$formatters ??= self::initPlaceholderFormatters(); self::$formatters[$name] = $callable; } @@ -171,9 +169,7 @@ public static function setPlaceholderFormatterDefinition(string $name, callable */ public static function getPlaceholderFormatterDefinition(string $name): ?callable { - if (!self::$formatters) { - self::$formatters = self::initPlaceholderFormatters(); - } + self::$formatters ??= self::initPlaceholderFormatters(); return self::$formatters[$name] ?? null; } @@ -225,6 +221,9 @@ private function getCurrentTimeInMilliseconds(): float return round(microtime(true) * 1000); } + /** + * @return array + */ private static function initPlaceholderFormatters(): array { return [ diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index 21b4cc543..fab1b3d67 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -38,8 +38,8 @@ class QuestionHelper extends Helper */ private $inputStream; - private static $stty = true; - private static $stdinIsInteractive; + private static bool $stty = true; + private static bool $stdinIsInteractive; /** * Asks a question to the user. @@ -473,7 +473,7 @@ private function isInteractiveInput($inputStream): bool return false; } - if (null !== self::$stdinIsInteractive) { + if (isset(self::$stdinIsInteractive)) { return self::$stdinIsInteractive; } diff --git a/Helper/Table.php b/Helper/Table.php index 5201f73a2..758e9c5fb 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -36,69 +36,27 @@ class Table private const BORDER_OUTSIDE = 0; private const BORDER_INSIDE = 1; - private $headerTitle; - private $footerTitle; - - /** - * Table headers. - */ - private $headers = []; - - /** - * Table rows. - */ - private $rows = []; - private $horizontal = false; - - /** - * Column widths cache. - */ - private $effectiveColumnWidths = []; - - /** - * Number of columns cache. - * - * @var int - */ - private $numberOfColumns; - - /** - * @var OutputInterface - */ - private $output; - - /** - * @var TableStyle - */ - private $style; - - /** - * @var array - */ - private $columnStyles = []; - - /** - * User set column widths. - * - * @var array - */ - private $columnWidths = []; - private $columnMaxWidths = []; - - /** - * @var array|null - */ - private static $styles; - - private $rendered = false; + private ?string $headerTitle = null; + private ?string $footerTitle = null; + private array $headers = []; + private array $rows = []; + private bool $horizontal = false; + private array $effectiveColumnWidths = []; + private int $numberOfColumns; + private OutputInterface $output; + private TableStyle $style; + private array $columnStyles = []; + private array $columnWidths = []; + private array $columnMaxWidths = []; + private bool $rendered = false; + + private static array $styles; public function __construct(OutputInterface $output) { $this->output = $output; - if (!self::$styles) { - self::$styles = self::initStyles(); - } + self::$styles ??= self::initStyles(); $this->setStyle('default'); } @@ -108,9 +66,7 @@ public function __construct(OutputInterface $output) */ public static function setStyleDefinition(string $name, TableStyle $style) { - if (!self::$styles) { - self::$styles = self::initStyles(); - } + self::$styles ??= self::initStyles(); self::$styles[$name] = $style; } @@ -120,15 +76,9 @@ public static function setStyleDefinition(string $name, TableStyle $style) */ public static function getStyleDefinition(string $name): TableStyle { - if (!self::$styles) { - self::$styles = self::initStyles(); - } + self::$styles ??= self::initStyles(); - if (isset(self::$styles[$name])) { - return self::$styles[$name]; - } - - throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); + return self::$styles[$name] ?? throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); } /** @@ -791,7 +741,7 @@ private function getCellWidth(array $row, int $column): int private function cleanup() { $this->effectiveColumnWidths = []; - $this->numberOfColumns = null; + unset($this->numberOfColumns); } /** @@ -850,10 +800,6 @@ private function resolveStyle(TableStyle|string $name): TableStyle return $name; } - if (isset(self::$styles[$name])) { - return self::$styles[$name]; - } - - throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); + return self::$styles[$name] ?? throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name)); } } diff --git a/Helper/TableCell.php b/Helper/TableCell.php index 0ddf92c5b..394b2bc95 100644 --- a/Helper/TableCell.php +++ b/Helper/TableCell.php @@ -18,8 +18,8 @@ */ class TableCell { - private $value; - private $options = [ + private string $value; + private array $options = [ 'rowspan' => 1, 'colspan' => 1, 'style' => null, diff --git a/Helper/TableCellStyle.php b/Helper/TableCellStyle.php index 833f22479..65ae9e728 100644 --- a/Helper/TableCellStyle.php +++ b/Helper/TableCellStyle.php @@ -32,7 +32,7 @@ class TableCellStyle 'right' => \STR_PAD_LEFT, ]; - private $options = [ + private array $options = [ 'fg' => 'default', 'bg' => 'default', 'options' => null, diff --git a/Helper/TableRows.php b/Helper/TableRows.php index cbc07d294..97d07726e 100644 --- a/Helper/TableRows.php +++ b/Helper/TableRows.php @@ -16,7 +16,7 @@ */ class TableRows implements \IteratorAggregate { - private $generator; + private \Closure $generator; public function __construct(\Closure $generator) { diff --git a/Helper/TableStyle.php b/Helper/TableStyle.php index f30b6020e..7c3cb86b2 100644 --- a/Helper/TableStyle.php +++ b/Helper/TableStyle.php @@ -23,30 +23,30 @@ */ class TableStyle { - private $paddingChar = ' '; - private $horizontalOutsideBorderChar = '-'; - private $horizontalInsideBorderChar = '-'; - private $verticalOutsideBorderChar = '|'; - private $verticalInsideBorderChar = '|'; - private $crossingChar = '+'; - private $crossingTopRightChar = '+'; - private $crossingTopMidChar = '+'; - private $crossingTopLeftChar = '+'; - private $crossingMidRightChar = '+'; - private $crossingBottomRightChar = '+'; - private $crossingBottomMidChar = '+'; - private $crossingBottomLeftChar = '+'; - private $crossingMidLeftChar = '+'; - private $crossingTopLeftBottomChar = '+'; - private $crossingTopMidBottomChar = '+'; - private $crossingTopRightBottomChar = '+'; - private $headerTitleFormat = ' %s '; - private $footerTitleFormat = ' %s '; - private $cellHeaderFormat = '%s'; - private $cellRowFormat = '%s'; - private $cellRowContentFormat = ' %s '; - private $borderFormat = '%s'; - private $padType = \STR_PAD_RIGHT; + private string $paddingChar = ' '; + private string $horizontalOutsideBorderChar = '-'; + private string $horizontalInsideBorderChar = '-'; + private string $verticalOutsideBorderChar = '|'; + private string $verticalInsideBorderChar = '|'; + private string $crossingChar = '+'; + private string $crossingTopRightChar = '+'; + private string $crossingTopMidChar = '+'; + private string $crossingTopLeftChar = '+'; + private string $crossingMidRightChar = '+'; + private string $crossingBottomRightChar = '+'; + private string $crossingBottomMidChar = '+'; + private string $crossingBottomLeftChar = '+'; + private string $crossingMidLeftChar = '+'; + private string $crossingTopLeftBottomChar = '+'; + private string $crossingTopMidBottomChar = '+'; + private string $crossingTopRightBottomChar = '+'; + private string $headerTitleFormat = ' %s '; + private string $footerTitleFormat = ' %s '; + private string $cellHeaderFormat = '%s'; + private string $cellRowFormat = '%s'; + private string $cellRowContentFormat = ' %s '; + private string $borderFormat = '%s'; + private int $padType = \STR_PAD_RIGHT; /** * Sets padding character, used for cell padding. diff --git a/Input/ArgvInput.php b/Input/ArgvInput.php index 62acac895..2f973d81a 100644 --- a/Input/ArgvInput.php +++ b/Input/ArgvInput.php @@ -40,8 +40,8 @@ */ class ArgvInput extends Input { - private $tokens; - private $parsed; + private array $tokens; + private array $parsed; public function __construct(array $argv = null, InputDefinition $definition = null) { diff --git a/Input/ArrayInput.php b/Input/ArrayInput.php index 4c423b08b..fdb47df4d 100644 --- a/Input/ArrayInput.php +++ b/Input/ArrayInput.php @@ -25,7 +25,7 @@ */ class ArrayInput extends Input { - private $parameters; + private array $parameters; public function __construct(array $parameters, InputDefinition $definition = null) { diff --git a/Input/InputArgument.php b/Input/InputArgument.php index 3c8842196..f89fa33c9 100644 --- a/Input/InputArgument.php +++ b/Input/InputArgument.php @@ -25,10 +25,10 @@ class InputArgument public const OPTIONAL = 2; public const IS_ARRAY = 4; - private $name; - private $mode; - private $default; - private $description; + private string $name; + private int $mode; + private string|int|bool|array|null|float $default; + private string $description; /** * @param string $name The argument name diff --git a/Input/InputDefinition.php b/Input/InputDefinition.php index e5d3e0995..f4b14a1c8 100644 --- a/Input/InputDefinition.php +++ b/Input/InputDefinition.php @@ -28,13 +28,13 @@ */ class InputDefinition { - private $arguments; - private $requiredCount; - private $lastArrayArgument; - private $lastOptionalArgument; - private $options; - private $negations; - private $shortcuts; + private array $arguments = []; + private int $requiredCount = 0; + private ?InputArgument $lastArrayArgument = null; + private ?InputArgument $lastOptionalArgument = null; + private array $options = []; + private array $negations = []; + private array $shortcuts = []; /** * @param array $definition An array of InputArgument and InputOption instance diff --git a/Input/InputOption.php b/Input/InputOption.php index 8e4ace579..613af2035 100644 --- a/Input/InputOption.php +++ b/Input/InputOption.php @@ -46,11 +46,11 @@ class InputOption */ public const VALUE_NEGATABLE = 16; - private $name; - private $shortcut; - private $mode; - private $default; - private $description; + private string $name; + private string|array|null $shortcut; + private int $mode; + private string|int|bool|array|null|float $default; + private string $description; /** * @param string|array|null $shortcut The shortcuts, can be null, a string of shortcuts delimited by | or an array of shortcuts diff --git a/Logger/ConsoleLogger.php b/Logger/ConsoleLogger.php index 4bf5f31a9..8d028ac8e 100644 --- a/Logger/ConsoleLogger.php +++ b/Logger/ConsoleLogger.php @@ -29,8 +29,8 @@ class ConsoleLogger extends AbstractLogger public const INFO = 'info'; public const ERROR = 'error'; - private $output; - private $verbosityLevelMap = [ + private OutputInterface $output; + private array $verbosityLevelMap = [ LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL, @@ -40,7 +40,7 @@ class ConsoleLogger extends AbstractLogger LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE, LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG, ]; - private $formatLevelMap = [ + private array $formatLevelMap = [ LogLevel::EMERGENCY => self::ERROR, LogLevel::ALERT => self::ERROR, LogLevel::CRITICAL => self::ERROR, @@ -50,7 +50,7 @@ class ConsoleLogger extends AbstractLogger LogLevel::INFO => self::INFO, LogLevel::DEBUG => self::INFO, ]; - private $errored = false; + private bool $errored = false; public function __construct(OutputInterface $output, array $verbosityLevelMap = [], array $formatLevelMap = []) { diff --git a/Output/BufferedOutput.php b/Output/BufferedOutput.php index 7235b1f6b..784e309bd 100644 --- a/Output/BufferedOutput.php +++ b/Output/BufferedOutput.php @@ -16,7 +16,7 @@ */ class BufferedOutput extends Output { - private $buffer = ''; + private string $buffer = ''; /** * Empties buffer and returns its content. diff --git a/Output/ConsoleOutput.php b/Output/ConsoleOutput.php index 39c12d2c9..1ed7f20a2 100644 --- a/Output/ConsoleOutput.php +++ b/Output/ConsoleOutput.php @@ -29,8 +29,8 @@ */ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface { - private $stderr; - private $consoleSectionOutputs = []; + private OutputInterface $stderr; + private array $consoleSectionOutputs = []; /** * @param int $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) diff --git a/Output/ConsoleSectionOutput.php b/Output/ConsoleSectionOutput.php index 9d9f02df2..d4c2f20c7 100644 --- a/Output/ConsoleSectionOutput.php +++ b/Output/ConsoleSectionOutput.php @@ -21,10 +21,10 @@ */ class ConsoleSectionOutput extends StreamOutput { - private $content = []; - private $lines = 0; - private $sections; - private $terminal; + private array $content = []; + private int $lines = 0; + private array $sections; + private Terminal $terminal; /** * @param resource $stream diff --git a/Output/NullOutput.php b/Output/NullOutput.php index 982f3c396..768207f0e 100644 --- a/Output/NullOutput.php +++ b/Output/NullOutput.php @@ -24,7 +24,7 @@ */ class NullOutput implements OutputInterface { - private $formatter; + private NullOutputFormatter $formatter; /** * {@inheritdoc} @@ -39,11 +39,8 @@ public function setFormatter(OutputFormatterInterface $formatter) */ public function getFormatter(): OutputFormatterInterface { - if ($this->formatter) { - return $this->formatter; - } // to comply with the interface we must return a OutputFormatterInterface - return $this->formatter = new NullOutputFormatter(); + return $this->formatter ??= new NullOutputFormatter(); } /** diff --git a/Output/Output.php b/Output/Output.php index 48c4d3881..c337e113f 100644 --- a/Output/Output.php +++ b/Output/Output.php @@ -29,8 +29,8 @@ */ abstract class Output implements OutputInterface { - private $verbosity; - private $formatter; + private int $verbosity; + private OutputFormatterInterface $formatter; /** * @param int|null $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) diff --git a/Output/TrimmedBufferOutput.php b/Output/TrimmedBufferOutput.php index 2c547a3f0..0d375e0c8 100644 --- a/Output/TrimmedBufferOutput.php +++ b/Output/TrimmedBufferOutput.php @@ -21,8 +21,8 @@ */ class TrimmedBufferOutput extends Output { - private $maxLength; - private $buffer = ''; + private int $maxLength; + private string $buffer = ''; public function __construct(int $maxLength, ?int $verbosity = self::VERBOSITY_NORMAL, bool $decorated = false, OutputFormatterInterface $formatter = null) { diff --git a/Question/ChoiceQuestion.php b/Question/ChoiceQuestion.php index bbba24ef1..97121754c 100644 --- a/Question/ChoiceQuestion.php +++ b/Question/ChoiceQuestion.php @@ -20,10 +20,10 @@ */ class ChoiceQuestion extends Question { - private $choices; - private $multiselect = false; - private $prompt = ' > '; - private $errorMessage = 'Value "%s" is invalid'; + private array $choices; + private bool $multiselect = false; + private string $prompt = ' > '; + private string $errorMessage = 'Value "%s" is invalid'; /** * @param string $question The question to ask to the user diff --git a/Question/ConfirmationQuestion.php b/Question/ConfirmationQuestion.php index 4228521b9..40eab2429 100644 --- a/Question/ConfirmationQuestion.php +++ b/Question/ConfirmationQuestion.php @@ -18,7 +18,7 @@ */ class ConfirmationQuestion extends Question { - private $trueAnswerRegex; + private string $trueAnswerRegex; /** * @param string $question The question to ask to the user diff --git a/Question/Question.php b/Question/Question.php index 03dac1ae6..2d6a98878 100644 --- a/Question/Question.php +++ b/Question/Question.php @@ -21,16 +21,16 @@ */ class Question { - private $question; - private $attempts; - private $hidden = false; - private $hiddenFallback = true; - private $autocompleterCallback; - private $validator; - private $default; - private $normalizer; - private $trimmable = true; - private $multiline = false; + private string $question; + private ?int $attempts = null; + private bool $hidden = false; + private bool $hiddenFallback = true; + private ?\Closure $autocompleterCallback = null; + private ?\Closure $validator = null; + private string|int|bool|null|float $default; + private ?\Closure $normalizer = null; + private bool $trimmable = true; + private bool $multiline = false; /** * @param string $question The question to ask to the user @@ -184,7 +184,7 @@ public function setAutocompleterCallback(callable $callback = null): static throw new LogicException('A hidden question cannot use the autocompleter.'); } - $this->autocompleterCallback = $callback; + $this->autocompleterCallback = null === $callback || $callback instanceof \Closure ? $callback : \Closure::fromCallable($callback); return $this; } @@ -196,7 +196,7 @@ public function setAutocompleterCallback(callable $callback = null): static */ public function setValidator(callable $validator = null): static { - $this->validator = $validator; + $this->validator = null === $validator || $validator instanceof \Closure ? $validator : \Closure::fromCallable($validator); return $this; } @@ -248,7 +248,7 @@ public function getMaxAttempts(): ?int */ public function setNormalizer(callable $normalizer): static { - $this->normalizer = $normalizer; + $this->normalizer = $normalizer instanceof \Closure ? $normalizer : \Closure::fromCallable($normalizer); return $this; } diff --git a/SignalRegistry/SignalRegistry.php b/SignalRegistry/SignalRegistry.php index ed93dd062..15978febc 100644 --- a/SignalRegistry/SignalRegistry.php +++ b/SignalRegistry/SignalRegistry.php @@ -13,7 +13,7 @@ final class SignalRegistry { - private $signalHandlers = []; + private array $signalHandlers = []; public function __construct() { diff --git a/SingleCommandApplication.php b/SingleCommandApplication.php index c1831d1d2..4162f1937 100644 --- a/SingleCommandApplication.php +++ b/SingleCommandApplication.php @@ -20,9 +20,9 @@ */ class SingleCommandApplication extends Command { - private $version = 'UNKNOWN'; - private $autoExit = true; - private $running = false; + private string $version = 'UNKNOWN'; + private bool $autoExit = true; + private bool $running = false; public function setVersion(string $version): self { diff --git a/Style/OutputStyle.php b/Style/OutputStyle.php index 0b2ded36c..1338f04c6 100644 --- a/Style/OutputStyle.php +++ b/Style/OutputStyle.php @@ -23,7 +23,7 @@ */ abstract class OutputStyle implements OutputInterface, StyleInterface { - private $output; + private OutputInterface $output; public function __construct(OutputInterface $output) { diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php index bea443c08..99360753f 100644 --- a/Style/SymfonyStyle.php +++ b/Style/SymfonyStyle.php @@ -37,11 +37,11 @@ class SymfonyStyle extends OutputStyle { public const MAX_LINE_LENGTH = 120; - private $input; - private $questionHelper; - private $progressBar; - private $lineLength; - private $bufferedOutput; + private InputInterface $input; + private SymfonyQuestionHelper $questionHelper; + private ProgressBar $progressBar; + private int $lineLength; + private TrimmedBufferOutput $bufferedOutput; public function __construct(InputInterface $input, OutputInterface $output) { @@ -322,7 +322,7 @@ public function progressFinish() { $this->getProgressBar()->finish(); $this->newLine(2); - $this->progressBar = null; + unset($this->progressBar); } /** @@ -347,9 +347,7 @@ public function askQuestion(Question $question): mixed $this->autoPrependBlock(); } - if (!$this->questionHelper) { - $this->questionHelper = new SymfonyQuestionHelper(); - } + $this->questionHelper ??= new SymfonyQuestionHelper(); $answer = $this->questionHelper->ask($this->input, $this, $question); @@ -410,11 +408,8 @@ public function getErrorStyle(): self private function getProgressBar(): ProgressBar { - if (!$this->progressBar) { - throw new RuntimeException('The ProgressBar is not started.'); - } - - return $this->progressBar; + return $this->progressBar + ?? throw new RuntimeException('The ProgressBar is not started.'); } private function autoPrependBlock(): void diff --git a/Terminal.php b/Terminal.php index 953d6491e..80020c95d 100644 --- a/Terminal.php +++ b/Terminal.php @@ -13,9 +13,9 @@ class Terminal { - private static $width; - private static $height; - private static $stty; + private static ?int $width = null; + private static ?int $height = null; + private static ?bool $stty = null; /** * Gets the terminal width. diff --git a/Tester/ApplicationTester.php b/Tester/ApplicationTester.php index 0404020c6..ffa21cba4 100644 --- a/Tester/ApplicationTester.php +++ b/Tester/ApplicationTester.php @@ -28,7 +28,7 @@ class ApplicationTester { use TesterTrait; - private $application; + private Application $application; public function __construct(Application $application) { diff --git a/Tester/CommandTester.php b/Tester/CommandTester.php index f6ee4b730..2ff813b7d 100644 --- a/Tester/CommandTester.php +++ b/Tester/CommandTester.php @@ -24,7 +24,7 @@ class CommandTester { use TesterTrait; - private $command; + private Command $command; public function __construct(Command $command) { diff --git a/Tester/TesterTrait.php b/Tester/TesterTrait.php index 6ba625841..0d2a371e4 100644 --- a/Tester/TesterTrait.php +++ b/Tester/TesterTrait.php @@ -23,14 +23,11 @@ */ trait TesterTrait { - /** @var StreamOutput */ - private $output; - private $inputs = []; - private $captureStreamsIndependently = false; - /** @var InputInterface */ - private $input; - /** @var int */ - private $statusCode; + private StreamOutput $output; + private array $inputs = []; + private bool $captureStreamsIndependently = false; + private InputInterface $input; + private int $statusCode; /** * Gets the display returned by the last execution of the command or application. @@ -39,7 +36,7 @@ trait TesterTrait */ public function getDisplay(bool $normalize = false): string { - if (null === $this->output) { + if (!isset($this->output)) { throw new \RuntimeException('Output not initialized, did you execute the command before requesting the display?'); } @@ -99,11 +96,7 @@ public function getOutput(): OutputInterface */ public function getStatusCode(): int { - if (null === $this->statusCode) { - throw new \RuntimeException('Status code not initialized, did you execute the command before requesting the status code?'); - } - - return $this->statusCode; + return $this->statusCode ?? throw new \RuntimeException('Status code not initialized, did you execute the command before requesting the status code?'); } public function assertCommandIsSuccessful(string $message = ''): void From 38c5cec0b87fa8b0bf79f71dfacd9a71cf308fe3 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Thu, 9 Sep 2021 14:56:10 +0200 Subject: [PATCH 021/215] Fix return types --- Cursor.php | 26 +++++++++++++------------- Helper/Table.php | 12 ++++++------ Helper/TableStyle.php | 10 +++++----- SingleCommandApplication.php | 4 ++-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Cursor.php b/Cursor.php index bd6ce1548..03e8c618b 100644 --- a/Cursor.php +++ b/Cursor.php @@ -33,7 +33,7 @@ public function __construct(OutputInterface $output, $input = null) /** * @return $this */ - public function moveUp(int $lines = 1): self + public function moveUp(int $lines = 1): static { $this->output->write(sprintf("\x1b[%dA", $lines)); @@ -43,7 +43,7 @@ public function moveUp(int $lines = 1): self /** * @return $this */ - public function moveDown(int $lines = 1): self + public function moveDown(int $lines = 1): static { $this->output->write(sprintf("\x1b[%dB", $lines)); @@ -53,7 +53,7 @@ public function moveDown(int $lines = 1): self /** * @return $this */ - public function moveRight(int $columns = 1): self + public function moveRight(int $columns = 1): static { $this->output->write(sprintf("\x1b[%dC", $columns)); @@ -63,7 +63,7 @@ public function moveRight(int $columns = 1): self /** * @return $this */ - public function moveLeft(int $columns = 1): self + public function moveLeft(int $columns = 1): static { $this->output->write(sprintf("\x1b[%dD", $columns)); @@ -73,7 +73,7 @@ public function moveLeft(int $columns = 1): self /** * @return $this */ - public function moveToColumn(int $column): self + public function moveToColumn(int $column): static { $this->output->write(sprintf("\x1b[%dG", $column)); @@ -83,7 +83,7 @@ public function moveToColumn(int $column): self /** * @return $this */ - public function moveToPosition(int $column, int $row): self + public function moveToPosition(int $column, int $row): static { $this->output->write(sprintf("\x1b[%d;%dH", $row + 1, $column)); @@ -93,7 +93,7 @@ public function moveToPosition(int $column, int $row): self /** * @return $this */ - public function savePosition(): self + public function savePosition(): static { $this->output->write("\x1b7"); @@ -103,7 +103,7 @@ public function savePosition(): self /** * @return $this */ - public function restorePosition(): self + public function restorePosition(): static { $this->output->write("\x1b8"); @@ -113,7 +113,7 @@ public function restorePosition(): self /** * @return $this */ - public function hide(): self + public function hide(): static { $this->output->write("\x1b[?25l"); @@ -123,7 +123,7 @@ public function hide(): self /** * @return $this */ - public function show(): self + public function show(): static { $this->output->write("\x1b[?25h\x1b[?0c"); @@ -135,7 +135,7 @@ public function show(): self * * @return $this */ - public function clearLine(): self + public function clearLine(): static { $this->output->write("\x1b[2K"); @@ -157,7 +157,7 @@ public function clearLineAfter(): self * * @return $this */ - public function clearOutput(): self + public function clearOutput(): static { $this->output->write("\x1b[0J"); @@ -169,7 +169,7 @@ public function clearOutput(): self * * @return $this */ - public function clearScreen(): self + public function clearScreen(): static { $this->output->write("\x1b[2J"); diff --git a/Helper/Table.php b/Helper/Table.php index d854532ad..94abf74d1 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -174,7 +174,7 @@ public function setColumnMaxWidth(int $columnIndex, int $width): static /** * @return $this */ - public function setHeaders(array $headers) + public function setHeaders(array $headers): static { $headers = array_values($headers); if (!empty($headers) && !\is_array($headers[0])) { @@ -196,7 +196,7 @@ public function setRows(array $rows) /** * @return $this */ - public function addRows(array $rows) + public function addRows(array $rows): static { foreach ($rows as $row) { $this->addRow($row); @@ -226,7 +226,7 @@ public function addRow(TableSeparator|array $row): static * * @return $this */ - public function appendRow(TableSeparator|array $row): self + public function appendRow(TableSeparator|array $row): static { if (!$this->output instanceof ConsoleSectionOutput) { throw new RuntimeException(sprintf('Output should be an instance of "%s" when calling "%s".', ConsoleSectionOutput::class, __METHOD__)); @@ -255,7 +255,7 @@ public function setRow(int|string $column, array $row): static /** * @return $this */ - public function setHeaderTitle(?string $title): self + public function setHeaderTitle(?string $title): static { $this->headerTitle = $title; @@ -265,7 +265,7 @@ public function setHeaderTitle(?string $title): self /** * @return $this */ - public function setFooterTitle(?string $title): self + public function setFooterTitle(?string $title): static { $this->footerTitle = $title; @@ -275,7 +275,7 @@ public function setFooterTitle(?string $title): self /** * @return $this */ - public function setHorizontal(bool $horizontal = true): self + public function setHorizontal(bool $horizontal = true): static { $this->horizontal = $horizontal; diff --git a/Helper/TableStyle.php b/Helper/TableStyle.php index ec627420b..bbad98e73 100644 --- a/Helper/TableStyle.php +++ b/Helper/TableStyle.php @@ -88,7 +88,7 @@ public function getPaddingChar(): string * * @return $this */ - public function setHorizontalBorderChars(string $outside, string $inside = null): self + public function setHorizontalBorderChars(string $outside, string $inside = null): static { $this->horizontalOutsideBorderChar = $outside; $this->horizontalInsideBorderChar = $inside ?? $outside; @@ -113,7 +113,7 @@ public function setHorizontalBorderChars(string $outside, string $inside = null) * * @return $this */ - public function setVerticalBorderChars(string $outside, string $inside = null): self + public function setVerticalBorderChars(string $outside, string $inside = null): static { $this->verticalOutsideBorderChar = $outside; $this->verticalInsideBorderChar = $inside ?? $outside; @@ -167,7 +167,7 @@ public function getBorderChars(): array * * @return $this */ - public function setCrossingChars(string $cross, string $topLeft, string $topMid, string $topRight, string $midRight, string $bottomRight, string $bottomMid, string $bottomLeft, string $midLeft, string $topLeftBottom = null, string $topMidBottom = null, string $topRightBottom = null): self + public function setCrossingChars(string $cross, string $topLeft, string $topMid, string $topRight, string $midRight, string $bottomRight, string $bottomMid, string $bottomLeft, string $midLeft, string $topLeftBottom = null, string $topMidBottom = null, string $topRightBottom = null): static { $this->crossingChar = $cross; $this->crossingTopLeftChar = $topLeft; @@ -338,7 +338,7 @@ public function getHeaderTitleFormat(): string /** * @return $this */ - public function setHeaderTitleFormat(string $format): self + public function setHeaderTitleFormat(string $format): static { $this->headerTitleFormat = $format; @@ -353,7 +353,7 @@ public function getFooterTitleFormat(): string /** * @return $this */ - public function setFooterTitleFormat(string $format): self + public function setFooterTitleFormat(string $format): static { $this->footerTitleFormat = $format; diff --git a/SingleCommandApplication.php b/SingleCommandApplication.php index fe2417a11..4f0b5ba3c 100644 --- a/SingleCommandApplication.php +++ b/SingleCommandApplication.php @@ -27,7 +27,7 @@ class SingleCommandApplication extends Command /** * @return $this */ - public function setVersion(string $version): self + public function setVersion(string $version): static { $this->version = $version; @@ -39,7 +39,7 @@ public function setVersion(string $version): self * * @return $this */ - public function setAutoExit(bool $autoExit): self + public function setAutoExit(bool $autoExit): static { $this->autoExit = $autoExit; From cd34b32651067f89034ec089e9b7d8e9203f736c Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Tue, 14 Sep 2021 18:54:58 +0200 Subject: [PATCH 022/215] [Console] Relax return type on HelperInterface::getName() --- Helper/HelperInterface.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Helper/HelperInterface.php b/Helper/HelperInterface.php index 14795809e..1d2b7bfb8 100644 --- a/Helper/HelperInterface.php +++ b/Helper/HelperInterface.php @@ -30,6 +30,8 @@ public function getHelperSet(): ?HelperSet; /** * Returns the canonical name of this helper. + * + * @return string */ - public function getName(): string; + public function getName(); } From 3bdf9d6d20931d52b7901045f2621c971a66953d Mon Sep 17 00:00:00 2001 From: Kevin Bond Date: Wed, 13 Oct 2021 14:38:46 -0400 Subject: [PATCH 023/215] [Console] remove mixed return types from `InputInterface` --- Input/InputInterface.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Input/InputInterface.php b/Input/InputInterface.php index 2c4e5719c..024da1884 100644 --- a/Input/InputInterface.php +++ b/Input/InputInterface.php @@ -50,8 +50,10 @@ public function hasParameterOption(string|array $values, bool $onlyParams = fals * @param string|array $values The value(s) to look for in the raw parameters (can be an array) * @param string|bool|int|float|array|null $default The default value to return if no result is found * @param bool $onlyParams Only check real parameters, skip those following an end of options (--) signal + * + * @return mixed */ - public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false): mixed; + public function getParameterOption(string|array $values, string|bool|int|float|array|null $default = false, bool $onlyParams = false); /** * Binds the current Input instance with the given arguments and options. @@ -77,9 +79,11 @@ public function getArguments(): array; /** * Returns the argument value for a given argument name. * + * @return mixed + * * @throws InvalidArgumentException When argument given doesn't exist */ - public function getArgument(string $name): mixed; + public function getArgument(string $name); /** * Sets an argument value by name. @@ -103,9 +107,11 @@ public function getOptions(): array; /** * Returns the option value for a given option name. * + * @return mixed + * * @throws InvalidArgumentException When option given doesn't exist */ - public function getOption(string $name): mixed; + public function getOption(string $name); /** * Sets an option value by name. From 4c170712dc4a910e5823cef7ae823ef251384ccb Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 26 Oct 2021 18:07:50 +0200 Subject: [PATCH 024/215] Fix missing return types --- Completion/CompletionSuggestions.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Completion/CompletionSuggestions.php b/Completion/CompletionSuggestions.php index 13572472e..e69c66710 100644 --- a/Completion/CompletionSuggestions.php +++ b/Completion/CompletionSuggestions.php @@ -28,7 +28,7 @@ class CompletionSuggestions * * @return $this */ - public function suggestValue(string $value): self + public function suggestValue(string $value): static { $this->valueSuggestions[] = $value; @@ -42,7 +42,7 @@ public function suggestValue(string $value): self * * @return $this */ - public function suggestValues(array $values): self + public function suggestValues(array $values): static { $this->valueSuggestions = array_merge($this->valueSuggestions, $values); @@ -54,7 +54,7 @@ public function suggestValues(array $values): self * * @return $this */ - public function suggestOption(InputOption $option): self + public function suggestOption(InputOption $option): static { $this->optionSuggestions[] = $option; @@ -68,7 +68,7 @@ public function suggestOption(InputOption $option): self * * @return $this */ - public function suggestOptions(array $options): self + public function suggestOptions(array $options): static { foreach ($options as $option) { $this->suggestOption($option); From 9c3d967e0e53f756bed1a0d14568866c4991eb2e Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Wed, 27 Oct 2021 12:20:15 +0200 Subject: [PATCH 025/215] remove no longer needed PHP version requirements from tests --- Tests/Command/CommandTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Tests/Command/CommandTest.php b/Tests/Command/CommandTest.php index 41f01b823..1ce203860 100644 --- a/Tests/Command/CommandTest.php +++ b/Tests/Command/CommandTest.php @@ -420,9 +420,6 @@ public function testCommandAttribute() $this->assertSame(['f'], $command->getAliases()); } - /** - * @requires PHP 8 - */ public function testDefaultCommand() { $apl = new Application(); From b6bd92e3bc3a973259c66ffb59e9b8fa39fb7944 Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Mon, 6 Dec 2021 21:02:18 +0100 Subject: [PATCH 026/215] Use str_ends_with() and str_starts_with() --- Formatter/OutputFormatter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Formatter/OutputFormatter.php b/Formatter/OutputFormatter.php index bc47f6e10..fd11a84d8 100644 --- a/Formatter/OutputFormatter.php +++ b/Formatter/OutputFormatter.php @@ -254,7 +254,7 @@ private function applyCurrentStyle(string $text, string $current, int $width, in $text = $prefix.preg_replace('~([^\\n]{'.$width.'})\\ *~', "\$1\n", $text); $text = rtrim($text, "\n").($matches[1] ?? ''); - if (!$currentLineLength && '' !== $current && "\n" !== substr($current, -1)) { + if (!$currentLineLength && '' !== $current && !str_ends_with($current, "\n")) { $text = "\n".$text; } From 9d38167286cb425fc4d9ef4066af2b8097263ec9 Mon Sep 17 00:00:00 2001 From: Thomas Calvet Date: Wed, 8 Dec 2021 14:13:04 +0100 Subject: [PATCH 027/215] Leverage str_starts_with(), str_ends_with() and str_contains() --- Helper/QuestionHelper.php | 2 +- Helper/Table.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Helper/QuestionHelper.php b/Helper/QuestionHelper.php index 3266a92df..113cd33a9 100644 --- a/Helper/QuestionHelper.php +++ b/Helper/QuestionHelper.php @@ -398,7 +398,7 @@ private function getHiddenResponse(OutputInterface $output, $inputStream, bool $ $exe = __DIR__.'/../Resources/bin/hiddeninput.exe'; // handle code running from a phar - if ('phar:' === substr(__FILE__, 0, 5)) { + if (str_starts_with(__FILE__, 'phar:')) { $tmpExe = sys_get_temp_dir().'/hiddeninput.exe'; copy($exe, $tmpExe); $exe = $tmpExe; diff --git a/Helper/Table.php b/Helper/Table.php index 94abf74d1..0b8d8de8c 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -490,11 +490,11 @@ private function renderCell(array $row, int $column, string $cellFormat): string $cellFormat = '<'.$tag.'>%s'; } - if (strstr($content, '')) { + if (str_contains($content, '')) { $content = str_replace('', '', $content); $width -= 3; } - if (strstr($content, '')) { + if (str_contains($content, '')) { $content = str_replace('', '', $content); $width -= \strlen(''); } @@ -538,7 +538,7 @@ private function buildTableRows(array $rows): TableRows if (isset($this->columnMaxWidths[$column]) && Helper::width(Helper::removeDecoration($formatter, $cell)) > $this->columnMaxWidths[$column]) { $cell = $formatter->formatAndWrap($cell, $this->columnMaxWidths[$column] * $colspan); } - if (!strstr($cell ?? '', "\n")) { + if (!str_contains($cell ?? '', "\n")) { continue; } $escaped = implode("\n", array_map([OutputFormatter::class, 'escapeTrailingBackslash'], explode("\n", $cell))); @@ -603,7 +603,7 @@ private function fillNextRows(array $rows, int $line): array if ($cell instanceof TableCell && $cell->getRowspan() > 1) { $nbLines = $cell->getRowspan() - 1; $lines = [$cell]; - if (strstr($cell, "\n")) { + if (str_contains($cell, "\n")) { $lines = explode("\n", str_replace("\n", "\n", $cell)); $nbLines = \count($lines) > $nbLines ? substr_count($cell, "\n") : $nbLines; From d5818ed8c269e92c7767db7f4c8ed2ca97359a9a Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 7 Dec 2021 12:27:08 +0100 Subject: [PATCH 028/215] Remove FQCN type hints on properties --- Application.php | 14 +++++++------- CI/GithubActionReporter.php | 2 +- Command/Command.php | 8 ++++---- Command/HelpCommand.php | 2 +- Command/LazyCommand.php | 2 +- Command/LockableTrait.php | 3 +-- CommandLoader/ContainerCommandLoader.php | 2 +- Cursor.php | 2 +- Descriptor/ApplicationDescription.php | 2 +- Event/ConsoleEvent.php | 4 ++-- EventListener/ErrorListener.php | 2 +- Formatter/NullOutputFormatter.php | 2 +- Formatter/OutputFormatter.php | 2 +- Formatter/OutputFormatterStyle.php | 2 +- Formatter/OutputFormatterStyleStack.php | 2 +- Helper/Dumper.php | 6 +++--- Helper/ProgressBar.php | 6 +++--- Helper/ProgressIndicator.php | 2 +- Helper/Table.php | 4 ++-- Input/InputDefinition.php | 4 ++-- Logger/ConsoleLogger.php | 2 +- Output/ConsoleOutput.php | 2 +- Output/ConsoleSectionOutput.php | 2 +- Output/NullOutput.php | 2 +- Output/Output.php | 2 +- Style/OutputStyle.php | 2 +- Style/SymfonyStyle.php | 10 +++++----- Tester/ApplicationTester.php | 2 +- Tester/CommandTester.php | 2 +- Tester/TesterTrait.php | 4 ++-- 30 files changed, 51 insertions(+), 52 deletions(-) diff --git a/Application.php b/Application.php index b582435f7..09234f5eb 100644 --- a/Application.php +++ b/Application.php @@ -72,20 +72,20 @@ class Application implements ResetInterface { private array $commands = []; private bool $wantHelps = false; - private ?Command $runningCommand = null; + private $runningCommand = null; private string $name; private string $version; - private ?CommandLoaderInterface $commandLoader = null; + private $commandLoader = null; private bool $catchExceptions = true; private bool $autoExit = true; - private InputDefinition $definition; - private HelperSet $helperSet; - private ?EventDispatcherInterface $dispatcher = null; - private Terminal $terminal; + private $definition; + private $helperSet; + private $dispatcher = null; + private $terminal; private string $defaultCommand; private bool $singleCommand = false; private bool $initialized = false; - private SignalRegistry $signalRegistry; + private $signalRegistry; private array $signalsToDispatchEvent = []; public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN') diff --git a/CI/GithubActionReporter.php b/CI/GithubActionReporter.php index 7e5565469..a15c1ff18 100644 --- a/CI/GithubActionReporter.php +++ b/CI/GithubActionReporter.php @@ -20,7 +20,7 @@ */ class GithubActionReporter { - private OutputInterface $output; + private $output; /** * @see https://github.com/actions/toolkit/blob/5e5e1b7aacba68a53836a34db4a288c3c1c1585b/packages/core/src/command.ts#L80-L85 diff --git a/Command/Command.php b/Command/Command.php index d6354b4ab..e69bae098 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -47,20 +47,20 @@ class Command */ protected static $defaultDescription; - private ?Application $application = null; + private $application = null; private ?string $name = null; private ?string $processTitle = null; private array $aliases = []; - private InputDefinition $definition; + private $definition; private bool $hidden = false; private string $help = ''; private string $description = ''; - private ?InputDefinition $fullDefinition = null; + private $fullDefinition = null; private bool $ignoreValidationErrors = false; private ?\Closure $code = null; private array $synopsis = []; private array $usages = []; - private ?HelperSet $helperSet = null; + private $helperSet = null; public static function getDefaultName(): ?string { diff --git a/Command/HelpCommand.php b/Command/HelpCommand.php index ad4b813e4..66f8593eb 100644 --- a/Command/HelpCommand.php +++ b/Command/HelpCommand.php @@ -27,7 +27,7 @@ */ class HelpCommand extends Command { - private Command $command; + private $command; /** * {@inheritdoc} diff --git a/Command/LazyCommand.php b/Command/LazyCommand.php index b674a6387..aec412679 100644 --- a/Command/LazyCommand.php +++ b/Command/LazyCommand.php @@ -24,7 +24,7 @@ */ final class LazyCommand extends Command { - private \Closure|Command $command; + private $command; private ?bool $isEnabled; public function __construct(string $name, array $aliases, string $description, bool $isHidden, \Closure $commandFactory, ?bool $isEnabled = true) diff --git a/Command/LockableTrait.php b/Command/LockableTrait.php index 67923a9e8..796955142 100644 --- a/Command/LockableTrait.php +++ b/Command/LockableTrait.php @@ -13,7 +13,6 @@ use Symfony\Component\Console\Exception\LogicException; use Symfony\Component\Lock\LockFactory; -use Symfony\Component\Lock\LockInterface; use Symfony\Component\Lock\Store\FlockStore; use Symfony\Component\Lock\Store\SemaphoreStore; @@ -24,7 +23,7 @@ */ trait LockableTrait { - private ?LockInterface $lock = null; + private $lock = null; /** * Locks a command. diff --git a/CommandLoader/ContainerCommandLoader.php b/CommandLoader/ContainerCommandLoader.php index 651fb665e..9b26577f0 100644 --- a/CommandLoader/ContainerCommandLoader.php +++ b/CommandLoader/ContainerCommandLoader.php @@ -22,7 +22,7 @@ */ class ContainerCommandLoader implements CommandLoaderInterface { - private ContainerInterface $container; + private $container; private array $commandMap; /** diff --git a/Cursor.php b/Cursor.php index 03e8c618b..995e3d7dd 100644 --- a/Cursor.php +++ b/Cursor.php @@ -18,7 +18,7 @@ */ final class Cursor { - private OutputInterface $output; + private $output; private $input; /** diff --git a/Descriptor/ApplicationDescription.php b/Descriptor/ApplicationDescription.php index 5f32173ae..0802f1b38 100644 --- a/Descriptor/ApplicationDescription.php +++ b/Descriptor/ApplicationDescription.php @@ -24,7 +24,7 @@ class ApplicationDescription { public const GLOBAL_NAMESPACE = '_global'; - private Application $application; + private $application; private ?string $namespace; private bool $showHidden; private array $namespaces; diff --git a/Event/ConsoleEvent.php b/Event/ConsoleEvent.php index 6ba1615fe..56b8a9a60 100644 --- a/Event/ConsoleEvent.php +++ b/Event/ConsoleEvent.php @@ -25,8 +25,8 @@ class ConsoleEvent extends Event { protected $command; - private InputInterface $input; - private OutputInterface $output; + private $input; + private $output; public function __construct(?Command $command, InputInterface $input, OutputInterface $output) { diff --git a/EventListener/ErrorListener.php b/EventListener/ErrorListener.php index bcd918331..61bd9d344 100644 --- a/EventListener/ErrorListener.php +++ b/EventListener/ErrorListener.php @@ -24,7 +24,7 @@ */ class ErrorListener implements EventSubscriberInterface { - private ?LoggerInterface $logger; + private $logger; public function __construct(LoggerInterface $logger = null) { diff --git a/Formatter/NullOutputFormatter.php b/Formatter/NullOutputFormatter.php index d14db326a..d770e1465 100644 --- a/Formatter/NullOutputFormatter.php +++ b/Formatter/NullOutputFormatter.php @@ -16,7 +16,7 @@ */ final class NullOutputFormatter implements OutputFormatterInterface { - private NullOutputFormatterStyle $style; + private $style; /** * {@inheritdoc} diff --git a/Formatter/OutputFormatter.php b/Formatter/OutputFormatter.php index bc47f6e10..c914a1246 100644 --- a/Formatter/OutputFormatter.php +++ b/Formatter/OutputFormatter.php @@ -23,7 +23,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface { private bool $decorated; private array $styles = []; - private OutputFormatterStyleStack $styleStack; + private $styleStack; public function __clone() { diff --git a/Formatter/OutputFormatterStyle.php b/Formatter/OutputFormatterStyle.php index 9e8ea967e..0a009e962 100644 --- a/Formatter/OutputFormatterStyle.php +++ b/Formatter/OutputFormatterStyle.php @@ -20,7 +20,7 @@ */ class OutputFormatterStyle implements OutputFormatterStyleInterface { - private Color $color; + private $color; private string $foreground; private string $background; private array $options; diff --git a/Formatter/OutputFormatterStyleStack.php b/Formatter/OutputFormatterStyleStack.php index e72b641ba..b425449ef 100644 --- a/Formatter/OutputFormatterStyleStack.php +++ b/Formatter/OutputFormatterStyleStack.php @@ -24,7 +24,7 @@ class OutputFormatterStyleStack implements ResetInterface */ private array $styles = []; - private OutputFormatterStyleInterface $emptyStyle; + private $emptyStyle; public function __construct(OutputFormatterStyleInterface $emptyStyle = null) { diff --git a/Helper/Dumper.php b/Helper/Dumper.php index 76b76c0a4..50190951b 100644 --- a/Helper/Dumper.php +++ b/Helper/Dumper.php @@ -21,9 +21,9 @@ */ final class Dumper { - private OutputInterface $output; - private ?CliDumper $dumper; - private ?ClonerInterface $cloner; + private $output; + private $dumper; + private $cloner; private \Closure $handler; public function __construct(OutputInterface $output, CliDumper $dumper = null, ClonerInterface $cloner = null) diff --git a/Helper/ProgressBar.php b/Helper/ProgressBar.php index b087b4b92..72c26f2f3 100644 --- a/Helper/ProgressBar.php +++ b/Helper/ProgressBar.php @@ -47,7 +47,7 @@ final class ProgressBar private float $lastWriteTime = 0; private float $minSecondsBetweenRedraws = 0; private float $maxSecondsBetweenRedraws = 1; - private OutputInterface $output; + private $output; private int $step = 0; private ?int $max = null; private int $startTime; @@ -56,9 +56,9 @@ final class ProgressBar private int $formatLineCount; private array $messages = []; private bool $overwrite = true; - private Terminal $terminal; + private $terminal; private ?string $previousMessage = null; - private Cursor $cursor; + private $cursor; private static array $formatters; private static array $formats; diff --git a/Helper/ProgressIndicator.php b/Helper/ProgressIndicator.php index 9ca24e942..c746f9b92 100644 --- a/Helper/ProgressIndicator.php +++ b/Helper/ProgressIndicator.php @@ -31,7 +31,7 @@ class ProgressIndicator 'very_verbose_no_ansi' => ' %message% (%elapsed:6s%, %memory:6s%)', ]; - private OutputInterface $output; + private $output; private int $startTime; private ?string $format = null; private ?string $message = null; diff --git a/Helper/Table.php b/Helper/Table.php index 94abf74d1..2e87ed9c7 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -43,8 +43,8 @@ class Table private bool $horizontal = false; private array $effectiveColumnWidths = []; private int $numberOfColumns; - private OutputInterface $output; - private TableStyle $style; + private $output; + private $style; private array $columnStyles = []; private array $columnWidths = []; private array $columnMaxWidths = []; diff --git a/Input/InputDefinition.php b/Input/InputDefinition.php index f4b14a1c8..cb270d81f 100644 --- a/Input/InputDefinition.php +++ b/Input/InputDefinition.php @@ -30,8 +30,8 @@ class InputDefinition { private array $arguments = []; private int $requiredCount = 0; - private ?InputArgument $lastArrayArgument = null; - private ?InputArgument $lastOptionalArgument = null; + private $lastArrayArgument = null; + private $lastOptionalArgument = null; private array $options = []; private array $negations = []; private array $shortcuts = []; diff --git a/Logger/ConsoleLogger.php b/Logger/ConsoleLogger.php index 8d028ac8e..61a782150 100644 --- a/Logger/ConsoleLogger.php +++ b/Logger/ConsoleLogger.php @@ -29,7 +29,7 @@ class ConsoleLogger extends AbstractLogger public const INFO = 'info'; public const ERROR = 'error'; - private OutputInterface $output; + private $output; private array $verbosityLevelMap = [ LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, diff --git a/Output/ConsoleOutput.php b/Output/ConsoleOutput.php index 1ed7f20a2..3326cdf23 100644 --- a/Output/ConsoleOutput.php +++ b/Output/ConsoleOutput.php @@ -29,7 +29,7 @@ */ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface { - private OutputInterface $stderr; + private $stderr; private array $consoleSectionOutputs = []; /** diff --git a/Output/ConsoleSectionOutput.php b/Output/ConsoleSectionOutput.php index d4c2f20c7..92dca7968 100644 --- a/Output/ConsoleSectionOutput.php +++ b/Output/ConsoleSectionOutput.php @@ -24,7 +24,7 @@ class ConsoleSectionOutput extends StreamOutput private array $content = []; private int $lines = 0; private array $sections; - private Terminal $terminal; + private $terminal; /** * @param resource $stream diff --git a/Output/NullOutput.php b/Output/NullOutput.php index 768207f0e..87214ec49 100644 --- a/Output/NullOutput.php +++ b/Output/NullOutput.php @@ -24,7 +24,7 @@ */ class NullOutput implements OutputInterface { - private NullOutputFormatter $formatter; + private $formatter; /** * {@inheritdoc} diff --git a/Output/Output.php b/Output/Output.php index c337e113f..58c1837b7 100644 --- a/Output/Output.php +++ b/Output/Output.php @@ -30,7 +30,7 @@ abstract class Output implements OutputInterface { private int $verbosity; - private OutputFormatterInterface $formatter; + private $formatter; /** * @param int|null $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) diff --git a/Style/OutputStyle.php b/Style/OutputStyle.php index 1338f04c6..0b2ded36c 100644 --- a/Style/OutputStyle.php +++ b/Style/OutputStyle.php @@ -23,7 +23,7 @@ */ abstract class OutputStyle implements OutputInterface, StyleInterface { - private OutputInterface $output; + private $output; public function __construct(OutputInterface $output) { diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php index 58640ab5f..78af16670 100644 --- a/Style/SymfonyStyle.php +++ b/Style/SymfonyStyle.php @@ -38,12 +38,12 @@ class SymfonyStyle extends OutputStyle { public const MAX_LINE_LENGTH = 120; - private InputInterface $input; - private OutputInterface $output; - private SymfonyQuestionHelper $questionHelper; - private ProgressBar $progressBar; + private $input; + private $output; + private $questionHelper; + private $progressBar; private int $lineLength; - private TrimmedBufferOutput $bufferedOutput; + private $bufferedOutput; public function __construct(InputInterface $input, OutputInterface $output) { diff --git a/Tester/ApplicationTester.php b/Tester/ApplicationTester.php index ffa21cba4..0404020c6 100644 --- a/Tester/ApplicationTester.php +++ b/Tester/ApplicationTester.php @@ -28,7 +28,7 @@ class ApplicationTester { use TesterTrait; - private Application $application; + private $application; public function __construct(Application $application) { diff --git a/Tester/CommandTester.php b/Tester/CommandTester.php index 2ff813b7d..f6ee4b730 100644 --- a/Tester/CommandTester.php +++ b/Tester/CommandTester.php @@ -24,7 +24,7 @@ class CommandTester { use TesterTrait; - private Command $command; + private $command; public function __construct(Command $command) { diff --git a/Tester/TesterTrait.php b/Tester/TesterTrait.php index 0d2a371e4..b238f958b 100644 --- a/Tester/TesterTrait.php +++ b/Tester/TesterTrait.php @@ -23,10 +23,10 @@ */ trait TesterTrait { - private StreamOutput $output; + private $output; private array $inputs = []; private bool $captureStreamsIndependently = false; - private InputInterface $input; + private $input; private int $statusCode; /** From 5b67cce06f0e53890bb3bfeabe5e796642820959 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 9 Dec 2021 13:46:12 +0100 Subject: [PATCH 029/215] Revert "bug #44494 Remove FQCN type hints on properties (fabpot)" This reverts commit 0a13eba7037c6636be7a35c194d7d2e86d6ea6ba, reversing changes made to e4cfa82c31ffda491b73e181c8d3d4e0a307eee8. --- Application.php | 14 +++++++------- CI/GithubActionReporter.php | 2 +- Command/Command.php | 8 ++++---- Command/HelpCommand.php | 2 +- Command/LazyCommand.php | 2 +- Command/LockableTrait.php | 3 ++- CommandLoader/ContainerCommandLoader.php | 2 +- Cursor.php | 2 +- Descriptor/ApplicationDescription.php | 2 +- Event/ConsoleEvent.php | 4 ++-- EventListener/ErrorListener.php | 2 +- Formatter/NullOutputFormatter.php | 2 +- Formatter/OutputFormatter.php | 2 +- Formatter/OutputFormatterStyle.php | 2 +- Formatter/OutputFormatterStyleStack.php | 2 +- Helper/Dumper.php | 6 +++--- Helper/ProgressBar.php | 6 +++--- Helper/ProgressIndicator.php | 2 +- Helper/Table.php | 4 ++-- Input/InputDefinition.php | 4 ++-- Logger/ConsoleLogger.php | 2 +- Output/ConsoleOutput.php | 2 +- Output/ConsoleSectionOutput.php | 2 +- Output/NullOutput.php | 2 +- Output/Output.php | 2 +- Style/OutputStyle.php | 2 +- Style/SymfonyStyle.php | 10 +++++----- Tester/ApplicationTester.php | 2 +- Tester/CommandTester.php | 2 +- Tester/TesterTrait.php | 4 ++-- 30 files changed, 52 insertions(+), 51 deletions(-) diff --git a/Application.php b/Application.php index 09234f5eb..b582435f7 100644 --- a/Application.php +++ b/Application.php @@ -72,20 +72,20 @@ class Application implements ResetInterface { private array $commands = []; private bool $wantHelps = false; - private $runningCommand = null; + private ?Command $runningCommand = null; private string $name; private string $version; - private $commandLoader = null; + private ?CommandLoaderInterface $commandLoader = null; private bool $catchExceptions = true; private bool $autoExit = true; - private $definition; - private $helperSet; - private $dispatcher = null; - private $terminal; + private InputDefinition $definition; + private HelperSet $helperSet; + private ?EventDispatcherInterface $dispatcher = null; + private Terminal $terminal; private string $defaultCommand; private bool $singleCommand = false; private bool $initialized = false; - private $signalRegistry; + private SignalRegistry $signalRegistry; private array $signalsToDispatchEvent = []; public function __construct(string $name = 'UNKNOWN', string $version = 'UNKNOWN') diff --git a/CI/GithubActionReporter.php b/CI/GithubActionReporter.php index a15c1ff18..7e5565469 100644 --- a/CI/GithubActionReporter.php +++ b/CI/GithubActionReporter.php @@ -20,7 +20,7 @@ */ class GithubActionReporter { - private $output; + private OutputInterface $output; /** * @see https://github.com/actions/toolkit/blob/5e5e1b7aacba68a53836a34db4a288c3c1c1585b/packages/core/src/command.ts#L80-L85 diff --git a/Command/Command.php b/Command/Command.php index e69bae098..d6354b4ab 100644 --- a/Command/Command.php +++ b/Command/Command.php @@ -47,20 +47,20 @@ class Command */ protected static $defaultDescription; - private $application = null; + private ?Application $application = null; private ?string $name = null; private ?string $processTitle = null; private array $aliases = []; - private $definition; + private InputDefinition $definition; private bool $hidden = false; private string $help = ''; private string $description = ''; - private $fullDefinition = null; + private ?InputDefinition $fullDefinition = null; private bool $ignoreValidationErrors = false; private ?\Closure $code = null; private array $synopsis = []; private array $usages = []; - private $helperSet = null; + private ?HelperSet $helperSet = null; public static function getDefaultName(): ?string { diff --git a/Command/HelpCommand.php b/Command/HelpCommand.php index 66f8593eb..ad4b813e4 100644 --- a/Command/HelpCommand.php +++ b/Command/HelpCommand.php @@ -27,7 +27,7 @@ */ class HelpCommand extends Command { - private $command; + private Command $command; /** * {@inheritdoc} diff --git a/Command/LazyCommand.php b/Command/LazyCommand.php index aec412679..b674a6387 100644 --- a/Command/LazyCommand.php +++ b/Command/LazyCommand.php @@ -24,7 +24,7 @@ */ final class LazyCommand extends Command { - private $command; + private \Closure|Command $command; private ?bool $isEnabled; public function __construct(string $name, array $aliases, string $description, bool $isHidden, \Closure $commandFactory, ?bool $isEnabled = true) diff --git a/Command/LockableTrait.php b/Command/LockableTrait.php index 796955142..67923a9e8 100644 --- a/Command/LockableTrait.php +++ b/Command/LockableTrait.php @@ -13,6 +13,7 @@ use Symfony\Component\Console\Exception\LogicException; use Symfony\Component\Lock\LockFactory; +use Symfony\Component\Lock\LockInterface; use Symfony\Component\Lock\Store\FlockStore; use Symfony\Component\Lock\Store\SemaphoreStore; @@ -23,7 +24,7 @@ */ trait LockableTrait { - private $lock = null; + private ?LockInterface $lock = null; /** * Locks a command. diff --git a/CommandLoader/ContainerCommandLoader.php b/CommandLoader/ContainerCommandLoader.php index 9b26577f0..651fb665e 100644 --- a/CommandLoader/ContainerCommandLoader.php +++ b/CommandLoader/ContainerCommandLoader.php @@ -22,7 +22,7 @@ */ class ContainerCommandLoader implements CommandLoaderInterface { - private $container; + private ContainerInterface $container; private array $commandMap; /** diff --git a/Cursor.php b/Cursor.php index 995e3d7dd..03e8c618b 100644 --- a/Cursor.php +++ b/Cursor.php @@ -18,7 +18,7 @@ */ final class Cursor { - private $output; + private OutputInterface $output; private $input; /** diff --git a/Descriptor/ApplicationDescription.php b/Descriptor/ApplicationDescription.php index 0802f1b38..5f32173ae 100644 --- a/Descriptor/ApplicationDescription.php +++ b/Descriptor/ApplicationDescription.php @@ -24,7 +24,7 @@ class ApplicationDescription { public const GLOBAL_NAMESPACE = '_global'; - private $application; + private Application $application; private ?string $namespace; private bool $showHidden; private array $namespaces; diff --git a/Event/ConsoleEvent.php b/Event/ConsoleEvent.php index 56b8a9a60..6ba1615fe 100644 --- a/Event/ConsoleEvent.php +++ b/Event/ConsoleEvent.php @@ -25,8 +25,8 @@ class ConsoleEvent extends Event { protected $command; - private $input; - private $output; + private InputInterface $input; + private OutputInterface $output; public function __construct(?Command $command, InputInterface $input, OutputInterface $output) { diff --git a/EventListener/ErrorListener.php b/EventListener/ErrorListener.php index 61bd9d344..bcd918331 100644 --- a/EventListener/ErrorListener.php +++ b/EventListener/ErrorListener.php @@ -24,7 +24,7 @@ */ class ErrorListener implements EventSubscriberInterface { - private $logger; + private ?LoggerInterface $logger; public function __construct(LoggerInterface $logger = null) { diff --git a/Formatter/NullOutputFormatter.php b/Formatter/NullOutputFormatter.php index d770e1465..d14db326a 100644 --- a/Formatter/NullOutputFormatter.php +++ b/Formatter/NullOutputFormatter.php @@ -16,7 +16,7 @@ */ final class NullOutputFormatter implements OutputFormatterInterface { - private $style; + private NullOutputFormatterStyle $style; /** * {@inheritdoc} diff --git a/Formatter/OutputFormatter.php b/Formatter/OutputFormatter.php index 654eb4da8..fd11a84d8 100644 --- a/Formatter/OutputFormatter.php +++ b/Formatter/OutputFormatter.php @@ -23,7 +23,7 @@ class OutputFormatter implements WrappableOutputFormatterInterface { private bool $decorated; private array $styles = []; - private $styleStack; + private OutputFormatterStyleStack $styleStack; public function __clone() { diff --git a/Formatter/OutputFormatterStyle.php b/Formatter/OutputFormatterStyle.php index 0a009e962..9e8ea967e 100644 --- a/Formatter/OutputFormatterStyle.php +++ b/Formatter/OutputFormatterStyle.php @@ -20,7 +20,7 @@ */ class OutputFormatterStyle implements OutputFormatterStyleInterface { - private $color; + private Color $color; private string $foreground; private string $background; private array $options; diff --git a/Formatter/OutputFormatterStyleStack.php b/Formatter/OutputFormatterStyleStack.php index b425449ef..e72b641ba 100644 --- a/Formatter/OutputFormatterStyleStack.php +++ b/Formatter/OutputFormatterStyleStack.php @@ -24,7 +24,7 @@ class OutputFormatterStyleStack implements ResetInterface */ private array $styles = []; - private $emptyStyle; + private OutputFormatterStyleInterface $emptyStyle; public function __construct(OutputFormatterStyleInterface $emptyStyle = null) { diff --git a/Helper/Dumper.php b/Helper/Dumper.php index 50190951b..76b76c0a4 100644 --- a/Helper/Dumper.php +++ b/Helper/Dumper.php @@ -21,9 +21,9 @@ */ final class Dumper { - private $output; - private $dumper; - private $cloner; + private OutputInterface $output; + private ?CliDumper $dumper; + private ?ClonerInterface $cloner; private \Closure $handler; public function __construct(OutputInterface $output, CliDumper $dumper = null, ClonerInterface $cloner = null) diff --git a/Helper/ProgressBar.php b/Helper/ProgressBar.php index 72c26f2f3..b087b4b92 100644 --- a/Helper/ProgressBar.php +++ b/Helper/ProgressBar.php @@ -47,7 +47,7 @@ final class ProgressBar private float $lastWriteTime = 0; private float $minSecondsBetweenRedraws = 0; private float $maxSecondsBetweenRedraws = 1; - private $output; + private OutputInterface $output; private int $step = 0; private ?int $max = null; private int $startTime; @@ -56,9 +56,9 @@ final class ProgressBar private int $formatLineCount; private array $messages = []; private bool $overwrite = true; - private $terminal; + private Terminal $terminal; private ?string $previousMessage = null; - private $cursor; + private Cursor $cursor; private static array $formatters; private static array $formats; diff --git a/Helper/ProgressIndicator.php b/Helper/ProgressIndicator.php index c746f9b92..9ca24e942 100644 --- a/Helper/ProgressIndicator.php +++ b/Helper/ProgressIndicator.php @@ -31,7 +31,7 @@ class ProgressIndicator 'very_verbose_no_ansi' => ' %message% (%elapsed:6s%, %memory:6s%)', ]; - private $output; + private OutputInterface $output; private int $startTime; private ?string $format = null; private ?string $message = null; diff --git a/Helper/Table.php b/Helper/Table.php index 2e87ed9c7..94abf74d1 100644 --- a/Helper/Table.php +++ b/Helper/Table.php @@ -43,8 +43,8 @@ class Table private bool $horizontal = false; private array $effectiveColumnWidths = []; private int $numberOfColumns; - private $output; - private $style; + private OutputInterface $output; + private TableStyle $style; private array $columnStyles = []; private array $columnWidths = []; private array $columnMaxWidths = []; diff --git a/Input/InputDefinition.php b/Input/InputDefinition.php index cb270d81f..f4b14a1c8 100644 --- a/Input/InputDefinition.php +++ b/Input/InputDefinition.php @@ -30,8 +30,8 @@ class InputDefinition { private array $arguments = []; private int $requiredCount = 0; - private $lastArrayArgument = null; - private $lastOptionalArgument = null; + private ?InputArgument $lastArrayArgument = null; + private ?InputArgument $lastOptionalArgument = null; private array $options = []; private array $negations = []; private array $shortcuts = []; diff --git a/Logger/ConsoleLogger.php b/Logger/ConsoleLogger.php index 61a782150..8d028ac8e 100644 --- a/Logger/ConsoleLogger.php +++ b/Logger/ConsoleLogger.php @@ -29,7 +29,7 @@ class ConsoleLogger extends AbstractLogger public const INFO = 'info'; public const ERROR = 'error'; - private $output; + private OutputInterface $output; private array $verbosityLevelMap = [ LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL, LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL, diff --git a/Output/ConsoleOutput.php b/Output/ConsoleOutput.php index 3326cdf23..1ed7f20a2 100644 --- a/Output/ConsoleOutput.php +++ b/Output/ConsoleOutput.php @@ -29,7 +29,7 @@ */ class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface { - private $stderr; + private OutputInterface $stderr; private array $consoleSectionOutputs = []; /** diff --git a/Output/ConsoleSectionOutput.php b/Output/ConsoleSectionOutput.php index 92dca7968..d4c2f20c7 100644 --- a/Output/ConsoleSectionOutput.php +++ b/Output/ConsoleSectionOutput.php @@ -24,7 +24,7 @@ class ConsoleSectionOutput extends StreamOutput private array $content = []; private int $lines = 0; private array $sections; - private $terminal; + private Terminal $terminal; /** * @param resource $stream diff --git a/Output/NullOutput.php b/Output/NullOutput.php index 87214ec49..768207f0e 100644 --- a/Output/NullOutput.php +++ b/Output/NullOutput.php @@ -24,7 +24,7 @@ */ class NullOutput implements OutputInterface { - private $formatter; + private NullOutputFormatter $formatter; /** * {@inheritdoc} diff --git a/Output/Output.php b/Output/Output.php index 58c1837b7..c337e113f 100644 --- a/Output/Output.php +++ b/Output/Output.php @@ -30,7 +30,7 @@ abstract class Output implements OutputInterface { private int $verbosity; - private $formatter; + private OutputFormatterInterface $formatter; /** * @param int|null $verbosity The verbosity level (one of the VERBOSITY constants in OutputInterface) diff --git a/Style/OutputStyle.php b/Style/OutputStyle.php index 0b2ded36c..1338f04c6 100644 --- a/Style/OutputStyle.php +++ b/Style/OutputStyle.php @@ -23,7 +23,7 @@ */ abstract class OutputStyle implements OutputInterface, StyleInterface { - private $output; + private OutputInterface $output; public function __construct(OutputInterface $output) { diff --git a/Style/SymfonyStyle.php b/Style/SymfonyStyle.php index 78af16670..58640ab5f 100644 --- a/Style/SymfonyStyle.php +++ b/Style/SymfonyStyle.php @@ -38,12 +38,12 @@ class SymfonyStyle extends OutputStyle { public const MAX_LINE_LENGTH = 120; - private $input; - private $output; - private $questionHelper; - private $progressBar; + private InputInterface $input; + private OutputInterface $output; + private SymfonyQuestionHelper $questionHelper; + private ProgressBar $progressBar; private int $lineLength; - private $bufferedOutput; + private TrimmedBufferOutput $bufferedOutput; public function __construct(InputInterface $input, OutputInterface $output) { diff --git a/Tester/ApplicationTester.php b/Tester/ApplicationTester.php index 0404020c6..ffa21cba4 100644 --- a/Tester/ApplicationTester.php +++ b/Tester/ApplicationTester.php @@ -28,7 +28,7 @@ class ApplicationTester { use TesterTrait; - private $application; + private Application $application; public function __construct(Application $application) { diff --git a/Tester/CommandTester.php b/Tester/CommandTester.php index f6ee4b730..2ff813b7d 100644 --- a/Tester/CommandTester.php +++ b/Tester/CommandTester.php @@ -24,7 +24,7 @@ class CommandTester { use TesterTrait; - private $command; + private Command $command; public function __construct(Command $command) { diff --git a/Tester/TesterTrait.php b/Tester/TesterTrait.php index b238f958b..0d2a371e4 100644 --- a/Tester/TesterTrait.php +++ b/Tester/TesterTrait.php @@ -23,10 +23,10 @@ */ trait TesterTrait { - private $output; + private StreamOutput $output; private array $inputs = []; private bool $captureStreamsIndependently = false; - private $input; + private InputInterface $input; private int $statusCode; /** From 9a51ef3bf1676c063261ff1b653a5580373f184c Mon Sep 17 00:00:00 2001 From: Guillaume Aveline Date: Thu, 21 Oct 2021 22:52:41 +0200 Subject: [PATCH 030/215] [Console] Issue 43602 : Add fish completion --- Command/CompleteCommand.php | 6 ++++- Completion/Output/FishCompletionOutput.php | 30 +++++++++++++++++++++ Resources/completion.fish | 29 ++++++++++++++++++++ Tests/Command/CompleteCommandTest.php | 2 +- Tests/Command/DumpCompletionCommandTest.php | 2 +- Tests/Fixtures/application_1.json | 2 +- Tests/Fixtures/application_1.xml | 2 +- Tests/Fixtures/application_2.json | 2 +- Tests/Fixtures/application_2.xml | 2 +- 9 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 Completion/Output/FishCompletionOutput.php create mode 100644 Resources/completion.fish diff --git a/Command/CompleteCommand.php b/Command/CompleteCommand.php index 97357d673..4fb3398eb 100644 --- a/Command/CompleteCommand.php +++ b/Command/CompleteCommand.php @@ -15,6 +15,7 @@ use Symfony\Component\Console\Completion\CompletionSuggestions; use Symfony\Component\Console\Completion\Output\BashCompletionOutput; use Symfony\Component\Console\Completion\Output\CompletionOutputInterface; +use Symfony\Component\Console\Completion\Output\FishCompletionOutput; use Symfony\Component\Console\Exception\CommandNotFoundException; use Symfony\Component\Console\Exception\ExceptionInterface; use Symfony\Component\Console\Input\InputInterface; @@ -41,7 +42,10 @@ final class CompleteCommand extends Command public function __construct(array $completionOutputs = []) { // must be set before the parent constructor, as the property value is used in configure() - $this->completionOutputs = $completionOutputs + ['bash' => BashCompletionOutput::class]; + $this->completionOutputs = $completionOutputs + [ + 'bash' => BashCompletionOutput::class, + 'fish' => FishCompletionOutput::class, + ]; parent::__construct(); } diff --git a/Completion/Output/FishCompletionOutput.php b/Completion/Output/FishCompletionOutput.php new file mode 100644 index 000000000..9b02f09aa --- /dev/null +++ b/Completion/Output/FishCompletionOutput.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Console\Completion\Output; + +use Symfony\Component\Console\Completion\CompletionSuggestions; +use Symfony\Component\Console\Output\OutputInterface; + +/** + * @author Guillaume Aveline + */ +class FishCompletionOutput implements CompletionOutputInterface +{ + public function write(CompletionSuggestions $suggestions, OutputInterface $output): void + { + $values = $suggestions->getValueSuggestions(); + foreach ($suggestions->getOptionSuggestions() as $option) { + $values[] = '--'.$option->getName(); + } + $output->write(implode("\n", $values)); + } +} diff --git a/Resources/completion.fish b/Resources/completion.fish new file mode 100644 index 000000000..6566c58a3 --- /dev/null +++ b/Resources/completion.fish @@ -0,0 +1,29 @@ +# This file is part of the Symfony package. +# +# (c) Fabien Potencier +# +# For the full copyright and license information, please view +# https://symfony.com/doc/current/contributing/code/license.html + +function _sf_{{ COMMAND_NAME }} + set sf_cmd (commandline -o) + set c (math (count (commandline -oc))) - 1) + + set completecmd "$sf_cmd[1]" "_complete" "-sfish" "-S{{ VERSION }}" + + for i in $sf_cmd + if [ $i != "" ] + set completecmd $completecmd "-i$i" + end + end + + set completecmd $completecmd "-c$c" + + set sfcomplete ($completecmd) + + for i in $sfcomplete + echo $i + end +end + +complete -c '{{ COMMAND_NAME }}' -a '(_sf_{{ COMMAND_NAME }})' -f diff --git a/Tests/Command/CompleteCommandTest.php b/Tests/Command/CompleteCommandTest.php index 189928897..74caa246c 100644 --- a/Tests/Command/CompleteCommandTest.php +++ b/Tests/Command/CompleteCommandTest.php @@ -47,7 +47,7 @@ public function testRequiredShellOption() public function testUnsupportedShellOption() { - $this->expectExceptionMessage('Shell completion is not supported for your shell: "unsupported" (supported: "bash").'); + $this->expectExceptionMessage('Shell completion is not supported for your shell: "unsupported" (supported: "bash", "fish").'); $this->execute(['--shell' => 'unsupported']); } diff --git a/Tests/Command/DumpCompletionCommandTest.php b/Tests/Command/DumpCompletionCommandTest.php index de8a3d4a6..b50e42b16 100644 --- a/Tests/Command/DumpCompletionCommandTest.php +++ b/Tests/Command/DumpCompletionCommandTest.php @@ -23,7 +23,7 @@ public function provideCompletionSuggestions() { yield 'shell' => [ [''], - ['bash'], + ['bash', 'fish'], ]; } } diff --git a/Tests/Fixtures/application_1.json b/Tests/Fixtures/application_1.json index 280a4247e..2cd6ee961 100644 --- a/Tests/Fixtures/application_1.json +++ b/Tests/Fixtures/application_1.json @@ -89,7 +89,7 @@ "accept_value": true, "is_value_required": true, "is_multiple": false, - "description": "The shell type (\"bash\")", + "description": "The shell type (\"bash\", \"fish\")", "default": null }, "current": { diff --git a/Tests/Fixtures/application_1.xml b/Tests/Fixtures/application_1.xml index 5a1722934..0f78ec5d3 100644 --- a/Tests/Fixtures/application_1.xml +++ b/Tests/Fixtures/application_1.xml @@ -10,7 +10,7 @@