| Total Complexity | 9 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Coverage | 95% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 14 | trait BeforeValidationTrait |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var callable|null |
||
| 18 | */ |
||
| 19 | private $skipOnEmptyCallback = null; |
||
| 20 | |||
| 21 | 99 | public function shouldSkipOnEmpty(mixed $validatedValue): bool |
|
| 24 | } |
||
| 25 | |||
| 26 | 138 | protected function setSkipOnEmptyCallback(mixed $skipOnEmpty = false): void |
|
| 27 | { |
||
| 28 | 138 | if ($skipOnEmpty === false) { |
|
| 29 | 123 | $this->skipOnEmptyCallback = null; |
|
| 30 | 123 | return; |
|
| 31 | } |
||
| 32 | |||
| 33 | 19 | if ($skipOnEmpty === true) { |
|
| 34 | 6 | $this->skipOnEmptyCallback = new SkipOnEmpty(); |
|
| 35 | 6 | return; |
|
| 36 | } |
||
| 37 | |||
| 38 | 14 | if (!is_callable($skipOnEmpty)) { |
|
| 39 | throw new InvalidArgumentException('$skipOnEmpty must be a boolean or a callable.'); |
||
| 40 | } |
||
| 41 | |||
| 42 | 14 | $this->skipOnEmptyCallback = $skipOnEmpty; |
|
| 43 | } |
||
| 44 | |||
| 45 | 15 | public function skipOnEmpty(bool|callable $value): self |
|
| 50 | } |
||
| 51 | |||
| 52 | 93 | public function shouldSkipOnError(): bool |
|
| 53 | { |
||
| 54 | 93 | return $this->skipOnError; |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @psalm-return Closure(mixed, ValidationContext):bool|null |
||
| 59 | * |
||
| 60 | * @return Closure|null |
||
| 61 | */ |
||
| 62 | 92 | public function getWhen(): ?Closure |
|
| 65 | } |
||
| 66 | } |
||
| 67 |