Test Failed
Pull Request — master (#87)
by Dmitriy
02:38
created

Action   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 14 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure\IO\Http\User\GetView;
6
7
use App\Application\Exception\NotFoundException;
8
use App\Application\User\Entity\User;
9
use App\Application\User\Entity\UserRepository;
10
use App\Infrastructure\IO\Http\User\GetView\Response\ResponseFactory;
11
use OpenApi\Annotations as OA;
12
use Psr\Http\Message\ResponseInterface;
13
use Yiisoft\Router\CurrentRoute;
14
15
/**
16
 * @OA\Tag(
17
 *     name="user",
18
 *     description="Users"
19
 * )
20
 *
21
 * @OA\Get(
22
 *     tags={"user"},
23
 *     path="/users/{id}",
24
 *     summary="Returns a user with a given ID",
25
 *     description="",
26
 *     security={{"ApiKey": {}}},
27
 *     @OA\Parameter(
28
 *          @OA\Schema(type="int", example="2"),
29
 *          in="path",
30
 *          name="id",
31
 *          parameter="id"
32
 *     ),
33
 *     @OA\Response(
34
 *          response="200",
35
 *          description="Success",
36
 *          @OA\JsonContent(
37
 *              allOf={
38
 *                  @OA\Schema(ref="#/components/schemas/Response"),
39
 *                  @OA\Schema(
40
 *                      @OA\Property(
41
 *                          property="data",
42
 *                          type="object",
43
 *                          @OA\Property(
44
 *                              property="user",
45
 *                              type="object",
46
 *                              ref="#/components/schemas/UserViewResponse"
47
 *                          ),
48
 *                      ),
49
 *                  ),
50
 *              },
51
 *          )
52
 *    ),
53
 * )
54
 */
55
final class Action
56
{
57
    public function __invoke(
58
        CurrentRoute $currentRoute,
59
        UserRepository $userRepository,
60
        ResponseFactory $responseFactory,
61
    ): ResponseInterface {
62
        /**
63
         * @var User $user
64
         */
65
        $user = $userRepository->findByPK($currentRoute->getArgument('id'));
66
        if ($user === null) {
67
            throw new NotFoundException();
68
        }
69
70
        return $responseFactory->create($user);
71
    }
72
}
73