From 22e85ebd79bcba77669891bc277af838c1b68920 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Thu, 29 Sep 2022 14:17:56 +0100 Subject: [PATCH] [9.x] Improves `$request->enum()` type API (#44370) * improve input enum method * type test for input enum method * Apply fixes from StyleCI * Fixes types tests and improves wording of generics Co-authored-by: SupunKavinda Co-authored-by: StyleCI Bot --- .../Http/Concerns/InteractsWithInput.php | 6 ++++-- types/Http/Request.php | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 types/Http/Request.php diff --git a/src/Illuminate/Http/Concerns/InteractsWithInput.php b/src/Illuminate/Http/Concerns/InteractsWithInput.php index a6b1e0983c05..ae28ca268b2a 100644 --- a/src/Illuminate/Http/Concerns/InteractsWithInput.php +++ b/src/Illuminate/Http/Concerns/InteractsWithInput.php @@ -372,9 +372,11 @@ public function date($key, $format = null, $tz = null) /** * Retrieve input from the request as an enum. * + * @template TEnum + * * @param string $key - * @param string $enumClass - * @return mixed|null + * @param class-string $enumClass + * @return TEnum|null */ public function enum($key, $enumClass) { diff --git a/types/Http/Request.php b/types/Http/Request.php new file mode 100644 index 000000000000..a13cec69a1cb --- /dev/null +++ b/types/Http/Request.php @@ -0,0 +1,14 @@ + 'test', +]); + +assertType('TestEnum|null', $request->enum('key', TestEnum::class));