@@ -6,21 +6,21 @@ class Process {
66 const PIPE_OUT = 1 ;
77 const PIPE_ERROR = 2 ;
88
9- /** @var string[] */
10- protected $ command ;
11- /** @var string */
12- protected $ cwd ;
13- /** @var array Indexed array of streams: 0=>input, 1=>output, 2=>error. */
14- protected $ pipes ;
9+ /** @var array<int, string> */
10+ protected array $ command ;
11+ protected string $ cwd ;
12+ /** @var array<int, resource> Indexed array of streams: 0=>input, 1=>output, 2=>error. */
13+ protected array $ pipes ;
1514 /** @var resource The process as returned from proc_open. */
1615 protected $ process = null ;
17- protected $ status ;
18- /** @var bool */
19- protected $ isBlocking = false ;
16+ /** @var array<string, mixed> */
17+ protected array $ status ;
18+ protected bool $ isBlocking = false ;
2019
2120 public function __construct (string ...$ command ) {
2221 $ this ->command = $ command ;
2322 $ this ->cwd = getcwd ();
23+ $ this ->pipes = [];
2424 }
2525
2626 public function __destruct () {
@@ -35,7 +35,7 @@ public function setExecCwd(string $cwd):void {
3535 * Runs the command in a concurrent thread.
3636 * Sets the input, output and errors streams.
3737 */
38- public function exec () {
38+ public function exec (): void {
3939 $ descriptor = [
4040 self ::PIPE_IN => ["pipe " , "r " ],
4141 self ::PIPE_OUT => ["pipe " , "w " ],
@@ -45,7 +45,11 @@ public function exec() {
4545 $ oldCwd = getcwd ();
4646 chdir ($ this ->cwd );
4747
48+ // Parameter #1 of proc_open is an array
49+ // @see https://www.php.net/manual/en/function.proc-open.php
50+
4851 $ this ->process = proc_open (
52+ /** @phpstan-param string[] */
4953 $ this ->command ,
5054 $ descriptor ,
5155 $ this ->pipes
@@ -89,6 +93,7 @@ public function hasNotEnded():bool {
8993 return $ this ->status ["exitcode " ] === 0 ;
9094 }
9195
96+ /** @return array<int, string> */
9297 public function getCommand ():array {
9398 return $ this ->command ;
9499 }
@@ -153,8 +158,8 @@ public function setBlocking(bool $blocking = true):void {
153158 * @see https://php.net/manual/function.proc-get-status.php
154159 **/
155160 protected function refreshStatus ():void {
156- if ( $ this ->status ["running " ] ?? null
157- || empty ($ this ->status )) {
161+ $ running = $ this ->status ["running " ] ?? null ;
162+ if ( $ running || empty ($ this ->status )) {
158163 if (is_resource ($ this ->process )) {
159164 $ this ->status = proc_get_status ($ this ->process );
160165 }
0 commit comments