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 ( 6d67f8...8413b3 )
by James
01:55
created

DeleteDBToken::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 19
ccs 0
cts 12
cp 0
rs 9.6333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 12
1
<?php
2
declare(strict_types=1);
3
4
5
namespace PragmaRX\Google2FALaravel\Listeners;
6
7
use Illuminate\Auth\Events\Logout;
8
use Illuminate\Database\QueryException;
9
use Illuminate\Support\Facades\DB;
10
use Illuminate\Support\Facades\Log;
11
12
/**
13
 * Class DeleteDBToken
14
 */
15
class DeleteDBToken
16
{
17
    /**
18
     * @param Logout $event
19
     */
20
    public function handle(Logout $event): void
21
    {
22
        $storeInCookie = config('google2fa.store_in_cookie', false);
23
        if (false === $storeInCookie) {
24
            return;
25
        }
26
        // delete token from DB, making cookie worthless.
27
        $cookieName = config('google2fa.cookie_name', 'google2fa_token');
28
        $token      = request()->cookies->get($cookieName);
29
30
        // check DB for token.
31
        try {
32
            DB::table('2fa_tokens')
33
                       ->where('token', $token)
34
                       ->where('user_id', $event->user->id)->delete();
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
35
        } catch (QueryException $e) {
36
            Log::error('Could not delete user token from database.');
37
        }
38
    }
39
40
}