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

PayloadResponder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 17
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 9 2
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