From 7e81c9144a26fb4d0e2c2ab4fdd511163581c000 Mon Sep 17 00:00:00 2001 From: Alexandre Daubois Date: Tue, 13 Jun 2023 13:07:33 +0200 Subject: [PATCH] [Console] Remove deprecations across the component --- .github/expected-missing-return-types.diff | 94 +++++++++---------- UPGRADE-7.0.md | 7 ++ src/Symfony/Component/Console/Application.php | 14 +-- src/Symfony/Component/Console/CHANGELOG.md | 7 ++ .../Component/Console/Command/Command.php | 59 ++---------- .../Console/Command/CompleteCommand.php | 10 -- .../Console/Command/DumpCompletionCommand.php | 10 -- .../Component/Console/Command/LazyCommand.php | 11 +-- .../Command/SignalableCommandInterface.php | 4 +- .../Formatter/NullOutputFormatterStyle.php | 10 +- .../Formatter/OutputFormatterStyle.php | 10 +- .../Component/Console/Helper/Helper.php | 5 +- .../Component/Console/Input/InputArgument.php | 5 +- .../Component/Console/Input/InputOption.php | 5 +- .../Component/Console/Input/StringInput.php | 4 - .../Component/Console/Question/Question.php | 10 +- .../Console/Tests/Command/CommandTest.php | 50 ---------- .../Component/Dotenv/Command/DebugCommand.php | 10 -- src/Symfony/Component/Runtime/composer.json | 2 +- 19 files changed, 83 insertions(+), 244 deletions(-) diff --git a/.github/expected-missing-return-types.diff b/.github/expected-missing-return-types.diff index bd455327ec038..ce82fd236a718 100644 --- a/.github/expected-missing-return-types.diff +++ b/.github/expected-missing-return-types.diff @@ -2210,7 +2210,7 @@ index cc024da461..00b79e915f 100644 { $errors = []; diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php -index b7aaa6a29e..dd14cf2c5c 100644 +index f8526ae5ce..72da224185 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -114,5 +114,5 @@ class Application implements ResetInterface @@ -2340,66 +2340,66 @@ index b7aaa6a29e..dd14cf2c5c 100644 { foreach ($command->getHelperSet() as $helper) { diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php -index 704b112d1a..b296bffcbd 100644 +index fae37b686a..5bc670292d 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php -@@ -145,5 +145,5 @@ class Command +@@ -111,5 +111,5 @@ class Command * @return void */ - public function ignoreValidationErrors() + public function ignoreValidationErrors(): void { $this->ignoreValidationErrors = true; -@@ -153,5 +153,5 @@ class Command +@@ -119,5 +119,5 @@ class Command * @return void */ -- public function setApplication(Application $application = null) -+ public function setApplication(Application $application = null): void +- public function setApplication(?Application $application) ++ public function setApplication(?Application $application): void { - if (1 > \func_num_args()) { -@@ -171,5 +171,5 @@ class Command + $this->application = $application; +@@ -134,5 +134,5 @@ class Command * @return void */ - public function setHelperSet(HelperSet $helperSet) + public function setHelperSet(HelperSet $helperSet): void { $this->helperSet = $helperSet; -@@ -200,5 +200,5 @@ class Command +@@ -163,5 +163,5 @@ class Command * @return bool */ - public function isEnabled() + public function isEnabled(): bool { return true; -@@ -210,5 +210,5 @@ class Command +@@ -173,5 +173,5 @@ class Command * @return void */ - protected function configure() + protected function configure(): void { } -@@ -228,5 +228,5 @@ class Command +@@ -191,5 +191,5 @@ class Command * @see setCode() */ - protected function execute(InputInterface $input, OutputInterface $output) + protected function execute(InputInterface $input, OutputInterface $output): int { throw new LogicException('You must override the execute() method in the concrete command class.'); -@@ -242,5 +242,5 @@ class Command +@@ -205,5 +205,5 @@ class Command * @return void */ - protected function interact(InputInterface $input, OutputInterface $output) + protected function interact(InputInterface $input, OutputInterface $output): void { } -@@ -258,5 +258,5 @@ class Command +@@ -221,5 +221,5 @@ class Command * @return void */ - protected function initialize(InputInterface $input, OutputInterface $output) + protected function initialize(InputInterface $input, OutputInterface $output): void { } -@@ -701,5 +701,5 @@ class Command +@@ -656,5 +656,5 @@ class Command * @throws InvalidArgumentException if the helper is not defined */ - public function getHelper(string $name): mixed @@ -2436,14 +2436,14 @@ index 5850c3d7b8..e2371f88fd 100644 { $this diff --git a/src/Symfony/Component/Console/Command/SignalableCommandInterface.php b/src/Symfony/Component/Console/Command/SignalableCommandInterface.php -index 4d0876003d..d33732acb6 100644 +index 7ebffede11..40b301d18f 100644 --- a/src/Symfony/Component/Console/Command/SignalableCommandInterface.php +++ b/src/Symfony/Component/Console/Command/SignalableCommandInterface.php -@@ -31,4 +31,4 @@ interface SignalableCommandInterface +@@ -29,4 +29,4 @@ interface SignalableCommandInterface * @return int|false The exit code to return or false to continue the normal execution */ -- public function handleSignal(int $signal, /* int|false $previousExitCode = 0 */); -+ public function handleSignal(int $signal, /* int|false $previousExitCode = 0 */): int|false; +- public function handleSignal(int $signal, int|false $previousExitCode = 0); ++ public function handleSignal(int $signal, int|false $previousExitCode = 0): int|false; } diff --git a/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php b/src/Symfony/Component/Console/DependencyInjection/AddConsoleCommandPass.php index 27705ddb63..1b25473f75 100644 @@ -2528,38 +2528,38 @@ index 433cd41978..02187a7ffc 100644 /** diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php -index 346a474c61..db3012ced8 100644 +index f075e881d8..b93a539df1 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php @@ -42,5 +42,5 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface * @return void */ -- public function setForeground(string $color = null) -+ public function setForeground(string $color = null): void +- public function setForeground(?string $color) ++ public function setForeground(?string $color): void { - if (1 > \func_num_args()) { -@@ -53,5 +53,5 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface + $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options); +@@ -50,5 +50,5 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface * @return void */ -- public function setBackground(string $color = null) -+ public function setBackground(string $color = null): void +- public function setBackground(?string $color) ++ public function setBackground(?string $color): void { - if (1 > \func_num_args()) { -@@ -69,5 +69,5 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface + $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options); +@@ -63,5 +63,5 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface * @return void */ - public function setOption(string $option) + public function setOption(string $option): void { $this->options[] = $option; -@@ -78,5 +78,5 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface +@@ -72,5 +72,5 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface * @return void */ - public function unsetOption(string $option) + public function unsetOption(string $option): void { $pos = array_search($option, $this->options); -@@ -91,5 +91,5 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface +@@ -85,5 +85,5 @@ class OutputFormatterStyle implements OutputFormatterStyleInterface * @return void */ - public function setOptions(array $options) @@ -2645,31 +2645,31 @@ index eb32bce8fc..57edd56954 100644 { $options = array_merge([ diff --git a/src/Symfony/Component/Console/Helper/Helper.php b/src/Symfony/Component/Console/Helper/Helper.php -index 3631b30f69..5e4407a591 100644 +index c80c1f468f..9578a074bb 100644 --- a/src/Symfony/Component/Console/Helper/Helper.php +++ b/src/Symfony/Component/Console/Helper/Helper.php @@ -27,5 +27,5 @@ abstract class Helper implements HelperInterface * @return void */ -- public function setHelperSet(HelperSet $helperSet = null) -+ public function setHelperSet(HelperSet $helperSet = null): void +- public function setHelperSet(?HelperSet $helperSet) ++ public function setHelperSet(?HelperSet $helperSet): void { - if (1 > \func_num_args()) { -@@ -95,5 +95,5 @@ abstract class Helper implements HelperInterface + $this->helperSet = $helperSet; +@@ -92,5 +92,5 @@ abstract class Helper implements HelperInterface * @return string */ - public static function formatTime(int|float $secs) + public static function formatTime(int|float $secs): string { static $timeFormats = [ -@@ -127,5 +127,5 @@ abstract class Helper implements HelperInterface +@@ -124,5 +124,5 @@ abstract class Helper implements HelperInterface * @return string */ - public static function formatMemory(int $memory) + public static function formatMemory(int $memory): string { if ($memory >= 1024 * 1024 * 1024) { -@@ -147,5 +147,5 @@ abstract class Helper implements HelperInterface +@@ -144,5 +144,5 @@ abstract class Helper implements HelperInterface * @return string */ - public static function removeDecoration(OutputFormatterInterface $formatter, ?string $string) @@ -2904,16 +2904,16 @@ index 0f5617cd17..bdd5dd264f 100644 { $this->stream = $stream; diff --git a/src/Symfony/Component/Console/Input/InputArgument.php b/src/Symfony/Component/Console/Input/InputArgument.php -index 5cb151488d..2dc276a372 100644 +index fa57f5d0d4..e657b56ad7 100644 --- a/src/Symfony/Component/Console/Input/InputArgument.php +++ b/src/Symfony/Component/Console/Input/InputArgument.php @@ -96,5 +96,5 @@ class InputArgument * @throws LogicException When incorrect default value is given */ -- public function setDefault(string|bool|int|float|array $default = null) -+ public function setDefault(string|bool|int|float|array $default = null): void +- public function setDefault(string|bool|int|float|array|null $default) ++ public function setDefault(string|bool|int|float|array|null $default): void { - if (1 > \func_num_args()) { + if ($this->isRequired() && null !== $default) { diff --git a/src/Symfony/Component/Console/Input/InputAwareInterface.php b/src/Symfony/Component/Console/Input/InputAwareInterface.php index 0ad27b4558..f5e544930e 100644 --- a/src/Symfony/Component/Console/Input/InputAwareInterface.php @@ -3037,16 +3037,16 @@ index aaed5fd01d..e7de9bcdec 100644 + public function setInteractive(bool $interactive): void; } diff --git a/src/Symfony/Component/Console/Input/InputOption.php b/src/Symfony/Component/Console/Input/InputOption.php -index fdf88dcc27..cf7a71a3c4 100644 +index c9e8aa82b6..ee7c119cd2 100644 --- a/src/Symfony/Component/Console/Input/InputOption.php +++ b/src/Symfony/Component/Console/Input/InputOption.php @@ -182,5 +182,5 @@ class InputOption * @return void */ -- public function setDefault(string|bool|int|float|array $default = null) -+ public function setDefault(string|bool|int|float|array $default = null): void +- public function setDefault(string|bool|int|float|array|null $default) ++ public function setDefault(string|bool|int|float|array|null $default): void { - if (1 > \func_num_args()) { + if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) { diff --git a/src/Symfony/Component/Console/Input/StreamableInputInterface.php b/src/Symfony/Component/Console/Input/StreamableInputInterface.php index 4b95fcb11e..b95fab2601 100644 --- a/src/Symfony/Component/Console/Input/StreamableInputInterface.php @@ -3283,10 +3283,10 @@ index b00445ece8..5e9b1086b0 100644 { $this->buffer .= $message; diff --git a/src/Symfony/Component/Console/Question/Question.php b/src/Symfony/Component/Console/Question/Question.php -index 26896bb531..af97d04ddc 100644 +index dec0954e79..873b302873 100644 --- a/src/Symfony/Component/Console/Question/Question.php +++ b/src/Symfony/Component/Console/Question/Question.php -@@ -270,5 +270,5 @@ class Question +@@ -264,5 +264,5 @@ class Question * @return bool */ - protected function isAssoc(array $array) @@ -4684,7 +4684,7 @@ index c1cd9087f0..a9efa77a6d 100644 { return $this->resolved; diff --git a/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBagInterface.php b/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBagInterface.php -index 51a662afc2..19e1f18d29 100644 +index 8c76fe7a8e..b255b0e8ef 100644 --- a/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBagInterface.php +++ b/src/Symfony/Component/DependencyInjection/ParameterBag/ParameterBagInterface.php @@ -29,5 +29,5 @@ interface ParameterBagInterface diff --git a/UPGRADE-7.0.md b/UPGRADE-7.0.md index 672a620aeaa51..5a3e9e011015d 100644 --- a/UPGRADE-7.0.md +++ b/UPGRADE-7.0.md @@ -10,6 +10,13 @@ Cache * Add parameter `$isSameDatabase` to `DoctrineDbalAdapter::configureSchema()` +Console +------- + + * Remove `Command::$defaultName` and `Command::$defaultDescription`, use the `AsCommand` attribute instead + * Passing null to `*Command::setApplication()`, `*FormatterStyle::setForeground/setBackground()`, `Helper::setHelpSet()`, `Input*::setDefault()` and `Question::setAutocompleterCallback/setValidator()` must be done explicitly + * Remove `StringInput::REGEX_STRING` + DoctrineBridge -------------- diff --git a/src/Symfony/Component/Console/Application.php b/src/Symfony/Component/Console/Application.php index b7aaa6a29e65a..f8526ae5ceb7f 100644 --- a/src/Symfony/Component/Console/Application.php +++ b/src/Symfony/Component/Console/Application.php @@ -1026,11 +1026,6 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI // If the command is signalable, we call the handleSignal() method if (\in_array($signal, $commandSignals, true)) { $exitCode = $command->handleSignal($signal, $exitCode); - // BC layer for Symfony <= 5 - if (null === $exitCode) { - trigger_deprecation('symfony/console', '6.3', 'Not returning an exit code from "%s::handleSignal()" is deprecated, return "false" to keep the command running or "0" to exit successfully.', get_debug_type($command)); - $exitCode = 0; - } } if (false !== $exitCode) { @@ -1045,14 +1040,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI foreach ($commandSignals as $signal) { $this->signalRegistry->register($signal, function (int $signal) use ($command): void { - $exitCode = $command->handleSignal($signal); - // BC layer for Symfony <= 5 - if (null === $exitCode) { - trigger_deprecation('symfony/console', '6.3', 'Not returning an exit code from "%s::handleSignal()" is deprecated, return "false" to keep the command running or "0" to exit successfully.', get_debug_type($command)); - $exitCode = 0; - } - - if (false !== $exitCode) { + if (false !== $exitCode = $command->handleSignal($signal)) { exit($exitCode); } }); diff --git a/src/Symfony/Component/Console/CHANGELOG.md b/src/Symfony/Component/Console/CHANGELOG.md index 48b8f5a707c51..1666fa4bb8e60 100644 --- a/src/Symfony/Component/Console/CHANGELOG.md +++ b/src/Symfony/Component/Console/CHANGELOG.md @@ -1,6 +1,13 @@ CHANGELOG ========= +7.0 +--- + + * Remove `Command::$defaultName` and `Command::$defaultDescription`, use the `AsCommand` attribute instead + * Passing null to `*Command::setApplication()`, `*FormatterStyle::setForeground/setBackground()`, `Helper::setHelpSet()`, `Input*::setDefault()` and `Question::setAutocompleterCallback/setValidator()` must be done explicitly + * Remove `StringInput::REGEX_STRING` + 6.4 --- diff --git a/src/Symfony/Component/Console/Command/Command.php b/src/Symfony/Component/Console/Command/Command.php index 704b112d1aed6..fae37b686a3c3 100644 --- a/src/Symfony/Component/Console/Command/Command.php +++ b/src/Symfony/Component/Console/Command/Command.php @@ -39,20 +39,6 @@ class Command public const FAILURE = 1; public const INVALID = 2; - /** - * @var string|null The default command name - * - * @deprecated since Symfony 6.1, use the AsCommand attribute instead - */ - protected static $defaultName; - - /** - * @var string|null The default command description - * - * @deprecated since Symfony 6.1, use the AsCommand attribute instead - */ - protected static $defaultDescription; - private ?Application $application = null; private ?string $name = null; private ?string $processTitle = null; @@ -70,40 +56,20 @@ class Command public static function getDefaultName(): ?string { - $class = static::class; - - if ($attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) { + if ($attribute = (new \ReflectionClass(static::class))->getAttributes(AsCommand::class)) { return $attribute[0]->newInstance()->name; } - $r = new \ReflectionProperty($class, 'defaultName'); - - if ($class !== $r->class || null === static::$defaultName) { - return null; - } - - trigger_deprecation('symfony/console', '6.1', 'Relying on the static property "$defaultName" for setting a command name is deprecated. Add the "%s" attribute to the "%s" class instead.', AsCommand::class, static::class); - - return static::$defaultName; + return null; } public static function getDefaultDescription(): ?string { - $class = static::class; - - if ($attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) { + if ($attribute = (new \ReflectionClass(static::class))->getAttributes(AsCommand::class)) { return $attribute[0]->newInstance()->description; } - $r = new \ReflectionProperty($class, 'defaultDescription'); - - if ($class !== $r->class || null === static::$defaultDescription) { - return null; - } - - trigger_deprecation('symfony/console', '6.1', 'Relying on the static property "$defaultDescription" for setting a command description is deprecated. Add the "%s" attribute to the "%s" class instead.', AsCommand::class, static::class); - - return static::$defaultDescription; + return null; } /** @@ -152,11 +118,8 @@ public function ignoreValidationErrors() /** * @return void */ - public function setApplication(Application $application = null) + public function setApplication(?Application $application) { - if (1 > \func_num_args()) { - trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); - } $this->application = $application; if ($application) { $this->setHelperSet($application->getHelperSet()); @@ -460,12 +423,8 @@ public function getNativeDefinition(): InputDefinition * * @throws InvalidArgumentException When argument mode is not valid */ - public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = null */): static + public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null, array|\Closure $suggestedValues = []): static { - $suggestedValues = 5 <= \func_num_args() ? func_get_arg(4) : []; - if (!\is_array($suggestedValues) && !$suggestedValues instanceof \Closure) { - throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be array or \Closure, "%s" given.', __METHOD__, get_debug_type($suggestedValues))); - } $this->definition->addArgument(new InputArgument($name, $mode, $description, $default, $suggestedValues)); $this->fullDefinition?->addArgument(new InputArgument($name, $mode, $description, $default, $suggestedValues)); @@ -484,12 +443,8 @@ public function addArgument(string $name, int $mode = null, string $description * * @throws InvalidArgumentException If option mode is invalid or incompatible */ - public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = [] */): static + public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null, array|\Closure $suggestedValues = []): static { - $suggestedValues = 6 <= \func_num_args() ? func_get_arg(5) : []; - if (!\is_array($suggestedValues) && !$suggestedValues instanceof \Closure) { - throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be array or \Closure, "%s" given.', __METHOD__, get_debug_type($suggestedValues))); - } $this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default, $suggestedValues)); $this->fullDefinition?->addOption(new InputOption($name, $shortcut, $mode, $description, $default, $suggestedValues)); diff --git a/src/Symfony/Component/Console/Command/CompleteCommand.php b/src/Symfony/Component/Console/Command/CompleteCommand.php index 058578d8b48d8..00dd05770ba25 100644 --- a/src/Symfony/Component/Console/Command/CompleteCommand.php +++ b/src/Symfony/Component/Console/Command/CompleteCommand.php @@ -34,16 +34,6 @@ final class CompleteCommand extends Command { public const COMPLETION_API_VERSION = '1'; - /** - * @deprecated since Symfony 6.1 - */ - protected static $defaultName = '|_complete'; - - /** - * @deprecated since Symfony 6.1 - */ - protected static $defaultDescription = 'Internal command to provide shell completion suggestions'; - private $completionOutputs; private $isDebug = false; diff --git a/src/Symfony/Component/Console/Command/DumpCompletionCommand.php b/src/Symfony/Component/Console/Command/DumpCompletionCommand.php index 51b613a1405ae..be6f545924f38 100644 --- a/src/Symfony/Component/Console/Command/DumpCompletionCommand.php +++ b/src/Symfony/Component/Console/Command/DumpCompletionCommand.php @@ -27,16 +27,6 @@ #[AsCommand(name: 'completion', description: 'Dump the shell completion script')] final class DumpCompletionCommand extends Command { - /** - * @deprecated since Symfony 6.1 - */ - protected static $defaultName = 'completion'; - - /** - * @deprecated since Symfony 6.1 - */ - protected static $defaultDescription = 'Dump the shell completion script'; - private array $supportedShells; protected function configure(): void diff --git a/src/Symfony/Component/Console/Command/LazyCommand.php b/src/Symfony/Component/Console/Command/LazyCommand.php index d56058221386c..7279724a681af 100644 --- a/src/Symfony/Component/Console/Command/LazyCommand.php +++ b/src/Symfony/Component/Console/Command/LazyCommand.php @@ -45,11 +45,8 @@ public function ignoreValidationErrors(): void $this->getCommand()->ignoreValidationErrors(); } - public function setApplication(Application $application = null): void + public function setApplication(?Application $application): void { - if (1 > \func_num_args()) { - trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); - } if ($this->command instanceof parent) { $this->command->setApplication($application); } @@ -116,9 +113,8 @@ public function getNativeDefinition(): InputDefinition /** * @param array|\Closure(CompletionInput,CompletionSuggestions):list $suggestedValues The values used for input completion */ - public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = [] */): static + public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null, array|\Closure $suggestedValues = []): static { - $suggestedValues = 5 <= \func_num_args() ? func_get_arg(4) : []; $this->getCommand()->addArgument($name, $mode, $description, $default, $suggestedValues); return $this; @@ -127,9 +123,8 @@ public function addArgument(string $name, int $mode = null, string $description /** * @param array|\Closure(CompletionInput,CompletionSuggestions):list $suggestedValues The values used for input completion */ - public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = [] */): static + public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null, array|\Closure $suggestedValues = []): static { - $suggestedValues = 6 <= \func_num_args() ? func_get_arg(5) : []; $this->getCommand()->addOption($name, $shortcut, $mode, $description, $default, $suggestedValues); return $this; diff --git a/src/Symfony/Component/Console/Command/SignalableCommandInterface.php b/src/Symfony/Component/Console/Command/SignalableCommandInterface.php index 4d0876003d5fd..7ebffede11235 100644 --- a/src/Symfony/Component/Console/Command/SignalableCommandInterface.php +++ b/src/Symfony/Component/Console/Command/SignalableCommandInterface.php @@ -26,9 +26,7 @@ public function getSubscribedSignals(): array; /** * The method will be called when the application is signaled. * - * @param int|false $previousExitCode - * @return int|false The exit code to return or false to continue the normal execution */ - public function handleSignal(int $signal, /* int|false $previousExitCode = 0 */); + public function handleSignal(int $signal, int|false $previousExitCode = 0); } diff --git a/src/Symfony/Component/Console/Formatter/NullOutputFormatterStyle.php b/src/Symfony/Component/Console/Formatter/NullOutputFormatterStyle.php index c2ce7d14cc904..06fa6e40b247c 100644 --- a/src/Symfony/Component/Console/Formatter/NullOutputFormatterStyle.php +++ b/src/Symfony/Component/Console/Formatter/NullOutputFormatterStyle.php @@ -21,19 +21,13 @@ public function apply(string $text): string return $text; } - public function setBackground(string $color = null): void + public function setBackground(?string $color): void { - if (1 > \func_num_args()) { - trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); - } // do nothing } - public function setForeground(string $color = null): void + public function setForeground(?string $color): void { - if (1 > \func_num_args()) { - trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); - } // do nothing } diff --git a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php index 346a474c613d2..f075e881d8359 100644 --- a/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php +++ b/src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php @@ -41,22 +41,16 @@ public function __construct(string $foreground = null, string $background = null /** * @return void */ - public function setForeground(string $color = null) + public function setForeground(?string $color) { - if (1 > \func_num_args()) { - trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); - } $this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options); } /** * @return void */ - public function setBackground(string $color = null) + public function setBackground(?string $color) { - if (1 > \func_num_args()) { - trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); - } $this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options); } diff --git a/src/Symfony/Component/Console/Helper/Helper.php b/src/Symfony/Component/Console/Helper/Helper.php index 3631b30f692ab..c80c1f468f09f 100644 --- a/src/Symfony/Component/Console/Helper/Helper.php +++ b/src/Symfony/Component/Console/Helper/Helper.php @@ -26,11 +26,8 @@ abstract class Helper implements HelperInterface /** * @return void */ - public function setHelperSet(HelperSet $helperSet = null) + public function setHelperSet(?HelperSet $helperSet) { - if (1 > \func_num_args()) { - trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); - } $this->helperSet = $helperSet; } diff --git a/src/Symfony/Component/Console/Input/InputArgument.php b/src/Symfony/Component/Console/Input/InputArgument.php index 5cb151488dc56..fa57f5d0d4709 100644 --- a/src/Symfony/Component/Console/Input/InputArgument.php +++ b/src/Symfony/Component/Console/Input/InputArgument.php @@ -95,11 +95,8 @@ public function isArray(): bool * * @throws LogicException When incorrect default value is given */ - public function setDefault(string|bool|int|float|array $default = null) + public function setDefault(string|bool|int|float|array|null $default) { - if (1 > \func_num_args()) { - trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); - } if ($this->isRequired() && null !== $default) { throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.'); } diff --git a/src/Symfony/Component/Console/Input/InputOption.php b/src/Symfony/Component/Console/Input/InputOption.php index fdf88dcc27490..c9e8aa82b64b5 100644 --- a/src/Symfony/Component/Console/Input/InputOption.php +++ b/src/Symfony/Component/Console/Input/InputOption.php @@ -181,11 +181,8 @@ public function isNegatable(): bool /** * @return void */ - public function setDefault(string|bool|int|float|array $default = null) + public function setDefault(string|bool|int|float|array|null $default) { - if (1 > \func_num_args()) { - trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); - } 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.'); } diff --git a/src/Symfony/Component/Console/Input/StringInput.php b/src/Symfony/Component/Console/Input/StringInput.php index 82bd21440807e..33f0f4b39bdbc 100644 --- a/src/Symfony/Component/Console/Input/StringInput.php +++ b/src/Symfony/Component/Console/Input/StringInput.php @@ -24,10 +24,6 @@ */ class StringInput extends ArgvInput { - /** - * @deprecated since Symfony 6.1 - */ - public const REGEX_STRING = '([^\s]+?)(?:\s|(? \func_num_args()) { - trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); - } if ($this->hidden && null !== $callback) { throw new LogicException('A hidden question cannot use the autocompleter.'); } @@ -194,11 +191,8 @@ public function setAutocompleterCallback(callable $callback = null): static * * @return $this */ - public function setValidator(callable $validator = null): static + public function setValidator(?callable $validator): static { - if (1 > \func_num_args()) { - trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__); - } $this->validator = null === $validator ? null : $validator(...); return $this; diff --git a/src/Symfony/Component/Console/Tests/Command/CommandTest.php b/src/Symfony/Component/Console/Tests/Command/CommandTest.php index f85280fed6401..48ba927063c77 100644 --- a/src/Symfony/Component/Console/Tests/Command/CommandTest.php +++ b/src/Symfony/Component/Console/Tests/Command/CommandTest.php @@ -442,37 +442,6 @@ public function testCommandAttribute() $this->assertSame(['f'], $command->getAliases()); } - /** - * @group legacy - */ - public function testDefaultNameProperty() - { - $this->expectDeprecation('Since symfony/console 6.1: Relying on the static property "$defaultName" for setting a command name is deprecated. Add the "Symfony\Component\Console\Attribute\AsCommand" attribute to the "Symfony\Component\Console\Tests\Command\MyCommand" class instead.'); - - $this->assertSame('my:command', MyCommand::getDefaultName()); - } - - /** - * @group legacy - */ - public function testDefaultDescriptionProperty() - { - $this->expectDeprecation('Since symfony/console 6.1: Relying on the static property "$defaultDescription" for setting a command description is deprecated. Add the "Symfony\Component\Console\Attribute\AsCommand" attribute to the "Symfony\Component\Console\Tests\Command\MyCommand" class instead.'); - - $this->assertSame('This is a command I wrote all by myself', MyCommand::getDefaultDescription()); - } - - /** - * @group legacy - */ - public function testStaticDefaultProperties() - { - $command = new MyCommand(); - - $this->assertSame('my:command', $command->getName()); - $this->assertSame('This is a command I wrote all by myself', $command->getDescription()); - } - public function testAttributeOverridesProperty() { $this->assertSame('my:command', MyAnnotatedCommand::getDefaultName()); @@ -518,29 +487,10 @@ class Php8Command2 extends Command { } -class MyCommand extends Command -{ - /** - * @deprecated since Symfony 6.1 - */ - protected static $defaultName = 'my:command'; - - /** - * @deprecated since Symfony 6.1 - */ - protected static $defaultDescription = 'This is a command I wrote all by myself'; -} - #[AsCommand(name: 'my:command', description: 'This is a command I wrote all by myself')] class MyAnnotatedCommand extends Command { - /** - * @deprecated since Symfony 6.1 - */ protected static $defaultName = 'i-shall-be-ignored'; - /** - * @deprecated since Symfony 6.1 - */ protected static $defaultDescription = 'This description should be ignored.'; } diff --git a/src/Symfony/Component/Dotenv/Command/DebugCommand.php b/src/Symfony/Component/Dotenv/Command/DebugCommand.php index 85cca991ca760..d78bb0911d3df 100644 --- a/src/Symfony/Component/Dotenv/Command/DebugCommand.php +++ b/src/Symfony/Component/Dotenv/Command/DebugCommand.php @@ -29,16 +29,6 @@ #[AsCommand(name: 'debug:dotenv', description: 'Lists all dotenv files with variables and values')] final class DebugCommand extends Command { - /** - * @deprecated since Symfony 6.1 - */ - protected static $defaultName = 'debug:dotenv'; - - /** - * @deprecated since Symfony 6.1 - */ - protected static $defaultDescription = 'Lists all dotenv files with variables and values'; - private $kernelEnvironment; private $projectDirectory; diff --git a/src/Symfony/Component/Runtime/composer.json b/src/Symfony/Component/Runtime/composer.json index 02d1c2f72ba5a..fa9c2cb3f58d0 100644 --- a/src/Symfony/Component/Runtime/composer.json +++ b/src/Symfony/Component/Runtime/composer.json @@ -20,7 +20,7 @@ "composer-plugin-api": "^1.0|^2.0" }, "require-dev": { - "composer/composer": "^1.0.2|^2.0", + "composer/composer": "^2.6", "symfony/console": "^6.4|^7.0", "symfony/dotenv": "^6.4|^7.0", "symfony/http-foundation": "^6.4|^7.0",