AbstractJsonEvent   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A executeEvent() 0 11 3
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