AuthController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
rs 10
c 1
b 0
f 0
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\Attributes as OA;
0 ignored issues
show
Bug introduced by
The type OpenApi\Attributes 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
#[OA\Tag(name: 'auth', description: 'Authentication')]
14
#[OA\SecurityScheme(securityScheme: 'ApiKey', type: 'apiKey', name: 'X-Api-Key', in: 'header')]
15
final class AuthController
16
{
17
    private ResponseFactory $responseFactory;
18
    private UserService $userService;
19
20
    public function __construct(
21
        ResponseFactory $responseFactory,
22
        UserService $userService
23
    ) {
24
        $this->responseFactory = $responseFactory;
25
        $this->userService = $userService;
26
    }
27
28
    #[OA\Post(
29
        path: '/auth/',
30
        description: '',
31
        summary: 'Authenticate by params',
32
        requestBody: new OA\RequestBody(required: true, content: new OA\JsonContent(
33
            allOf: [
34
                new OA\Schema(ref: '#/components/schemas/AuthRequest'),
35
            ]
36
        )),
37
        tags: ['auth'],
38
        responses: [
39
            new OA\Response(
40
                response: '200',
41
                description: 'Success',
42
                content: new OA\JsonContent(
43
                    allOf: [
44
                        new OA\Schema(ref: '#/components/schemas/Response'),
45
                        new OA\Schema(properties: [
46
                            new OA\Property(
47
                                property: 'data',
48
                                properties: [
49
                                    new OA\Property(property: 'token', type: 'string', example: 'uap4X5Bd7078lxIFvxAflcGAa5D95iSSZkNjg3XFrE2EBRBlbj'),
50
                                ],
51
                                type: 'object'
52
                            ),
53
                        ]),
54
                    ]
55
                )
56
            ),
57
            new OA\Response(
58
                response: '400',
59
                description: 'Bad request',
60
                content: new OA\JsonContent(ref:  '#/components/schemas/BadResponse')
61
            ),
62
        ]
63
    )]
64
    public function login(AuthRequest $request): ResponseInterface
65
    {
66
        return $this->responseFactory->createResponse(
67
            [
68
                'token' => $this->userService
69
                    ->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

69
                    ->/** @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...
70
                        $request->getLogin(),
71
                        $request->getPassword()
72
                    )
73
                    ->getToken(),
74
            ]
75
        );
76
    }
77
78
    #[OA\Post(
79
        path: '/logout/',
80
        description: '',
81
        summary: 'Logout',
82
        security: [new OA\SecurityScheme(ref: '#/components/securitySchemes/ApiKey')],
83
        tags: ['auth'],
84
        responses: [
85
            new OA\Response(
86
                response: '200',
87
                description: 'Success',
88
                content: new OA\JsonContent(ref:  '#/components/schemas/Response')
89
            ),
90
            new OA\Response(
91
                response: '400',
92
                description: 'Bad request',
93
                content: new OA\JsonContent(ref:  '#/components/schemas/BadResponse')
94
            ),
95
        ]
96
    )]
97
    public function logout(UserRequest $request): ResponseInterface
98
    {
99
        $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

99
        $this->userService->/** @scrutinizer ignore-call */ 
100
                            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...
100
101
        return $this->responseFactory->createResponse();
102
    }
103
}
104