Passed
Push — master ( 9aca0b...f2b626 )
by David
02:10
created

Hermes::dispatchJson()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace TheAentMachine;
3
4
use Symfony\Component\Process\Process;
5
6
class Hermes
7
{
8
    public static function dispatch(string $event, ?string $payload = null): void
9
    {
10
        $command = ['hermes', 'dispatch', $event];
11
        if (!empty($payload)) {
12
            $command[] = $payload;
13
        }
14
15
        $process = new Process($command);
16
        $process->enableOutput();
17
        $process->setTty(true);
18
19
        $process->mustRun();
20
    }
21
22
    public static function dispatchJson(string $event, array $payload): void
23
    {
24
        self::dispatch($event, \json_encode($payload));
25
    }
26
27
    public static function reply(string $event, ?string $payload = null): void
28
    {
29
        $command = ['hermes', 'reply', $event];
30
        if (!empty($payload)) {
31
            $command[] = $payload;
32
        }
33
34
        $process = new Process($command);
35
        $process->enableOutput();
36
        $process->setTty(true);
37
38
        $process->mustRun();
39
    }
40
41
    public static function replyJson(string $event, array $payload): void
42
    {
43
        self::reply($event, \json_encode($payload));
44
    }
45
}
46