Create::__invoke()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 7
Ratio 100 %

Importance

Changes 0
Metric Value
dl 7
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Controller\Task;
6
7
use Slim\Http\Request;
8
use Slim\Http\Response;
9
10 View Code Duplication
class Create extends Base
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...
11
{
12
    public function __invoke(Request $request, Response $response, array $args): Response
13
    {
14
        $input = $request->getParsedBody();
15
        $task = $this->getTaskService()->create($input);
0 ignored issues
show
Bug introduced by
It seems like $input defined by $request->getParsedBody() on line 14 can also be of type null or object; however, App\Service\TaskService::create() 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...
16
17
        return $this->jsonResponse($response, 'success', $task, 201);
18
    }
19
}
20