Passed
Push — master ( 4df8b5...b243c4 )
by Dmitriy
02:33 queued 01:04
created

AuthController   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 87
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 87
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A logout() 0 5 1
A login() 0 10 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Auth;
6
7
use App\User\UserRequest;
8
use App\User\UserService;
9
use OpenApi\Annotations as OA;
0 ignored issues
show
Bug introduced by
The type OpenApi\Annotations 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...
10
use Psr\Http\Message\ResponseInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ResponseInterface 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...
11
use Yiisoft\DataResponse\DataResponseFactoryInterface as ResponseFactory;
0 ignored issues
show
Bug introduced by
The type Yiisoft\DataResponse\DataResponseFactoryInterface 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...
12
13
/**
14
 * @OA\Tag(
15
 *     name="auth",
16
 *     description="Authentication"
17
 * )
18
 *
19
 * @OA\SecurityScheme(
20
 *     securityScheme="ApiKey",
21
 *     type="apiKey",
22
 *     in="header",
23
 *     name="X-Api-Key"
24
 * )
25
 */
26
final class AuthController
27
{
28
    private ResponseFactory $responseFactory;
29
    private UserService $userService;
30
31
    public function __construct(
32
        ResponseFactory $responseFactory,
33
        UserService $userService
34
    ) {
35
        $this->responseFactory = $responseFactory;
36
        $this->userService = $userService;
37
    }
38
39
    /**
40
     * @OA\Post(
41
     *     tags={"auth"},
42
     *     path="/auth/",
43
     *     summary="Authenticate by params",
44
     *     description="",
45
     *     @OA\Response(
46
     *          response="200",
47
     *          description="Success",
48
     *          @OA\JsonContent(
49
     *              allOf={
50
     *                  @OA\Schema(ref="#/components/schemas/Response"),
51
     *                  @OA\Schema(
52
     *                      @OA\Property(
53
     *                          property="data",
54
     *                          type="object",
55
     *                          @OA\Property(property="token", format="string", example="uap4X5Bd7078lxIFvxAflcGAa5D95iSSZkNjg3XFrE2EBRBlbj"),
56
     *                      ),
57
     *                  ),
58
     *              },
59
     *          )
60
     *    ),
61
     *    @OA\Response(
62
     *          response="400",
63
     *          description="Bad request",
64
     *          @OA\JsonContent(ref="#/components/schemas/BadResponse")
65
     *     ),
66
     *     @OA\RequestBody(
67
     *          required=true,
68
     *          @OA\MediaType(
69
     *              mediaType="application/json",
70
     *              @OA\Schema(ref="#/components/schemas/AuthRequest"),
71
     *          ),
72
     *     ),
73
     * )
74
     */
75
    public function login(AuthRequest $request): ResponseInterface
76
    {
77
        return $this->responseFactory->createResponse(
78
            [
79
                'token' => $this->userService
80
                    ->login(
0 ignored issues
show
Bug introduced by
The method login() does not exist on App\User\UserService. ( Ignorable by Annotation )

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

80
                    ->/** @scrutinizer ignore-call */ login(

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
81
                        $request->getLogin(),
82
                        $request->getPassword()
83
                    )
84
                    ->getToken(),
85
            ]
86
        );
87
    }
88
89
    /**
90
     * @OA\Post(
91
     *     tags={"auth"},
92
     *     path="/logout/",
93
     *     summary="Logout",
94
     *     description="",
95
     *     security={{"ApiKey": {}}},
96
     *     @OA\Response(
97
     *          response="200",
98
     *          description="Success",
99
     *          @OA\JsonContent(ref="#/components/schemas/Response")
100
     *    ),
101
     *    @OA\Response(
102
     *          response="400",
103
     *          description="Bad request",
104
     *          @OA\JsonContent(ref="#/components/schemas/BadResponse")
105
     *     ),
106
     * )
107
     */
108
    public function logout(UserRequest $request): ResponseInterface
109
    {
110
        $this->userService->logout($request->getUser());
0 ignored issues
show
Bug introduced by
The method logout() does not exist on App\User\UserService. ( Ignorable by Annotation )

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

110
        $this->userService->/** @scrutinizer ignore-call */ 
111
                            logout($request->getUser());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
111
112
        return $this->responseFactory->createResponse();
113
    }
114
}
115