@@ -26,7 +26,7 @@ final class ProcessRunner {
2626 *
2727 * @param string $command Shell command to execute.
2828 * @param array<string,mixed> $options Execution options.
29- * @return array{success: bool, output: string, exit_code: int} |\WP_Error
29+ * @return array< string,mixed> |\WP_Error
3030 */
3131 public static function run ( string $ command , array $ options = array () ): array |\WP_Error {
3232 $ timeout_seconds = max (0 , (int ) ( $ options ['timeout_seconds ' ] ?? 0 ));
@@ -53,7 +53,7 @@ public static function run( string $command, array $options = array() ): array|\
5353
5454 /**
5555 * @param array<string,mixed> $options
56- * @return array{success: bool, output: string, exit_code: int} |\WP_Error
56+ * @return array< string,mixed> |\WP_Error
5757 */
5858 private static function run_via_exec ( string $ command , array $ options , int $ output_cap ): array |\WP_Error {
5959 $ shell = RuntimeCapabilities::shell_diagnostic ();
@@ -87,7 +87,7 @@ private static function run_via_exec( string $command, array $options, int $outp
8787 * @param array<string,mixed> $options
8888 * @param callable|null $on_output
8989 * @param array<string,mixed>|null $env
90- * @return array{success: bool, output: string, exit_code: int} |\WP_Error
90+ * @return array< string,mixed> |\WP_Error
9191 */
9292 private static function run_via_proc_open ( string $ command , array $ options , int $ timeout_seconds , int $ output_cap , ?callable $ on_output , ?string $ cwd , ?array $ env ): array |\WP_Error {
9393 $ descriptor_spec = array (
@@ -108,8 +108,8 @@ private static function run_via_proc_open( string $command, array $options, int
108108 $ stdout = '' ;
109109 $ stderr = '' ;
110110 $ output = '' ;
111- $ deadline = $ timeout_seconds > 0 ? microtime (true ) + $ timeout_seconds : null ;
112- $ exit_code = null ;
111+ $ deadline = $ timeout_seconds > 0 ? microtime (true ) + $ timeout_seconds : null ;
112+ $ exit_code = 0 ;
113113
114114 while ( true ) {
115115 $ stdout_chunk = (string ) stream_get_contents ($ pipes [1 ]);
@@ -126,7 +126,7 @@ private static function run_via_proc_open( string $command, array $options, int
126126
127127 $ status = proc_get_status ($ process );
128128 if ( empty ($ status ['running ' ]) ) {
129- $ exit_code = isset ( $ status [ ' exitcode ' ]) ? ( int ) $ status ['exitcode ' ] : null ;
129+ $ exit_code = ( int ) $ status ['exitcode ' ];
130130 break ;
131131 }
132132
@@ -158,7 +158,7 @@ private static function run_via_proc_open( string $command, array $options, int
158158 }
159159
160160 $ close_code = proc_close ($ process );
161- if ( null === $ exit_code ) {
161+ if ( - 1 === $ exit_code ) {
162162 $ exit_code = $ close_code ;
163163 }
164164
@@ -236,6 +236,7 @@ private static function cap_output( string $output, int $output_cap ): string {
236236 /**
237237 * @param array<string,mixed> $options
238238 * @param array<string,mixed> $data
239+ * @return array<string,mixed>|\WP_Error
239240 */
240241 private static function error ( array $ options , string $ message , array $ data = array () ): array |\WP_Error {
241242 if ( ! empty ($ options ['error_as_result ' ]) ) {
0 commit comments