@@ -46,6 +46,9 @@ class Shell_Command extends WP_CLI_Command {
4646 * wp> // Make changes to files in the plugin directory
4747 * Detected changes in wp-content/plugins/my-plugin, restarting shell...
4848 * wp>
49+ *
50+ * @param string[] $_ Positional arguments. Unused.
51+ * @param array{basic?: bool, watch?: string} $assoc_args Associative arguments.
4952 */
5053 public function __invoke ( $ _ , $ assoc_args ) {
5154 $ watch_path = Utils \get_flag_value ( $ assoc_args , 'watch ' , false );
@@ -107,7 +110,7 @@ public function __invoke( $_, $assoc_args ) {
107110 * Resolve and validate the watch path.
108111 *
109112 * @param string $path Path to watch.
110- * @return string Absolute path to watch.
113+ * @return string|never Absolute path to watch.
111114 */
112115 private function resolve_watch_path ( $ path ) {
113116 if ( ! file_exists ( $ path ) ) {
@@ -128,7 +131,7 @@ private function resolve_watch_path( $path ) {
128131 * This replaces the current process with a new one to fully reload all code.
129132 * Falls back to in-process restart if pcntl_exec is not available.
130133 *
131- * @param array $assoc_args Command arguments to preserve.
134+ * @param array{basic?: bool, watch?: string} $assoc_args Command arguments to preserve.
132135 */
133136 private function restart_process ( $ assoc_args ) {
134137 // Check if pcntl_exec is available
@@ -143,10 +146,10 @@ private function restart_process( $assoc_args ) {
143146 // Get the WP-CLI script path
144147 $ wp_cli_script = null ;
145148 foreach ( array ( 'argv ' , '_SERVER ' ) as $ source ) {
146- if ( 'argv ' === $ source && isset ( $ GLOBALS ['argv ' ][0 ] ) ) {
149+ if ( 'argv ' === $ source && is_array ( $ GLOBALS [ ' argv ' ] ) && isset ( $ GLOBALS ['argv ' ][0 ] ) ) {
147150 $ wp_cli_script = $ GLOBALS ['argv ' ][0 ];
148151 break ;
149- } elseif ( '_SERVER ' === $ source && isset ( $ _SERVER ['argv ' ][0 ] ) ) {
152+ } elseif ( '_SERVER ' === $ source && is_array ( $ _SERVER [ ' argv ' ] ) && isset ( $ _SERVER ['argv ' ][0 ] ) ) {
150153 $ wp_cli_script = $ _SERVER ['argv ' ][0 ];
151154 break ;
152155 }
@@ -170,9 +173,9 @@ private function restart_process( $assoc_args ) {
170173 }
171174
172175 // Add the path argument if present in $_SERVER
173- if ( isset ( $ _SERVER ['argv ' ] ) ) {
176+ if ( isset ( $ _SERVER ['argv ' ] ) && is_array ( $ _SERVER [ ' argv ' ] ) ) {
174177 foreach ( $ _SERVER ['argv ' ] as $ arg ) {
175- if ( '--path= ' === substr ( $ arg , 0 , 7 ) ) {
178+ if ( is_string ( $ arg ) && '--path= ' === substr ( $ arg , 0 , 7 ) ) {
176179 $ args [] = $ arg ;
177180 }
178181 }
0 commit comments