Passed
Pull Request — master (#87)
by Dmitriy
02:45
created

Action::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 1
rs 10
c 1
b 0
f 0
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;
10
use Psr\Http\Message\ResponseInterface;
11
use Yiisoft\DataResponse\DataResponseFactoryInterface;
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="/auth/login",
29
 *     summary="Authenticate by params",
30
 *     description="",
31
 *     @OA\Response(
32
 *          response="200",
33
 *          description="Success",
34
 *          @OA\JsonContent(
35
 *              allOf={
36
 *                  @OA\Schema(ref="#/components/schemas/Response"),
37
 *                  @OA\Schema(
38
 *                      @OA\Property(
39
 *                          property="data",
40
 *                          type="object",
41
 *                          @OA\Property(property="token", format="string",
42
 *     example="uap4X5Bd7078lxIFvxAflcGAa5D95iSSZkNjg3XFrE2EBRBlbj"),
43
 *                      ),
44
 *                  ),
45
 *              },
46
 *          )
47
 *    ),
48
 *    @OA\Response(
49
 *          response="400",
50
 *          description="Bad request",
51
 *          @OA\JsonContent(ref="#/components/schemas/BadResponse")
52
 *     ),
53
 *     @OA\RequestBody(
54
 *          required=true,
55
 *          @OA\MediaType(
56
 *              mediaType="application/json",
57
 *              @OA\Schema(ref="#/components/schemas/LoginRequest"),
58
 *          ),
59
 *     ),
60
 * )
61
 */
62
final class Action
63
{
64
    public function __construct(
65
        private DataResponseFactoryInterface $responseFactory,
66
        private UserService $userService,
67
    ) {
68
    }
69
70 1
    public function __invoke(Request $request): ResponseInterface
71
    {
72 1
        $identity = $this->userService->login(
73 1
            $request->getLogin(),
74 1
            $request->getPassword()
75
        );
76
77 1
        return $this->responseFactory->createResponse([
78 1
            'token' => $identity->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\Application\User\Entity\User. ( Ignorable by Annotation )

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

78
            'token' => $identity->/** @scrutinizer ignore-call */ getToken(),
Loading history...
79
        ]);
80
    }
81
}
82