UserGetByIdAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 56
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 56
loc 56
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A __invoke() 6 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Finder\Http\Actions;
4
5
use Finder\Http\Resources\UserPlainResource;
6
use Population\Manipule\Managers\UserManager;
7
use Illuminate\Contracts\Routing\ResponseFactory;
8
use Illuminate\Http\JsonResponse;
9
use Illuminate\Http\Response;
10
11
/**
12
 * Class UserGetByIdAction.
13
 *
14
 * @package Finder\Http\Actions
15
 */
16 View Code Duplication
class UserGetByIdAction
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    /**
19
     * @var ResponseFactory
20
     */
21
    private $responseFactory;
22
23
    /**
24
     * @var UserManager
25
     */
26
    private $userManager;
27
28
    /**
29
     * UserGetByIdAction constructor.
30
     *
31
     * @param ResponseFactory $responseFactory
32
     * @param UserManager     $userManager
33
     */
34
    public function __construct(ResponseFactory $responseFactory, UserManager $userManager)
35
    {
36
        $this->responseFactory = $responseFactory;
37
        $this->userManager = $userManager;
38
    }
39
40
    /**
41
     * @apiVersion        1.0.0
42
     * @api               {get} /v1/users/:user_id Get
43
     * @apiName           Get
44
     * @apiGroup          Users
45
     * @apiHeader         {String} Accept application/json
46
     * @apiParam          {Integer{1...N}='me'} :user_id Unique resource ID.
47
     * @apiSuccessExample {json} Success-Response:
48
     * HTTP/1.1 20O OK
49
     * {
50
     *     "id": 1,
51
     *     "name": "username",
52
     *     "email": "[email protected]",
53
     *     "role": "Customer",
54
     *     "created_at": "2099-12-31T23:59:59+00:00",
55
     *     "updated_at": "2099-12-31T23:59:59+00:00"
56
     * }
57
     */
58
59
    /**
60
     * Get a user.
61
     *
62
     * @param  mixed $id
63
     * @return JsonResponse
64
     */
65
    public function __invoke($id): JsonResponse
66
    {
67
        $user = $this->userManager->getById((int) $id);
68
69
        return $this->responseFactory->json(new UserPlainResource($user), Response::HTTP_OK);
70
    }
71
}
72