@@ -51,6 +51,9 @@ class Process implements \IteratorAggregate
5151 public const ITER_SKIP_OUT = 4 ; // Use this flag to skip STDOUT while iterating
5252 public const ITER_SKIP_ERR = 8 ; // Use this flag to skip STDERR while iterating
5353
54+ /**
55+ * @var \Closure('out'|'err', string)|null
56+ */
5457 private ?\Closure $ callback = null ;
5558 private array |string $ commandline ;
5659 private ?string $ cwd ;
@@ -231,8 +234,8 @@ public function __clone()
231234 * The STDOUT and STDERR are also available after the process is finished
232235 * via the getOutput() and getErrorOutput() methods.
233236 *
234- * @param callable|null $callback A PHP callback to run whenever there is some
235- * output available on STDOUT or STDERR
237+ * @param ( callable('out'|'err', string):void) |null $callback A PHP callback to run whenever there is some
238+ * output available on STDOUT or STDERR
236239 *
237240 * @return int The exit status code
238241 *
@@ -257,6 +260,9 @@ public function run(?callable $callback = null, array $env = []): int
257260 * This is identical to run() except that an exception is thrown if the process
258261 * exits with a non-zero exit code.
259262 *
263+ * @param (callable('out'|'err', string):void)|null $callback A PHP callback to run whenever there is some
264+ * output available on STDOUT or STDERR
265+ *
260266 * @return $this
261267 *
262268 * @throws ProcessFailedException if the process didn't terminate successfully
@@ -284,8 +290,8 @@ public function mustRun(?callable $callback = null, array $env = []): static
284290 * the output in real-time while writing the standard input to the process.
285291 * It allows to have feedback from the independent process during execution.
286292 *
287- * @param callable|null $callback A PHP callback to run whenever there is some
288- * output available on STDOUT or STDERR
293+ * @param ( callable('out'|'err', string):void) |null $callback A PHP callback to run whenever there is some
294+ * output available on STDOUT or STDERR
289295 *
290296 * @throws ProcessStartFailedException When process can't be launched
291297 * @throws RuntimeException When process is already running
@@ -395,8 +401,8 @@ public function start(?callable $callback = null, array $env = []): void
395401 *
396402 * Be warned that the process is cloned before being started.
397403 *
398- * @param callable|null $callback A PHP callback to run whenever there is some
399- * output available on STDOUT or STDERR
404+ * @param ( callable('out'|'err', string):void) |null $callback A PHP callback to run whenever there is some
405+ * output available on STDOUT or STDERR
400406 *
401407 * @throws ProcessStartFailedException When process can't be launched
402408 * @throws RuntimeException When process is already running
@@ -424,7 +430,8 @@ public function restart(?callable $callback = null, array $env = []): static
424430 * from the output in real-time while writing the standard input to the process.
425431 * It allows to have feedback from the independent process during execution.
426432 *
427- * @param callable|null $callback A valid PHP callback
433+ * @param (callable('out'|'err', string):void)|null $callback A PHP callback to run whenever there is some
434+ * output available on STDOUT or STDERR
428435 *
429436 * @return int The exitcode of the process
430437 *
@@ -471,6 +478,9 @@ public function wait(?callable $callback = null): int
471478 * from the output in real-time while writing the standard input to the process.
472479 * It allows to have feedback from the independent process during execution.
473480 *
481+ * @param (callable('out'|'err', string):bool)|null $callback A PHP callback to run whenever there is some
482+ * output available on STDOUT or STDERR
483+ *
474484 * @throws RuntimeException When process timed out
475485 * @throws LogicException When process is not yet started
476486 * @throws ProcessTimedOutException In case the timeout was reached
@@ -1291,22 +1301,21 @@ private function getDescriptors(bool $hasCallback): array
12911301 * The callbacks adds all occurred output to the specific buffer and calls
12921302 * the user callback (if present) with the received output.
12931303 *
1294- * @param callable|null $callback The user defined PHP callback
1304+ * @param callable('out'|'err', string)|null $callback
1305+ *
1306+ * @return \Closure('out'|'err', string):bool
12951307 */
12961308 protected function buildCallback (?callable $ callback = null ): \Closure
12971309 {
12981310 if ($ this ->outputDisabled ) {
12991311 return fn ($ type , $ data ): bool => null !== $ callback && $ callback ($ type , $ data );
13001312 }
13011313
1302- $ out = self ::OUT ;
1303-
1304- return function ($ type , $ data ) use ($ callback , $ out ): bool {
1305- if ($ out == $ type ) {
1306- $ this ->addOutput ($ data );
1307- } else {
1308- $ this ->addErrorOutput ($ data );
1309- }
1314+ return function ($ type , $ data ) use ($ callback ): bool {
1315+ match ($ type ) {
1316+ self ::OUT => $ this ->addOutput ($ data ),
1317+ self ::ERR => $ this ->addErrorOutput ($ data ),
1318+ };
13101319
13111320 return null !== $ callback && $ callback ($ type , $ data );
13121321 };
0 commit comments