Skip to content

Commit 19ce603

Browse files
committed
Minor refactoring
1 parent 22a759a commit 19ce603

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/Shell/Shell.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@ class Shell {
1919
protected $cwd;
2020
protected $descriptors;
2121
protected $env;
22-
protected $error;
2322
protected $input;
24-
protected $output;
2523
protected $pipes;
2624
protected $process;
2725
protected $startTime;
2826
protected $status;
2927
protected $timeout;
3028

31-
public function __construct($command, $cwd = null, $input = null, $env = null, $timeout = 60)
29+
public function __construct(string $command, string $cwd = null, string $input = null, string $env = null, float $timeout = 60)
3230
{
3331
if (!\function_exists('proc_open')) {
3432
throw new RuntimeException('Required proc_open could not be found in your PHP setup');
@@ -39,6 +37,7 @@ public function __construct($command, $cwd = null, $input = null, $env = null, $
3937
$this->env = $env;
4038
$this->input = $input;
4139
$this->timeout = $timeout;
40+
$this->status = null;
4241
}
4342

4443
private function getDescriptors()
@@ -84,9 +83,9 @@ public function execute(bool $blocking = false)
8483
}
8584

8685
$this->setInput();
86+
$this->updateStatus();
8787

8888
$this->startTime = microtime(true);
89-
$this->status = $this->updateStatus();
9089

9190
if ($blocking) {
9291
$this->wait();
@@ -95,16 +94,12 @@ public function execute(bool $blocking = false)
9594

9695
public function getOutput()
9796
{
98-
$this->output = stream_get_contents($this->pipes[self::STDOUT_DESCRIPTOR_KEY]);
99-
100-
return $this->output;
97+
return stream_get_contents($this->pipes[self::STDOUT_DESCRIPTOR_KEY]);
10198
}
10299

103100
public function getErrorOutput()
104101
{
105-
$this->error = stream_get_contents($this->pipes[self::STDERR_DESCRIPTOR_KEY]);
106-
107-
return $this->error;
102+
return stream_get_contents($this->pipes[self::STDERR_DESCRIPTOR_KEY]);
108103
}
109104

110105
public function getExitCode()
@@ -134,7 +129,7 @@ public function wait()
134129

135130
public function isRunning()
136131
{
137-
return $this->status['running'];
132+
return $this->status && $this->status['running'];
138133
}
139134

140135
public function stop()
@@ -144,8 +139,10 @@ public function stop()
144139
}
145140

146141
$this->closePipes();
147-
proc_close($this->process);
148-
$this->updateStatus();
142+
143+
if (\is_resource($this->process)) {
144+
proc_close($this->process);
145+
}
149146

150147
return $this->getExitCode();
151148
}

0 commit comments

Comments
 (0)