Skip to content

Commit

Permalink
[9.x] Improves $request->enum() type API (laravel#44370)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: StyleCI Bot <[email protected]>
  • Loading branch information
3 people authored Sep 29, 2022
1 parent 678da30 commit 22e85eb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/Illuminate/Http/Concerns/InteractsWithInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<TEnum> $enumClass
* @return TEnum|null
*/
public function enum($key, $enumClass)
{
Expand Down
14 changes: 14 additions & 0 deletions types/Http/Request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

use Illuminate\Http\Request;
use function PHPStan\Testing\assertType;

class TestEnum
{
}

$request = Request::create('/', 'GET', [
'key' => 'test',
]);

assertType('TestEnum|null', $request->enum('key', TestEnum::class));

0 comments on commit 22e85eb

Please sign in to comment.