AbstractJsonEvent::executeEvent()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace TheAentMachine\Aent\Event;
4
5
abstract class AbstractJsonEvent extends AbstractEvent
6
{
7
    /**
8
     * @param mixed[] $payload
9
     * @return mixed[]|null
10
     */
11
    abstract protected function executeJsonEvent(array $payload): ?array;
12
13
    protected function executeEvent(?string $payload): ?string
14
    {
15
        if ($payload === null) {
16
            throw new \InvalidArgumentException('Empty payload. JSON message expected.');
17
        }
18
        $data = \GuzzleHttp\json_decode($payload, true);
19
        $result = $this->executeJsonEvent($data);
20
        if ($result === null) {
21
            return null;
22
        }
23
        return \GuzzleHttp\json_encode($result);
24
    }
25
}
26