Skip to content

Commit 3a5c082

Browse files
committed
improve pos support
1 parent 862e6e6 commit 3a5c082

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/Job.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,25 @@ private function setArguments(mixed ...$argument): void
164164
if (! $this->parameters->isVariadic()) {
165165
$this->assertArgumentsCount($argument);
166166
}
167+
if (count($this->parameters) === 0) {
168+
$this->arguments = $argument; // @phpstan-ignore-line
169+
170+
return;
171+
}
172+
$isPositional = array_is_list($argument);
167173
$lastKey = array_key_last($this->parameters->keys());
168174
$lastName = $this->parameters->keys()[$lastKey] ?? null;
169-
$values = [];
170175
foreach ($this->parameters as $name => $parameter) {
171176
if ($name === $lastName && $this->parameters->isVariadic()) {
172-
$variadicKeys = array_diff_key(
173-
$argument,
174-
array_flip($this->parameters->keys())
175-
);
177+
if ($isPositional) {
178+
/** @var int $lastKey */
179+
$variadicKeys = array_slice($argument, $lastKey);
180+
} else {
181+
$variadicKeys = array_diff_key(
182+
$argument,
183+
array_flip($this->parameters->keys())
184+
);
185+
}
176186
foreach ($variadicKeys as $key => $value) {
177187
$key = strval($key);
178188
$values[$key] = $value;

0 commit comments

Comments
 (0)