Passed
Pull Request — master (#572)
by Dmitriy
01:31
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;
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...
12
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...
13
use Yiisoft\Router\CurrentRoute;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Router\CurrentRoute 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...
14
15
/**
16
 * @OA\Tag(
17
 *     name="user",
18
 *     description="Users"
19
 * )
20
 *
21
 * @OA\Get(
22
 *     tags={"user"},
23
 *     path="/{locale}/users/{id}",
24
 *     summary="Returns a user with a given ID",
25
 *     description="",
26
 *     security={{"ApiKey": {}}},
27
 *     @OA\Parameter(
28
 *          @OA\Schema(type="string", example="en"),
29
 *          in="path",
30
 *          name="locale",
31
 *          parameter="locale"
32
 *     ),
33
 *     @OA\Parameter(
34
 *          @OA\Schema(type="int", example="2"),
35
 *          in="path",
36
 *          name="id",
37
 *          parameter="id"
38
 *     ),
39
 *     @OA\Response(
40
 *          response="200",
41
 *          description="Success",
42
 *          @OA\JsonContent(
43
 *              allOf={
44
 *                  @OA\Schema(ref="#/components/schemas/Response"),
45
 *                  @OA\Schema(
46
 *                      @OA\Property(
47
 *                          property="data",
48
 *                          type="object",
49
 *                          @OA\Property(
50
 *                              property="user",
51
 *                              type="object",
52
 *                              ref="#/components/schemas/UserViewResponse"
53
 *                          ),
54
 *                      ),
55
 *                  ),
56
 *              },
57
 *          )
58
 *    ),
59
 * )
60
 */
61
final class Action
62
{
63
    public function __invoke(
64
        CurrentRoute $currentRoute,
65
        UserRepository $userRepository,
66
        ResponseFactory $responseFactory,
67
    ): ResponseInterface {
68
        /**
69
         * @var User $user
70
         */
71
        $user = $userRepository->findByPK($currentRoute->getArgument('id'));
72
        if ($user === null) {
73
            throw new NotFoundException();
74
        }
75
76
        return $responseFactory->create($user);
77
    }
78
}
79