Skip to content

Commit 539e875

Browse files
committed
fix: array_values but with a hint for static analyzer
1 parent e07c964 commit 539e875

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/ChildProcess.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@ public function all(): array
5151
return $hydrated;
5252
}
5353

54+
/**
55+
* @param string|string[] $cmd
56+
* @return $this
57+
*/
5458
public function start(
5559
string|array $cmd,
5660
string $alias,
5761
?string $cwd = null,
5862
?array $env = null,
5963
bool $persistent = false
6064
): static {
61-
$cmd = $this->ensureCmdIsAnIndexedArray($cmd);
65+
$cmd = is_array($cmd) ? array_values($cmd) : [$cmd];
6266

6367
$process = $this->client->post('child-process/start', [
6468
'alias' => $alias,
@@ -71,9 +75,13 @@ public function start(
7175
return $this->fromRuntimeProcess($process);
7276
}
7377

78+
/**
79+
* @param string|string[] $cmd
80+
* @return $this
81+
*/
7482
public function php(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self
7583
{
76-
$cmd = $this->ensureCmdIsAnIndexedArray($cmd);
84+
$cmd = is_array($cmd) ? array_values($cmd) : [$cmd];
7785

7886
$process = $this->client->post('child-process/start-php', [
7987
'alias' => $alias,
@@ -86,9 +94,15 @@ public function php(string|array $cmd, string $alias, ?array $env = null, ?bool
8694
return $this->fromRuntimeProcess($process);
8795
}
8896

97+
/**
98+
* @param string|string[] $cmd
99+
* @return $this
100+
*/
89101
public function artisan(string|array $cmd, string $alias, ?array $env = null, ?bool $persistent = false): self
90102
{
91-
$cmd = ['artisan', ...(array) $cmd];
103+
$cmd = is_array($cmd) ? array_values($cmd) : [$cmd];
104+
105+
$cmd = ['artisan', ...$cmd];
92106

93107
return $this->php($cmd, $alias, env: $env, persistent: $persistent);
94108
}
@@ -135,15 +149,4 @@ protected function fromRuntimeProcess($process): static
135149

136150
return $this;
137151
}
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-
}
149152
}

0 commit comments

Comments
 (0)