Skip to content

Commit e07c964

Browse files
committed
fix: throw an exception if $cmd is not an indexed array
1 parent ededd88 commit e07c964

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

‎src/ChildProcess.php

+14-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function start(
5858
?array $env = null,
5959
bool $persistent = false
6060
): static {
61-
$cmd = is_array($cmd) ? array_values($cmd) : [$cmd];
61+
$cmd = $this->ensureCmdIsAnIndexedArray($cmd);
6262

6363
$process = $this->client->post('child-process/start', [
6464
'alias' => $alias,
@@ -73,8 +73,8 @@ public function start(
7373

7474
public function php(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self
7575
{
76-
$cmd = is_array($cmd) ? array_values($cmd) : [$cmd];
77-
76+
$cmd = $this->ensureCmdIsAnIndexedArray($cmd);
77+
7878
$process = $this->client->post('child-process/start-php', [
7979
'alias' => $alias,
8080
'cmd' => $cmd,
@@ -135,4 +135,15 @@ protected function fromRuntimeProcess($process): static
135135

136136
return $this;
137137
}
138+
139+
protected function ensureCmdIsAnIndexedArray(string|array $cmd): array
140+
{
141+
if (is_string($cmd)) {
142+
return [$cmd];
143+
}
144+
145+
if (array_keys($cmd) !== range(0, count($cmd) - 1)) {
146+
throw new \InvalidArgumentException('Only indexed arrays are supported for the cmd: argument.');
147+
}
148+
}
138149
}

0 commit comments

Comments
 (0)