Passed
Push — main ( a4880b...68f5b1 )
by Zsolt
09:25
created

PayloadResponder::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Http;
6
7
use DarkMatter\Http\Response;
8
use DarkMatter\Payload\Payload;
9
use DarkMatter\Payload\Status;
10
11
use DarkMatter\Responder\HtmlResponder;
12
13
14
/**
15
 * @property string $view
16
 */
17
18
class PayloadResponder extends HtmlResponder
19
{
20
    /**
21
     * Generates a payload response.
22
     *
23
     * @param Payload $payload
24
     * @return Response
25
     */
26
    public function __invoke(Payload $payload): Response
27
    {
28
        $payloadResult = $payload->getResult();
29
30
        if ($payload->getStatus() === Status::FOUND) {
31
            return $this->found($payloadResult);
32
        }
33
34
        return $this->error([$payloadResult['error'] ?? 'Unknown Error']);
35
    }
36
37
38
39
40
41
42
43
44
}
45