FernandoCalmet /
php-slim-rest-api
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace App\Middleware; |
||
| 6 | |||
| 7 | use App\Exception\AuthException; |
||
| 8 | use Firebase\JWT\JWT; |
||
| 9 | |||
| 10 | abstract class Base |
||
| 11 | 32 | { |
|
| 12 | protected function checkToken(string $token): object |
||
| 13 | { |
||
| 14 | 32 | try { |
|
| 15 | 1 | return JWT::decode($token, $_SERVER['SECRET_KEY'], ['HS256']); |
|
|
0 ignored issues
–
show
|
|||
| 16 | 1 | } catch (\UnexpectedValueException) { |
|
| 17 | throw new AuthException('Forbidden: you are not authorized.', 403); |
||
| 18 | } |
||
| 19 | } |
||
| 20 | } |
||
| 21 |
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. Please note the @ignore annotation hint above.