Completed
Pull Request — master (#377)
by
unknown
06:50
created

ResponseResolver::resolve()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
namespace Mpociot\ApiDoc\Tools;
4
5
use Illuminate\Routing\Route;
6
use Mpociot\ApiDoc\Tools\ResponseStrategies\ResponseTagStrategy;
7
use Mpociot\ApiDoc\Tools\ResponseStrategies\ResponseCallStrategy;
8
use Mpociot\ApiDoc\Tools\ResponseStrategies\TransformerTagsStrategy;
9
10
class ResponseResolver
11
{
12
    public static $strategies = [
13
        ResponseTagStrategy::class,
14
        TransformerTagsStrategy::class,
15
        ResponseCallStrategy::class,
16
    ];
17
18
    /**
19
     * @var Route
20
     */
21
    private $route;
22
23
    public function __construct(Route $route)
24
    {
25
        $this->route = $route;
26
    }
27
28
    private function resolve(array $tags, array $rulesToApply)
29
    {
30
        $response = null;
0 ignored issues
show
Unused Code introduced by
$response is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
31
        foreach (static::$strategies as $strategy) {
32
            $strategy = new $strategy();
33
            $response = $strategy($this->route, $tags, $rulesToApply);
34
            if (! is_null($response)) {
35
                return $this->getResponseContent($response);
36
            }
37
        }
38
    }
39
40
    public static function getResponse($route, $tags, $rulesToApply)
41
    {
42
        return (new static($route))->resolve($tags, $rulesToApply);
43
    }
44
45
    /**
46
     * @param $response
47
     *
48
     * @return mixed
49
     */
50
    private function getResponseContent($response)
51
    {
52
        return $response ? $response->getContent() : '';
53
    }
54
}
55