STDIOSubscriber::onDNSQueryProfiled()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
namespace RemotelyLiving\PHPDNS\Observability\Subscribers;
4
5
use RemotelyLiving\PHPDNS\Observability\Events\DNSQueried;
6
use RemotelyLiving\PHPDNS\Observability\Events\DNSQueryFailed;
7
use RemotelyLiving\PHPDNS\Observability\Events\DNSQueryProfiled;
8
use RemotelyLiving\PHPDNS\Observability\Events\ObservableEventAbstract;
9
use SplFileObject;
10
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
11
12
use function json_encode;
13
14
final class STDIOSubscriber implements EventSubscriberInterface
15
{
16
    public function __construct(private SplFileObject $STDOUT, private SplFileObject $STDERR)
17
    {
18
    }
19
20
    public static function getSubscribedEvents()
21
    {
22
        return [
23
            DNSQueryFailed::getName() => 'onDNSQueryFailed',
24
            DNSQueried::getName() => 'onDNSQueried',
25
            DNSQueryProfiled::getName() => 'onDNSQueryProfiled',
26
        ];
27
    }
28
29
    public function onDNSQueryFailed(ObservableEventAbstract $event): void
30
    {
31
        $this->STDERR->fwrite(json_encode($event, JSON_PRETTY_PRINT) . PHP_EOL);
32
    }
33
34
    public function onDNSQueried(ObservableEventAbstract $event): void
35
    {
36
        $this->STDOUT->fwrite(json_encode($event, JSON_PRETTY_PRINT) . PHP_EOL);
37
    }
38
39
    public function onDNSQueryProfiled(ObservableEventAbstract $event): void
40
    {
41
        $this->STDOUT->fwrite(json_encode($event, JSON_PRETTY_PRINT) . PHP_EOL);
42
    }
43
}
44