Test Failed
Pull Request — master (#20)
by Alexander
04:07 queued 01:32
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\Service\UserService;
0 ignored issues
show
Bug introduced by
The type App\Service\UserService was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
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(),
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