Completed
Pull Request — master (#26)
by Valentyn
02:41
created

AuthController   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 53
c 0
b 0
f 0
wmc 1
lcom 0
cbo 3
ccs 4
cts 4
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A login() 0 8 1
1
<?php
2
3
namespace App\Users\Controller;
4
5
use App\Controller\ControllerInterface;
6
use App\Users\Request\AuthUserRequest;
7
use App\Users\Service\AuthService;
8
use FOS\RestBundle\Controller\FOSRestController;
9
use Swagger\Annotations as SWG;
10
use Symfony\Component\Routing\Annotation\Route;
11
use Nelmio\ApiDocBundle\Annotation\Model;
12
13
class AuthController extends FOSRestController implements ControllerInterface
14
{
15
    /**
16
     * Endpoint action to get Access Token for authentication.
17
     *
18
     * @Route("/api/auth/login", methods={"POST"});
19
     * @SWG\Parameter(
20
     *      name="credentials",
21
     *      in="formData",
22
     *      type="string",
23
     *      description="Credentials",
24
     *      required=true,
25
     *      @SWG\Schema(
26
     *          type="object",
27
     *          example={"username": "username", "password": "password"}
28
     *      )
29
     *  )
30
     * @SWG\Response(
31
     *      response=200,
32
     *      description="API Token for user",
33
     *      @SWG\Schema(
34
     *          type="object",
35
     *          example={"api_token": "_api_token_"},
36
     *          @SWG\Property(property="api_token", type="string", description="Api Access Token"),
37
     *      ),
38
     *  )
39
     * @SWG\Response(
40
     *      response=400,
41
     *      description="Bad Request",
42
     *      @SWG\Schema(
43
     *          type="object",
44
     *          example={"message": "message", "errors": "array of errors"},
45
     *          @SWG\Property(property="message", type="integer", description="Error description"),
46
     *          @SWG\Property(property="errors", type="array", description="Errors list", @SWG\Items),
47
     *      ),
48
     *  )
49
     * @SWG\Tag(name="Authentication")
50
     *
51
     * @throws \LogicException
52
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
53
     * @param $authUserRequest AuthUserRequest
54
     * @param $authService AuthService
55
     * @return array
56
     */
57 3
    public function login(AuthUserRequest $authUserRequest, AuthService $authService)
58
    {
59 3
        $this->denyAccessUnlessGranted('IS_AUTHENTICATED_ANONYMOUSLY');
60
61 3
        $apiToken = $authService->getTokenByRequest($authUserRequest);
62
63 1
        return ['api_token' => $apiToken->getToken()];
64
    }
65
}