Skip to content

Commit 39c9857

Browse files
authored
Upgrade the minimum php version to 8.0 for circuit-breaker and command. (#4206)
1 parent c42f2bd commit 39c9857

8 files changed

Lines changed: 35 additions & 78 deletions

File tree

src/Annotation/Command.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@
1414
use Attribute;
1515
use Hyperf\Di\Annotation\AbstractAnnotation;
1616

17-
/**
18-
* @Annotation
19-
* @Target({"CLASS"})
20-
*/
2117
#[Attribute(Attribute::TARGET_CLASS)]
2218
class Command extends AbstractAnnotation
2319
{

src/Command.php

Lines changed: 28 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Symfony\Component\Console\Command\Command as SymfonyCommand;
2020
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
2121
use Symfony\Component\Console\Helper\Table;
22+
use Symfony\Component\Console\Helper\TableStyle;
2223
use Symfony\Component\Console\Input\ArrayInput;
2324
use Symfony\Component\Console\Input\InputInterface;
2425
use Symfony\Component\Console\Output\OutputInterface;
@@ -32,58 +33,39 @@ abstract class Command extends SymfonyCommand
3233

3334
/**
3435
* The name of the command.
35-
*
36-
* @var string
3736
*/
38-
protected $name;
37+
protected ?string $name = null;
3938

40-
/**
41-
* @var InputInterface
42-
*/
43-
protected $input;
39+
protected ?InputInterface $input = null;
4440

4541
/**
46-
* @var SymfonyStyle
42+
* @var null|SymfonyStyle
4743
*/
48-
protected $output;
44+
protected ?OutputInterface $output = null;
4945

5046
/**
5147
* The default verbosity of output commands.
52-
*
53-
* @var int
5448
*/
55-
protected $verbosity = OutputInterface::VERBOSITY_NORMAL;
49+
protected int $verbosity = OutputInterface::VERBOSITY_NORMAL;
5650

5751
/**
5852
* Execution in a coroutine environment.
59-
*
60-
* @var bool
6153
*/
62-
protected $coroutine = true;
54+
protected bool $coroutine = true;
6355

64-
/**
65-
* @var null|EventDispatcherInterface
66-
*/
67-
protected $eventDispatcher;
56+
protected ?EventDispatcherInterface $eventDispatcher = null;
6857

69-
/**
70-
* @var int
71-
*/
72-
protected $hookFlags;
58+
protected int $hookFlags = -1;
7359

7460
/**
7561
* The name and signature of the command.
76-
*
77-
* @var null|string
7862
*/
79-
protected $signature;
63+
protected ?string $signature = null;
8064

8165
/**
82-
* The mapping between human readable verbosity levels and Symfony's OutputInterface.
83-
*
84-
* @var array
66+
* The mapping between human-readable verbosity levels and Symfony's OutputInterface.
8567
*/
86-
protected $verbosityMap
68+
protected array $verbosityMap
8769
= [
8870
'v' => OutputInterface::VERBOSITY_VERBOSE,
8971
'vv' => OutputInterface::VERBOSITY_VERY_VERBOSE,
@@ -94,25 +76,21 @@ abstract class Command extends SymfonyCommand
9476

9577
/**
9678
* The exit code of the command.
97-
*
98-
* @var int
9979
*/
100-
protected $exitCode = 0;
80+
protected int $exitCode = 0;
10181

10282
public function __construct(string $name = null)
10383
{
104-
if (! $name && $this->name) {
105-
$name = $this->name;
106-
}
84+
$this->name = $name ?? $this->name;
10785

108-
if (! is_int($this->hookFlags)) {
86+
if ($this->hookFlags < 0) {
10987
$this->hookFlags = swoole_hook_flags();
11088
}
11189

11290
if (isset($this->signature)) {
11391
$this->configureUsingFluentDefinition();
11492
} else {
115-
parent::__construct($name);
93+
parent::__construct($this->name);
11694
}
11795

11896
$this->addEnableDispatcherOption();
@@ -138,28 +116,26 @@ public function confirm(string $question, bool $default = false): bool
138116

139117
/**
140118
* Prompt the user for input.
141-
*
142-
* @param null|mixed $default
143119
*/
144-
public function ask(string $question, $default = null)
120+
public function ask(string $question, string $default = null)
145121
{
146122
return $this->output->ask($question, $default);
147123
}
148124

149125
/**
150-
* Prompt the user for input with auto completion.
126+
* Prompt the user for input with auto-completion.
151127
*
152-
* @param null|mixed $default
128+
* @param null|bool|float|int|string $default
153129
*/
154130
public function anticipate(string $question, array $choices, $default = null)
155131
{
156132
return $this->askWithCompletion($question, $choices, $default);
157133
}
158134

159135
/**
160-
* Prompt the user for input with auto completion.
136+
* Prompt the user for input with auto-completion.
161137
*
162-
* @param null|mixed $default
138+
* @param null|bool|float|int|string $default
163139
*/
164140
public function askWithCompletion(string $question, array $choices, $default = null)
165141
{
@@ -184,7 +160,7 @@ public function secret(string $question, bool $fallback = true)
184160

185161
/**
186162
* Give the user a multiple choice from an array of answers.
187-
* @param null|mixed $default
163+
* @param mixed $default
188164
*/
189165
public function choiceMultiple(
190166
string $question,
@@ -202,7 +178,7 @@ public function choiceMultiple(
202178
/**
203179
* Give the user a single choice from an array of answers.
204180
*
205-
* @param null|mixed $default
181+
* @param mixed $default
206182
*/
207183
public function choice(
208184
string $question,
@@ -215,19 +191,16 @@ public function choice(
215191

216192
/**
217193
* Format input to textual table.
218-
*
219-
* @param mixed $rows
220-
* @param mixed $tableStyle
221194
*/
222-
public function table(array $headers, $rows, $tableStyle = 'default', array $columnStyles = []): void
195+
public function table(array $headers, array|Arrayable $rows, TableStyle|string $tableStyle = 'default', array $columnStyles = []): void
223196
{
224197
$table = new Table($this->output);
225198

226199
if ($rows instanceof Arrayable) {
227200
$rows = $rows->toArray();
228201
}
229202

230-
$table->setHeaders((array) $headers)->setRows($rows)->setStyle($tableStyle);
203+
$table->setHeaders($headers)->setRows($rows)->setStyle($tableStyle);
231204

232205
foreach ($columnStyles as $columnIndex => $columnStyle) {
233206
$table->setColumnStyle($columnIndex, $columnStyle);
@@ -375,7 +348,7 @@ protected function createInputFromArguments(array $arguments): ArrayInput
375348
}
376349

377350
/**
378-
* Get all of the context passed to the command.
351+
* Get all the context passed to the command.
379352
*/
380353
protected function context(): array
381354
{
@@ -395,9 +368,9 @@ protected function context(): array
395368
*/
396369
protected function specifyParameters(): void
397370
{
398-
// We will loop through all of the arguments and options for the command and
371+
// We will loop through all the arguments and options for the command and
399372
// set them all on the base command instance. This specifies what can get
400-
// passed into these commands as "parameters" to control the execution.
373+
// past into these commands as "parameters" to control the execution.
401374
if (method_exists($this, 'getArguments')) {
402375
foreach ($this->getArguments() ?? [] as $arguments) {
403376
call_user_func_array([$this, 'addArgument'], $arguments);

src/EnableEventDispatcher.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ public function addEnableDispatcherOption()
2626
public function enableDispatcher(InputInterface $input)
2727
{
2828
if ($input->getOption('enable-event-dispatcher')) {
29-
$this->eventDispatcher = ApplicationContext::getContainer()->get(EventDispatcherInterface::class);
29+
$dispatcher = ApplicationContext::getContainer()->get(EventDispatcherInterface::class);
30+
$this->eventDispatcher = $dispatcher instanceof EventDispatcherInterface ? $dispatcher : null;
3031
}
3132
}
3233
}

src/Event/Event.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,8 @@
1515

1616
abstract class Event
1717
{
18-
/**
19-
* @var Command
20-
*/
21-
protected $command;
22-
23-
public function __construct(Command $command)
18+
public function __construct(protected Command $command)
2419
{
25-
$this->command = $command;
2620
}
2721

2822
public function getCommand(): Command

src/Event/FailToHandle.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,9 @@
1616

1717
class FailToHandle extends Event
1818
{
19-
/**
20-
* @var Throwable
21-
*/
22-
protected $throwable;
23-
24-
public function __construct(Command $command, Throwable $throwable)
19+
public function __construct(Command $command, protected Throwable $throwable)
2520
{
2621
parent::__construct($command);
27-
28-
$this->throwable = $throwable;
2922
}
3023

3124
public function getThrowable(): Throwable

src/Parser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected static function name(string $expression): string
5151
}
5252

5353
/**
54-
* Extract all of the parameters from the tokens.
54+
* Extract all the parameters from the tokens.
5555
*/
5656
protected static function parameters(array $tokens): array
5757
{

tests/Command/SwooleFlagsCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
class SwooleFlagsCommand extends Command
1717
{
18-
protected $hookFlags = SWOOLE_HOOK_CURL | SWOOLE_HOOK_ALL;
18+
protected int $hookFlags = SWOOLE_HOOK_CURL | SWOOLE_HOOK_ALL;
1919

2020
public function handle()
2121
{

tests/CommandTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function testHookFlags()
4848
public function testExitCodeWhenThrowException()
4949
{
5050
/** @var FooExceptionCommand $command */
51-
$command = new ClassInvoker(new FooExceptionCommand());
51+
$command = new ClassInvoker(new FooExceptionCommand('foo'));
5252
$input = Mockery::mock(InputInterface::class);
5353
$input->shouldReceive('getOption')->andReturnFalse();
5454
$exitCode = $command->execute($input, Mockery::mock(OutputInterface::class));

0 commit comments

Comments
 (0)