Passed
Pull Request — master (#572)
by Alexander
02:59 queued 01:28
created

Action   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 17
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure\IO\Http\Auth\PostLogin;
6
7
use App\Application\User\Service\UserService;
8
use App\Infrastructure\IO\Http\Auth\PostLogin\Request\Request;
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;
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
 * @OA\Post(
27
 *     tags={"auth"},
28
 *     path="/{locale}/auth/login",
29
 *     summary="Authenticate by params",
30
 *     description="",
31
 *     @OA\Parameter(
32
 *          @OA\Schema(type="string", example="en"),
33
 *          in="path",
34
 *          name="locale",
35
 *          parameter="locale"
36
 *     ),
37
 *     @OA\Response(
38
 *          response="200",
39
 *          description="Success",
40
 *          @OA\JsonContent(
41
 *              allOf={
42
 *                  @OA\Schema(ref="#/components/schemas/Response"),
43
 *                  @OA\Schema(
44
 *                      @OA\Property(
45
 *                          property="data",
46
 *                          type="object",
47
 *                          @OA\Property(property="token", format="string",
48
 *     example="uap4X5Bd7078lxIFvxAflcGAa5D95iSSZkNjg3XFrE2EBRBlbj"),
49
 *                      ),
50
 *                  ),
51
 *              },
52
 *          )
53
 *    ),
54
 *    @OA\Response(
55
 *          response="400",
56
 *          description="Bad request",
57
 *          @OA\JsonContent(ref="#/components/schemas/BadResponse")
58
 *     ),
59
 *     @OA\RequestBody(
60
 *          required=true,
61
 *          @OA\MediaType(
62
 *              mediaType="application/json",
63
 *              @OA\Schema(ref="#/components/schemas/LoginRequest"),
64
 *          ),
65
 *     ),
66
 * )
67
 */
68
final class Action
69
{
70
    public function __construct(
71
        private DataResponseFactoryInterface $responseFactory,
72
        private UserService $userService,
73
    ) {
74
    }
75
76
    public function __invoke(Request $request): ResponseInterface
77
    {
78
        $identity = $this->userService->login(
79
            $request->getLogin(),
80
            $request->getPassword()
81
        );
82
83
        return $this->responseFactory->createResponse([
84
            'token' => $identity->getToken(),
85
        ]);
86
    }
87
}
88