UserCreateAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 62
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

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\Request;
10
use Illuminate\Http\Response;
11
12
/**
13
 * Class UserCreateAction.
14
 *
15
 * @package Finder\Http\Actions
16
 */
17 View Code Duplication
class UserCreateAction
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...
18
{
19
    /**
20
     * @var ResponseFactory
21
     */
22
    private $responseFactory;
23
24
    /**
25
     * @var UserManager
26
     */
27
    private $userManager;
28
29
    /**
30
     * UserCreateAction constructor.
31
     *
32
     * @param ResponseFactory $responseFactory
33
     * @param UserManager     $userManager
34
     */
35
    public function __construct(ResponseFactory $responseFactory, UserManager $userManager)
36
    {
37
        $this->responseFactory = $responseFactory;
38
        $this->userManager = $userManager;
39
    }
40
41
    /**
42
     * @apiVersion        1.0.0
43
     * @api               {post} /v1/users Create
44
     * @apiName           Create
45
     * @apiGroup          Users
46
     * @apiHeader         {String} Accept application/json
47
     * @apiHeader         {String} Content-type application/json
48
     * @apiParamExample   {json} Request-Body-Example:
49
     * {
50
     *     "name": "username",
51
     *     "email": "[email protected]",
52
     *     "password": "password"
53
     * }
54
     * @apiSuccessExample {json} Success-Response:
55
     * HTTP/1.1 201 Created
56
     * {
57
     *     "id": 1,
58
     *     "name": "username",
59
     *     "email": "[email protected]",
60
     *     "role": "Customer",
61
     *     "created_at": "2099-12-31T23:59:59+00:00",
62
     *     "updated_at": "2099-12-31T23:59:59+00:00"
63
     * }
64
     */
65
66
    /**
67
     * Create a user.
68
     *
69
     * @param  Request $request
70
     * @return JsonResponse
71
     */
72
    public function __invoke(Request $request): JsonResponse
73
    {
74
        $user = $this->userManager->create($request->all());
75
76
        return $this->responseFactory->json(new UserPlainResource($user), Response::HTTP_CREATED);
77
    }
78
}
79