Event::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Jaxon\Script\Action;
4
5
use Jaxon\Script\JsExpr;
6
use JsonSerializable;
7
8
class Event implements JsonSerializable
9
{
10
    /**
11
     * The constructor.
12
     *
13
     * @param string $sMode    The event mode: 'jq' or 'js'
14
     * @param string $sName    The event name
15
     * @param JsExpr $xHandler   The event handler
16
     */
17
    public function __construct(private string $sMode,
18
        private string $sName, private JsExpr $xHandler)
19
    {}
20
21
    /**
22
     * Convert this call to array, when converting the response into json.
23
     *
24
     * @return array
25
     */
26
    public function jsonSerialize(): array
27
    {
28
        return [
29
            '_type' => 'event',
30
            '_name' => $this->sName,
31
            'mode' => $this->sMode,
32
            'func' => $this->xHandler->jsonSerialize(),
33
        ];
34
    }
35
}
36