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

JsonDemoAction   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 1

1 Method

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