-
-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix not respecting return type of overridden Request::user() method.
- Loading branch information
1 parent
f934f35
commit e131dcd
Showing
3 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Bug1718; | ||
|
||
use Illuminate\Foundation\Http\FormRequest; | ||
use App\User; | ||
use function PHPStan\Testing\assertType; | ||
|
||
class AuthedRequest extends FormRequest | ||
{ | ||
public function authorize(): bool | ||
{ | ||
return parent::user() instanceof User; | ||
} | ||
|
||
public function user($guard = null): User | ||
{ | ||
$user = parent::user($guard); | ||
if (!$user instanceof User) { | ||
abort(403); | ||
} | ||
|
||
return $user; | ||
} | ||
} | ||
|
||
function test(AuthedRequest $request, FormRequest $formRequest): void | ||
{ | ||
assertType('App\User', $request->user()); | ||
assertType('App\User|null', $formRequest->user()); | ||
} |