Completed
Push — master ( cacde2...cef74a )
by Mauro
01:51
created

UpdateTask   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 12 12 2

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\Task;
4
5
use Slim\Http\Request;
6
use Slim\Http\Response;
7
8
/**
9
 * Update Task Controller.
10
 */
11 View Code Duplication
class UpdateTask extends BaseTask
12
{
13
    /**
14
     * Update a task.
15
     *
16
     * @param Request $request
17
     * @param Response $response
18
     * @param array $args
19
     * @return array
20
     */
21
    public function __invoke($request, $response, $args)
22
    {
23
        try {
24
            $this->setParams($request, $response, $args);
25
            $input = $this->request->getParsedBody();
26
            $result = $this->getTaskService()->updateTask($input, $this->args['id']);
0 ignored issues
show
Bug introduced by
It seems like $input defined by $this->request->getParsedBody() on line 25 can also be of type null or object; however, App\Service\TaskService::updateTask() 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...
27
28
            return $this->jsonResponse('success', $result, 200);
29
        } catch (\Exception $ex) {
30
            return $this->jsonResponse('error', $ex->getMessage(), $ex->getCode());
31
        }
32
    }
33
}
34