Skip to content

Commit edd9daf

Browse files
committed
refactor: commands - move the null exit code deprecation earlier
1 parent 3718f6d commit edd9daf

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

system/Boot.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -428,17 +428,6 @@ protected static function initializeConsole(): Console
428428

429429
protected static function runCommand(Console $console): int
430430
{
431-
$exitCode = $console->initialize()->run();
432-
433-
if (! is_int($exitCode)) {
434-
@trigger_error(sprintf(
435-
'Since v4.8.0, commands must return an integer exit code. Last command "%s" exited with %s. Defaulting to EXIT_SUCCESS.',
436-
$console->getCommand(),
437-
get_debug_type($exitCode),
438-
), E_USER_DEPRECATED);
439-
$exitCode = EXIT_SUCCESS;
440-
}
441-
442-
return $exitCode;
431+
return $console->initialize()->run();
443432
}
444433
}

system/CLI/BaseCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function __construct(LoggerInterface $logger, Commands $commands)
101101
*
102102
* @param array<int|string, string|null> $params
103103
*
104-
* @return int|void
104+
* @return int|null
105105
*/
106106
abstract public function run(array $params);
107107

@@ -110,7 +110,7 @@ abstract public function run(array $params);
110110
*
111111
* @param array<int|string, string|null> $params
112112
*
113-
* @return int|void
113+
* @return int|null
114114
*
115115
* @throws ReflectionException
116116
*/

system/CLI/Commands.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,20 @@ public function run(string $command, array $params)
6969

7070
Events::trigger('pre_command');
7171

72-
$exit = $class->run($params);
72+
$exitCode = $class->run($params);
7373

7474
Events::trigger('post_command');
7575

76-
return $exit;
76+
if (! is_int($exitCode)) {
77+
@trigger_error(sprintf(
78+
'Since v4.8.0, commands must return an integer exit code. Last command "%s" exited with %s. Defaulting to EXIT_SUCCESS.',
79+
$command,
80+
get_debug_type($exitCode),
81+
), E_USER_DEPRECATED);
82+
$exitCode = EXIT_SUCCESS;
83+
}
84+
85+
return $exitCode;
7786
}
7887

7988
/**

system/CLI/Console.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class Console
3939
*
4040
* @param list<string> $tokens
4141
*
42-
* @return int|null Exit code or null for legacy commands that don't return an exit code.
42+
* @return int Exit code
4343
*/
4444
public function run(array $tokens = [])
4545
{

0 commit comments

Comments
 (0)