Passed
Push — master ( cf066d...0d7181 )
by Anton
02:03
created

Response::toHtml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of Laravel Sense.
5
 *
6
 * (c) Anton Komarev <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Cog\Laravel\Sense\Http\Controllers\Requests\Get;
15
16
use Illuminate\Contracts\Support\Responsable;
17
18
class Response implements Responsable
19
{
20
    /**
21
     * @var \Cog\Laravel\Sense\RequestSummary\Models\RequestSummary
22
     */
23
    private $requestSummary;
24
25
    /**
26
     * @var \Cog\Laravel\Sense\StatementSummary\Models\StatementSummary[]
27
     */
28
    private $statementSummaries;
29
30
    public function __construct($requestSummary, $statementSummaries)
31
    {
32
        $this->requestSummary = $requestSummary;
33
        $this->statementSummaries = $statementSummaries;
34
    }
35
36
    public function toResponse($request)
37
    {
38
        return $request->wantsJson() ? $this->toJson() : $this->toHtml();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $request->wantsJs...son() : $this->toHtml() returns the type Illuminate\View\View|array which is incompatible with the return type mandated by Illuminate\Contracts\Sup...sponsable::toResponse() of Illuminate\Http\Response.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
39
    }
40
41
    private function toHtml()
42
    {
43
        return view('sense::requests.view', [
44
            'requestSummary' => $this->requestSummary,
45
            'statementSummaries' => $this->statementSummaries,
46
        ]);
47
    }
48
49
    private function toJson()
50
    {
51
        return [];
52
    }
53
}
54