| Conditions | 4 |
| Paths | 4 |
| Total Lines | 24 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 15 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | public function login(array $input): string |
||
| 12 | 6 | { |
|
| 13 | $data = json_decode((string) json_encode($input), false); |
||
| 14 | 6 | if (!isset($data->email)) { |
|
| 15 | 6 | throw new \App\Exception\UserException('The field "email" is required.', 400); |
|
| 16 | 1 | } |
|
| 17 | if (!isset($data->password)) { |
||
| 18 | 5 | throw new \App\Exception\UserException('The field "password" is required.', 400); |
|
| 19 | 1 | } |
|
| 20 | $password = hash('sha512', $data->password); |
||
| 21 | 4 | $user = $this->userRepository->login($data->email, $password); |
|
| 22 | 4 | $token = [ |
|
| 23 | 'sub' => $user->getId(), |
||
| 24 | 3 | 'email' => $user->getEmail(), |
|
| 25 | 3 | 'name' => $user->getName(), |
|
| 26 | 3 | 'iat' => time(), |
|
| 27 | 3 | 'exp' => time() + (7 * 24 * 60 * 60), |
|
| 28 | 3 | ]; |
|
| 29 | |||
| 30 | if (self::isLoggerEnabled() === true) { |
||
| 31 | 3 | $this->loggerService->setInfo('The user with the ID ' . $user->getId() . ' has logged in successfully.'); |
|
| 32 | 3 | } |
|
| 33 | |||
| 34 | return JWT::encode($token, $_SERVER['SECRET_KEY']); |
||
|
|
|||
| 35 | 3 | } |
|
| 37 |
This check compares calls to functions or methods with their respective definitions. If the call has less 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.