Skip to content

Commit ee5a48c

Browse files
Copilotswissspidy
andcommitted
Improve code structure with early returns and better string formatting
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 844f0bd commit ee5a48c

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

src/Shell_Command.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,28 @@ class Shell_Command extends WP_CLI_Command {
4040
public function __invoke( $_, $assoc_args ) {
4141
$hook = Utils\get_flag_value( $assoc_args, 'hook', '' );
4242

43-
if ( $hook ) {
44-
// Check if the hook has already fired.
45-
if ( did_action( $hook ) ) {
46-
// Hook already fired, start the shell immediately.
47-
$this->start_shell( $assoc_args );
48-
} else {
49-
// Hook hasn't fired yet.
50-
WP_CLI::error(
51-
sprintf(
52-
"The '%s' hook has not fired yet. The shell command runs after WordPress is loaded, so only hooks that have already been triggered can be used. Common hooks that are available include: init, plugins_loaded, wp_loaded.",
53-
$hook
54-
)
55-
);
56-
}
57-
} else {
58-
// No hook specified, start immediately.
43+
// No hook specified, start immediately.
44+
if ( ! $hook ) {
5945
$this->start_shell( $assoc_args );
46+
return;
6047
}
48+
49+
// Check if the hook has already fired.
50+
if ( did_action( $hook ) ) {
51+
// Hook already fired, start the shell immediately.
52+
$this->start_shell( $assoc_args );
53+
return;
54+
}
55+
56+
// Hook hasn't fired yet.
57+
WP_CLI::error(
58+
sprintf(
59+
"The '%s' hook has not fired yet. " .
60+
'The shell command runs after WordPress is loaded, so only hooks that have already been triggered can be used. ' .
61+
'Common hooks that are available include: init, plugins_loaded, wp_loaded.',
62+
$hook
63+
)
64+
);
6165
}
6266

6367
/**

0 commit comments

Comments
 (0)