8000 [Console] Remove deprecations across the component · symfony/symfony@a1854be · GitHub
[go: up one dir, main page]

Skip to content

Commit a1854be

Browse files
[Console] Remove deprecations across the component
1 parent d63071c commit a1854be

23 files changed

+107
-314
lines changed

.github/expected-missing-return-types.diff

+65-65
Large diffs are not rendered by default.

UPGRADE-7.0.md

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ Symfony 6.4 and Symfony 7.0 will be released simultaneously at the end of Novemb
55
release process, both versions will have the same features, but Symfony 7.0 won't include any deprecated features.
66
To upgrade, make sure to resolve all deprecation notices.
77

8+
Console
9+
-------
10+
11+
* Remove `Command::$defaultName` and `Command::$defaultDescription`, use the `AsCommand` attribute instead
12+
* Passing null to `*Command::setApplication()`, `*FormatterStyle::setForeground/setBackground()`, `Helper::setHelpSet()`, `Input*::setDefault()` and `Question::setAutocompleterCallback/setValidator()` must be done explicitly
13+
* Remove `StringInput::REGEX_STRING`
14+
815
DoctrineBridge
916
--------------
1017

src/Symfony/Component/Console/Application.php

+1-13
Original file line numberDiff line numberDiff line change
@@ -1026,11 +1026,6 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
10261026
// If the command is signalable, we call the handleSignal() method
10271027
if (\in_array($signal, $commandSignals, true)) {
10281028
$exitCode = $command->handleSignal($signal, $exitCode);
1029-
// BC layer for Symfony <= 5
1030-
if (null === $exitCode) {
1031-
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));
1032-
$exitCode = 0;
1033-
}
10341029
}
10351030

10361031
if (false !== $exitCode) {
@@ -1045,14 +1040,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
10451040

10461041
foreach ($commandSignals as $signal) {
10471042
$this->signalRegistry->register($signal, function (int $signal) use ($command): void {
1048-
$exitCode = $command->handleSignal($signal);
1049-
// BC layer for Symfony <= 5
1050-
if (null === $exitCode) {
1051-
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));
1052-
$exitCode = 0;
1053-
}
1054-
1055-
if (false !== $exitCode) {
1043+
if (false !== $exitCode = $command->handleSignal($signal)) {
10561044
exit($exitCode);
10571045
}
10581046
});

src/Symfony/Component/Console/CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
7.0
5+
---
6+
7+
* Remove `Command::$defaultName` and `Command::$defaultDescription`, use the `AsCommand` attribute instead
8+
* Passing null to `*Command::setApplication()`, `*FormatterStyle::setForeground/setBackground()`, `Helper::setHelpSet()`, `Input*::setDefault()` and `Question::setAutocompleterCallback/setValidator()` must be done explicitly
9+
* Remove `StringInput::REGEX_STRING`
10+
411
6.3
512
---
613

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

+7-52
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,6 @@ class Command
3939
public const FAILURE = 1;
4040
public const INVALID = 2;
4141

42-
/**
43-
* @var string|null The default command name
44-
*
45-
* @deprecated since Symfony 6.1, use the AsCommand attribute instead
46-
*/
47-
protected static $defaultName;
48-
49-
/**
50-
* @var string|null The default command description
51-
*
52-
* @deprecated since Symfony 6.1, use the AsCommand attribute instead
53-
*/
54-
protected static $defaultDescription;
55-
5642
private ?Application $application = null;
5743
private ?string $name = null;
5844
private ?string $processTitle = null;
@@ -70,40 +56,20 @@ class Command
7056

7157
public static function getDefaultName(): ?string
7258
{
73-
$class = static::class;
74-
75-
if ($attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) {
59+
if ($attribute = (new \ReflectionClass(static::class))->getAttributes(AsCommand::class)) {
7660
return $attribute[0]->newInstance()->name;
7761
}
7862

79-
$r = new \ReflectionProperty($class, 'defaultName');
80-
81-
if ($class !== $r->class || null === static::$defaultName) {
82-
return null;
83-
}
84-
85-
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);
86-
87-
return static::$defaultName;
63+
return null;
8864
}
8965

9066
public static function getDefaultDescription(): ?string
9167
{
92-
$class = static::class;
93-
94-
if ($attribute = (new \ReflectionClass($class))->getAttributes(AsCommand::class)) {
68+
if ($attribute = (new \ReflectionClass(static::class))->getAttributes(AsCommand::class)) {
9569
return $attribute[0]->newInstance()->description;
9670
}
9771

98-
$r = new \ReflectionProperty($class, 'defaultDescription');
99-
100-
if ($class !== $r->class || null === static::$defaultDescription) {
101-
return null;
102-
}
103-
104-
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);
105-
106-
return static::$defaultDescription;
72+
return null;
10773
}
10874

10975
/**
@@ -152,11 +118,8 @@ public function ignoreValidationErrors()
152118
/**
153119
* @return void
154120
*/
155-
public function setApplication(Application $application = null)
121+
public function setApplication(?Application $application)
156122
{
157-
if (1 > \func_num_args()) {
158-
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
159-
}
160123
$this->application = $application;
161124
if ($application) {
162125
$this->setHelperSet($application->getHelperSet());
@@ -460,12 +423,8 @@ public function getNativeDefinition(): InputDefinition
460423
*
461424
* @throws InvalidArgumentException When argument mode is not valid
462425
*/
463-
public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = null */): static
426+
public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null, array|\Closure $suggestedValues = []): static
464427
{
465-
$suggestedValues = 5 <= \func_num_args() ? func_get_arg(4) : [];
466-
if (!\is_array($suggestedValues) && !$suggestedValues instanceof \Closure) {
467-
throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be array or \Closure, "%s" given.', __METHOD__, get_debug_type($suggestedValues)));
468-
}
469428
$this->definition->addArgument(new InputArgument($name, $mode, $description, $default, $suggestedValues));
470429
$this->fullDefinition?->addArgument(new InputArgument($name, $mode, $description, $default, $suggestedValues));
471430

@@ -484,12 +443,8 @@ public function addArgument(string $name, int $mode = null, string $description
484443
*
485444
* @throws InvalidArgumentException If option mode is invalid or incompatible
486445
*/
487-
public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = [] */): static
446+
public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null, array|\Closure $suggestedValues = []): static
488447
{
489-
$suggestedValues = 6 <= \func_num_args() ? func_get_arg(5) : [];
490-
if (!\is_array($suggestedValues) && !$suggestedValues instanceof \Closure) {
491-
throw new \TypeError(sprintf('Argument 5 passed to "%s()" must be array or \Closure, "%s" given.', __METHOD__, get_debug_type($suggestedValues)));
492-
}
493448
$this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default, $suggestedValues));
494449
$this->fullDefinition?->addOption(new InputOption($name, $shortcut, $mode, $description, $default, $suggestedValues));
495450

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

+1-13
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,6 @@ final class CompleteCommand extends Command
3434
{
3535
public const COMPLETION_API_VERSION = '1';
3636

37-
/**
38-
* @deprecated since Symfony 6.1
39-
*/
40-
protected static $defaultName = '|_complete';
41-
42-
/**
43-
* @deprecated since Symfony 6.1
44-
*/
45-
protected static $defaultDescription = 'Internal command to provide shell completion suggestions';
46-
4737
private $completionOutputs;
4838

4939
private $isDebug = false;
@@ -70,7 +60,6 @@ protected function configure(): void
7060
->addOption('input', 'i', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'An array of input tokens (e.g. COMP_WORDS or argv)')
7161
->addOption('current', 'c', InputOption::VALUE_REQUIRED, 'The index of the "input" array that the cursor is in (e.g. COMP_CWORD)')
7262
->addOption('api-version', 'a', InputOption::VALUE_REQUIRED, 'The API version of the completion script')
73-
->addOption('symfony', 'S', InputOption::VALUE_REQUIRED, 'deprecated')
7463
;
7564
}
7665

@@ -82,8 +71,7 @@ protected function initialize(InputInterface $input, OutputInterface $output): v
8271
protected function execute(InputInterface $input, OutputInterface $output): int
8372
{
8473
try {
85-
// "symfony" must be kept for compat with the shell scripts generated by Symfony Console 5.4 - 6.1
86-
$version = $input->getOption('symfony') ? '1' : $input->getOption('api-version');
74+
$version = $input->getOption('api-version');
8775
if ($version && version_compare($version, self::COMPLETION_API_VERSION, '<')) {
8876
$message = sprintf('Completion script version is not supported ("%s" given, ">=%s" required).', $version, self::COMPLETION_API_VERSION);
8977
$this->log($message);

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

-10
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@
2727
#[AsCommand(name: 'completion', description: 'Dump the shell completion script')]
2828
final class DumpCompletionCommand extends Command
2929
{
30-
/**
31-
* @deprecated since Symfony 6.1
32-
*/
33-
protected static $defaultName = 'completion';
34-
35-
/**
36-
* @deprecated since Symfony 6.1
37-
*/
38-
protected static $defaultDescription = 'Dump the shell completion script';
39-
4030
private array $supportedShells;
4131

4232
protected function configure(): void

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

+3-8
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ public function ignoreValidationErrors(): void
4545
$this->getCommand()->ignoreValidationErrors();
4646
}
4747

48-
public function setApplication(Application $application = null): void
48+
public function setApplication(?Application $application): void
4949
{
50-
if (1 > \func_num_args()) {
51-
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
52-
}
5350
if ($this->command instanceof parent) {
5451
$this->command->setApplication($application);
5552
}
@@ -116,9 +113,8 @@ public function getNativeDefinition(): InputDefinition
116113
/**
117114
* @param array|\Closure(CompletionInput,CompletionSuggestions):list<string|Suggestion> $suggestedValues The values used for input completion
118115
*/
119-
public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = [] */): static
116+
public function addArgument(string $name, int $mode = null, string $description = '', mixed $default = null, array|\Closure $suggestedValues = []): static
120117
{
121-
$suggestedValues = 5 <= \func_num_args() ? func_get_arg(4) : [];
122118
$this->getCommand()->addArgument($name, $mode, $description, $default, $suggestedValues);
123119

124120
return $this;
@@ -127,9 +123,8 @@ public function addArgument(string $name, int $mode = null, string $description
127123
/**
128124
* @param array|\Closure(CompletionInput,CompletionSuggestions):list<string|Suggestion> $suggestedValues The values used for input completion
129125
*/
130-
public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null /* array|\Closure $suggestedValues = [] */): static
126+
public function addOption(string $name, string|array $shortcut = null, int $mode = null, string $description = '', mixed $default = null, array|\Closure $suggestedValues = []): static
131127
{
132-
$suggestedValues = 6 <= \func_num_args() ? func_get_arg(5) : [];
133128
$this->getCommand()->addOption($name, $shortcut, $mode, $description, $default, $suggestedValues);
134129

135130
return $this;

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ public function getSubscribedSignals(): array;
2626
/**
2727
* The method will be called when the application is signaled.
2828
*
29-
* @param int|false $previousExitCode
30-
3129
* @return int|false The exit code to return or false to continue the normal execution
3230
*/
33-
public function handleSignal(int $signal, /* int|false $previousExitCode = 0 */);
31+
public function handleSignal(int $signal, int|false $previousExitCode = 0);
3432
}

src/Symfony/Component/Console/Formatter/NullOutputFormatterStyle.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,13 @@ public function apply(string $text): string
2121
return $text;
2222
}
2323

24-
public function setBackground(string $color = null): void
24+
public function setBackground(?string $color): void
2525
{
26-
if (1 > \func_num_args()) {
27-
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
28-
}
2926
// do nothing
3027
}
3128

32-
public function setForeground(string $color = null): void
29+
public function setForeground(?string $color): void
3330
{
34-
if (1 > \func_num_args()) {
35-
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
36-
}
3731
// do nothing
3832
}
3933

src/Symfony/Component/Console/Formatter/OutputFormatterStyle.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,16 @@ public function __construct(string $foreground = null, string $background = null
4141
/**
4242
* @return void
4343
*/
44-
public function setForeground(string $color = null)
44+
public function setForeground(?string $color)
4545
{
46-
if (1 > \func_num_args()) {
47-
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
48-
}
4946
$this->color = new Color($this->foreground = $color ?: '', $this->background, $this->options);
5047
}
5148

5249
/**
5350
* @return void
5451
*/
55-
public function setBackground(string $color = null)
52+
public function setBackground(?string $color)
5653
{
57-
if (1 > \func_num_args()) {
58-
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
59-
}
6054
$this->color = new Color($this->foreground, $this->background = $color ?: '', $this->options);
6155
}
6256

src/Symfony/Component/Console/Helper/Helper.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,8 @@ abstract class Helper implements HelperInterface
2626
/**
2727
* @return void
2828
*/
29-
public function setHelperSet(HelperSet $helperSet = null)
29+
public function setHelperSet(?HelperSet $helperSet)
3030
{
31-
if (1 > \func_num_args()) {
32-
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
33-
}
3431
$this->helperSet = $helperSet;
3532
}
3633

src/Symfony/Component/Console/Input/InputArgument.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,8 @@ public function isArray(): bool
9595
*
9696
* @throws LogicException When incorrect default value is given
9797
*/
98-
public function setDefault(string|bool|int|float|array $default = null)
98+
public function setDefault(string|bool|int|float|array|null $default)
9999
{
100-
if (1 > \func_num_args()) {
101-
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
102-
}
103100
if ($this->isRequired() && null !== $default) {
104101
throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
105102
}

src/Symfony/Component/Console/Input/InputOption.php

+1-4
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,8 @@ public function isNegatable(): bool
181181
/**
182182
* @return void
183183
*/
184-
public function setDefault(string|bool|int|float|array $default = null)
184+
public function setDefault(string|bool|int|float|array|null $default)
185185
{
186-
if (1 > \func_num_args()) {
187-
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
188-
}
189186
if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
190187
throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
191188
}

src/Symfony/Component/Console/Input/StringInput.php

-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424
*/
2525
class StringInput extends ArgvInput
2626
{
27-
/**
28-
* @deprecated since Symfony 6.1
29-
*/
30-
public const REGEX_STRING = '([^\s]+?)(?:\s|(?<!\\\\)"|(?<!\\\\)\'|$)';
3127
public const REGEX_UNQUOTED_STRING = '([^\s\\\\]+?)';
3228
public const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';
3329

src/Symfony/Component/Console/Question/Question.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,8 @@ public function getAutocompleterCallback(): ?callable
175175
*
176176
* @return $this
177177
*/
178-
public function setAutocompleterCallback(callable $callback = null): static
178+
public function setAutocompleterCallback(?callable $callback): static
179179
{
180-
if (1 > \func_num_args()) {
181-
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
182-
}
183180
if ($this->hidden && null !== $callback) {
184181
throw new LogicException('A hidden question cannot use the autocompleter.');
185182
}
@@ -194,11 +191,8 @@ public function setAutocompleterCallback(callable $callback = null): static
194191
*
195192
* @return $this
196193
*/
197-
public function setValidator(callable $validator = null): static
194+
public function setValidator(?callable $validator): static
198195
{
199-
if (1 > \func_num_args()) {
200-
trigger_deprecation('symfony/console', '6.2', 'Calling "%s()" without any arguments is deprecated, pass null explicitly instead.', __METHOD__);
201-
}
202196
$this->validator = null === $validator ? null : $validator(...);
203197

204198
return $this;

0 commit comments

Comments
 (0)
0