Response::viewWithPayload()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace BrightComponents\Common\Macros;
4
5
use Illuminate\Support\Facades\Response as ResponseFactory;
6
use BrightComponents\Common\Payloads\Contracts\PayloadContract;
7
8
class Response
9
{
10
    /**
11
     * Response macro to send a json response based on a domain payload.
12
     *
13
     * @return mixed
14
     */
15
    public function jsonWithPayload()
16
    {
17
        return function (PayloadContract $payload) {
18
            return ResponseFactory::json($payload, $payload->getStatus());
0 ignored issues
show
Documentation introduced by
$payload is of type object<BrightComponents\...tracts\PayloadContract>, but the function expects a string|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
19
        };
20
    }
21
22
    /**
23
     * Response macro to send a response based on a payload.
24
     *
25
     * @return mixed
26
     */
27
    public function viewWithPayload()
28
    {
29
        return function (string $view, PayloadContract $payload, string $key = 'payload') {
30
            return ResponseFactory::view($view, [$key => $payload->getUnwrappedOutput()], $payload->getStatus());
31
        };
32
    }
33
}
34