STDIOSubscriber   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getSubscribedEvents() 0 6 1
A onDNSQueried() 0 3 1
A onDNSQueryFailed() 0 3 1
A onDNSQueryProfiled() 0 3 1
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