Skip to content

Commit 36591f1

Browse files
[Console] Remove deprecations across the component
1 parent 58f1ca5 commit 36591f1

23 files changed

+146
-351
lines changed

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

Lines changed: 104 additions & 121 deletions
Large diffs are not rendered by default.

UPGRADE-7.0.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ Cache
1010

1111
* Add parameter `$isSameDatabase` to `DoctrineDbalAdapter::configureSchema()`
1212

13+
Console
14+
-------
15+
16+
* Remove `Command::$defaultName` and `Command::$defaultDescription`, use the `AsCommand` attribute instead
17+
* Passing null to `*Command::setApplication()`, `*FormatterStyle::setForeground/setBackground()`, `Helper::setHelpSet()`, `Input*::setDefault()` and `Question::setAutocompleterCallback/setValidator()` must be done explicitly
18+
* Remove `StringInput::REGEX_STRING`
19+
1320
DoctrineBridge
1421
--------------
1522

src/Symfony/Component/Console/Application.php

Lines changed: 1 addition & 13 deletions
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

Lines changed: 7 additions & 0 deletions
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.4
512
---
613

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

Lines changed: 7 additions & 52 deletions
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

Lines changed: 1 addition & 13 deletions
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

Lines changed: 0 additions & 10 deletions
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

Lines changed: 3 additions & 8 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 2 additions & 8 deletions
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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

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

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


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy