Test Failed
Pull Request — master (#20)
by Alexander
04:17 queued 01:35
created

AuthController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A logout() 0 4 1
A login() 0 8 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Auth;
6
7
use App\User\UserService;
8
use Psr\Http\Message\ResponseInterface;
9
use Yiisoft\DataResponse\DataResponseFactoryInterface as ResponseFactory;
10
11
/**
12
 * @OA\Tag(
13
 *     name="auth",
14
 *     description="Authentication"
15
 * )
16
 */
17
final class AuthController
18
{
19
    private ResponseFactory $responseFactory;
20
    private UserService $userService;
21
22
    public function __construct(
23
        ResponseFactory $responseFactory,
24
        UserService $userService
25
    ) {
26
        $this->responseFactory = $responseFactory;
27
        $this->userService = $userService;
28
    }
29
30
    /**
31
     * @OA\Post(
32
     *     tags={"auth"},
33
     *     path="/auth",
34
     *     summary="Authenticate by token",
35
     *     description="",
36
     *     @OA\Response(response="200", description="Success")
37
     * )
38
     */
39
    public function login(AuthRequest $request): ResponseInterface
40
    {
41
        return $this->responseFactory->createResponse(
42
            [
43
                'token' => $this->userService->login(
44
                    $request->getLogin(),
45
                    $request->getPassword()
46
                )->getToken(),
0 ignored issues
show
Bug introduced by
The method getToken() does not exist on Yiisoft\Auth\IdentityInterface. It seems like you code against a sub-type of Yiisoft\Auth\IdentityInterface such as App\User\User. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

46
                )->/** @scrutinizer ignore-call */ getToken(),
Loading history...
47
            ]
48
        );
49
    }
50
51
    /**
52
     * @OA\Post(
53
     *     tags={"auth"},
54
     *     path="/logout",
55
     *     summary="Logout",
56
     *     description="",
57
     *     @OA\Response(response="200", description="Success")
58
     * )
59
     */
60
    public function logout(): ResponseInterface
61
    {
62
        $this->userService->logout();
63
        return $this->responseFactory->createResponse();
64
    }
65
}
66