Skip to content

Commit 3521111

Browse files
committed
"in" and "notIn" rules must have at least one option
1 parent 53b34c9 commit 3521111

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

src/Traits/Validator.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,26 +211,28 @@ public function notBetween(int | string $min, int | string $max) : static
211211
/**
212212
* Validate field is in list.
213213
*
214-
* @param string ...$in
214+
* @param string $in
215+
* @param string ...$others
215216
*
216217
* @return static
217218
*/
218-
public function in(string ...$in) : static
219+
public function in(string $in, string ...$others) : static
219220
{
220-
$this->rules[] = 'in:' . $this->implode($in);
221+
$this->rules[] = 'in:' . $this->implode([$in, ...$others]);
221222
return $this;
222223
}
223224

224225
/**
225226
* Validate field is not in list.
226227
*
227-
* @param string ...$notIn
228+
* @param string $notIn
229+
* @param string ...$others
228230
*
229231
* @return static
230232
*/
231-
public function notIn(string ...$notIn) : static
233+
public function notIn(string $notIn, string ...$others) : static
232234
{
233-
$this->rules[] = 'notIn:' . $this->implode($notIn);
235+
$this->rules[] = 'notIn:' . $this->implode([$notIn, ...$others]);
234236
return $this;
235237
}
236238

src/Validator.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,28 +307,30 @@ public static function notBetween(
307307
*
308308
* @param string $field
309309
* @param array<string,mixed> $data
310-
* @param string ...$in
310+
* @param string $in
311+
* @param string ...$others
311312
*
312313
* @return bool
313314
*/
314-
public static function in(string $field, array $data, string ...$in) : bool
315+
public static function in(string $field, array $data, string $in, string ...$others) : bool
315316
{
316317
$data = static::getData($field, $data);
317-
return $data !== null && \in_array($data, $in, true);
318+
return $data !== null && \in_array($data, [$in, ...$others], true);
318319
}
319320

320321
/**
321322
* Validate field is not in list.
322323
*
323324
* @param string $field
324325
* @param array<string,mixed> $data
325-
* @param string ...$notIn
326+
* @param string $notIn
327+
* @param string ...$others
326328
*
327329
* @return bool
328330
*/
329-
public static function notIn(string $field, array $data, string ...$notIn) : bool
331+
public static function notIn(string $field, array $data, string $notIn, string ...$others) : bool
330332
{
331-
return ! static::in($field, $data, ...$notIn);
333+
return ! static::in($field, $data, $notIn, ...$others);
332334
}
333335

334336
/**

0 commit comments

Comments
 (0)