AuthController::login()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 9.9
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace App\Users\Controller;
4
5
use App\Controller\BaseController;
6
use App\Users\Request\AuthUserRequest;
7
use App\Users\Service\AuthService;
8
use Symfony\Component\HttpFoundation\JsonResponse;
9
use Symfony\Component\Routing\Annotation\Route;
10
11
class AuthController extends BaseController
12
{
13
    /**
14
     * Endpoint action to get Access Token for authentication.
15
     *
16
     * @Route("/api/auth/login", methods={"POST", "OPTIONS"});
17
     *
18
     * @param $authUserRequest AuthUserRequest
19
     * @param $authService AuthService
20
     *
21
     * @throws \LogicException
22
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
23
     *
24
     * @return JsonResponse
25
     */
26 4
    public function login(AuthUserRequest $authUserRequest, AuthService $authService)
27
    {
28 4
        $this->denyAccessUnlessGranted('IS_AUTHENTICATED_ANONYMOUSLY');
29
30 4
        $apiToken = $authService->getTokenByRequest($authUserRequest);
31
32 2
        return $this->response([
33 2
            'api_token' => $apiToken->getToken(),
34 2
            'user_id' => $apiToken->getUser()->getId(),
35
        ]);
36
    }
37
}
38