Closed kingkero closed 9 months ago
Running static analysis such as PHPStan results in an error for using $guard->factory() even if $guard instanceof JWTGuard is true.
$guard->factory()
$guard instanceof JWTGuard
'expires_in' => auth()->factory()->getTTL() * 60
this doesn't pass PHPStan with the error message
Call to an undefined method Illuminate\Contracts\Auth\StatefulGuard&Tymon\JWTAuth\JWTGuard::factory().
In a Controller that uses the api:auth middleware, using
api:auth
use App\Http\Controllers\Controller; use Illuminate\Http\JsonResponse; use Symfony\Component\Process\Exception\RuntimeException; use Tymon\JWTAuth\JWTGuard; class RefreshController extends Controller { public function __invoke(): JsonResponse { $guard = Auth('api'); if (! $guard instanceof JWTGuard) { throw new RuntimeException('Wrong guard returned.'); } return response()->json([ 'token_type' => 'Bearer', 'access_token' => $guard->refresh(), 'expires_in' => $guard->factory()->getTTL() * 60, ]); } }
PHPStan should realize that ->factory() exists on the JWTGuard (via the jwt token)
->factory()
JWTGuard
Triggers the
error
Subject of the issue
Running static analysis such as PHPStan results in an error for using
$guard->factory()
even if$guard instanceof JWTGuard
is true.this doesn't pass PHPStan with the error message
Your environment
Steps to reproduce
In a Controller that uses the
api:auth
middleware, usingExpected behaviour
PHPStan should realize that
->factory()
exists on theJWTGuard
(via the jwt token)Actual behaviour
Triggers the
error