diff --git a/src/MonthSelect.php b/src/MonthSelect.php index 6aabbf55..7bd4292d 100644 --- a/src/MonthSelect.php +++ b/src/MonthSelect.php @@ -35,16 +35,26 @@ public function __invoke(mixed $value): mixed return $this->filter($value); } + /** + * Returns the result of filtering $value + * + * @template T + * @param T $value + * @return string|null|T + */ public function filter(mixed $value): mixed { if (! is_array($value)) { return $value; } - /** @var mixed $month */ $month = $value['month'] ?? null; - /** @var mixed $year */ + /** @var mixed $month */ + $month = $month === '' ? null : $month; + $year = $value['year'] ?? null; + /** @var mixed $year */ + $year = $year === '' ? null : $year; if ($this->returnNullIfAnyFieldEmpty && ($month === null || $year === null)) { return null; @@ -55,7 +65,7 @@ public function filter(mixed $value): mixed } if (! $this->isParsableAsDateValue($month, 1, 12) || ! $this->isParsableAsDateValue($year, 0, 9999)) { - /** @psalm-suppress InvalidReturnStatement */ + /** @psalm-var T */ return $value; } diff --git a/test/MonthSelectTest.php b/test/MonthSelectTest.php index 847ed103..03d2692d 100644 --- a/test/MonthSelectTest.php +++ b/test/MonthSelectTest.php @@ -32,6 +32,7 @@ public static function provideFilter(): array [['null_on_empty' => true], ['year' => null], null], [['null_on_all_empty' => true], ['year' => null, 'month' => null], null], [['null_on_all_empty' => true], [], null], + [['null_on_all_empty' => true], ['year' => '', 'month' => ''], null], ]; }