Passed
Branch main (0a6531)
by Zsolt
18:15 queued 08:15
created

JsonDemoAction::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 18
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Action;
6
7
use DarkMatter\Action\JsonAction;
8
use DarkMatter\Http\Response;
9
10
/**
11
 * Class JsonDemoAction
12
 *
13
 * This is an example of a JsonAction. In every action of this type you have access to the JsonResponder object
14
 * which can be used to send JSON encoded data back to the clint.
15
 *
16
 * @package App\Actions
17
 */
18
class JsonDemoAction extends JsonAction
19
{
20
    public function __invoke(array $arguments = []): Response
21
    {
22
        // At this point you would normally fetch some data from a domain or service:
23
        $customers = [
24
            [
25
                'id' => 1,
26
                'firstname' => 'Mikka',
27
                'lastname' => 'Makka',
28
            ],
29
            [
30
                'id' => 2,
31
                'firstname' => 'Zorro',
32
                'lastname' => 'Morro',
33
            ]
34
        ];
35
36
        // The data than automatically converted to JSON and send back to the client:
37
        return $this->responder->found($customers);
38
    }
39
}
40