GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( b09b4a...c4a10f )
by James
02:08
created

Middleware   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 33
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 24 6
1
<?php
2
3
namespace PragmaRX\Google2FALaravel;
4
5
use Closure;
6
use Illuminate\Http\Response;
7
use PragmaRX\Google2FALaravel\Support\Authenticator;
8
use PragmaRX\Google2FALaravel\Support\Constants;
9
10
/**
11
 * Class Middleware
12
 */
13
class Middleware
14
{
15
    /**
16
     * @param         $request
17
     * @param Closure $next
18
     *
19
     * @return \Illuminate\Http\JsonResponse|Response
20
     */
21 8
    public function handle($request, Closure $next)
22
    {
23
        /** @var Authenticator $authenticator */
24 8
        $authenticator = app(Authenticator::class)->boot($request);
25 8
        $cookieResult  = $authenticator->hasValidCookieToken();
26 8
        $authResult    = $authenticator->isAuthenticated();
27
28
        /** @var Response $response */
29 8
        $response = $next($request);
30
31 8
        if (false === $cookieResult && true === $authResult) {
32 4
            $cookieName = config('google2fa.cookie_name') ?? 'google2fa_token';
33 4
            $lifetime   = (int)(config('google2fa.cookie_lifetime') ?? 8035200);
34 4
            $lifetime   = $lifetime > 8035200 ? 8035200 : $lifetime;
35 4
            $token      = $authenticator->sessionGet(Constants::SESSION_TOKEN);
36 4
            $response->withCookie(cookie()->make($cookieName, $token, $lifetime / 60));
1 ignored issue
show
Bug introduced by
The method make does only exist in Illuminate\Cookie\CookieJar, but not in Symfony\Component\HttpFoundation\Cookie.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
37
        }
38
39 8
        if (true === $cookieResult || true === $authResult) {
40 4
            return $response;
41
        }
42
43 7
        return $authenticator->makeRequestOneTimePasswordResponse();
44
    }
45
}
46