Passed
Push — master ( 83447c...2e155a )
by Mauro
02:41
created

CreateUser   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 82.61 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 9 12 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 App\Controller\User;
4
5
use Slim\Http\Request;
6
use Slim\Http\Response;
7
8
/**
9
 * Create User Controller.
10
 */
11 View Code Duplication
class CreateUser extends BaseUser
12
{
13
    /**
14
     * Create a user.
15
     *
16
     * @param Request $request
17
     * @param Response $response
18
     * @param array $args
19
     * @return Response
20
     */
21
    public function __invoke($request, $response, $args)
22
    {
23
        $this->setParams($request, $response, $args);
24
        $input = $this->getInput();
25
        $result = $this->getUserService()->createUser($input);
0 ignored issues
show
Bug introduced by
It seems like $input defined by $this->getInput() on line 24 can also be of type null or object; however, App\Service\UserService::createUser() does only seem to accept array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
26
27
//        $client = new \Predis\Client();
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
28
//        $key = 'api-rest-slimphp:user:'.$result->id;
29
//        $client->set($key, json_encode($result));
30
31
        return $this->jsonResponse('success', $result, 201);
32
    }
33
}
34