These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace WWON\JwtGuard; |
||
4 | |||
5 | use Carbon\Carbon; |
||
6 | use Illuminate\Support\Facades\Config; |
||
7 | |||
8 | class TokenManager implements Contract\TokenManager |
||
9 | { |
||
10 | |||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | protected $tokenTable; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $userForeignKey; |
||
20 | |||
21 | /** |
||
22 | * TokenManager constructor |
||
23 | */ |
||
24 | public function __construct() |
||
25 | { |
||
26 | $this->tokenTable = Config::get('jwt_guard.token_table'); |
||
27 | $this->userForeignKey = Config::get('jwt_guard.user_foreign_key'); |
||
28 | } |
||
29 | |||
30 | /** |
||
31 | * add claim to the white list |
||
32 | * |
||
33 | * @param Claim $claim |
||
34 | * @return bool |
||
35 | */ |
||
36 | public function add(Claim $claim) |
||
37 | { |
||
38 | if ($this->check($claim->sub, $claim->jti)) { |
||
0 ignored issues
–
show
|
|||
39 | return; |
||
40 | } |
||
41 | |||
42 | \DB::table($this->tokenTable)->insert([ |
||
43 | $this->userForeignKey => $claim->sub, |
||
44 | 'token' => $claim->jti, |
||
45 | 'created_at' => Carbon::now()->toDateTimeString(), |
||
46 | 'updated_at' => Carbon::now()->toDateTimeString() |
||
47 | ]); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * check that claim is in the white list |
||
52 | * |
||
53 | * @param Claim $claim |
||
54 | * @return bool |
||
55 | */ |
||
56 | public function check(Claim $claim) |
||
57 | { |
||
58 | $token = \DB::table($this->tokenTable) |
||
59 | ->where($this->userForeignKey, $claim->sub) |
||
60 | ->where('token', $claim->jti)->first(); |
||
61 | |||
62 | return !empty($token); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * remove claim from the white list |
||
67 | * |
||
68 | * @param Claim $claim |
||
69 | * @return bool |
||
70 | */ |
||
71 | public function remove(Claim $claim) |
||
72 | { |
||
73 | if (!$this->check($claim->sub, $claim->jti)) { |
||
0 ignored issues
–
show
The call to
TokenManager::check() has too many arguments starting with $claim->jti .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the
Loading history...
|
|||
74 | return false; |
||
75 | } |
||
76 | |||
77 | \DB::table($this->tokenTable) |
||
78 | ->where($this->userForeignKey, $claim->sub) |
||
79 | ->where('token', $claim->jti)->delete(); |
||
80 | |||
81 | return true; |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * remove all claims associate to the subject from the white list |
||
86 | * |
||
87 | * @param Claim $claim |
||
88 | * @return int |
||
89 | */ |
||
90 | public function removeAll(Claim $claim) |
||
91 | { |
||
92 | return \DB::table($this->tokenTable) |
||
93 | ->where($this->userForeignKey, $claim->sub) |
||
94 | ->delete(); |
||
95 | } |
||
96 | |||
97 | } |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.