Passed
Pull Request — master (#225)
by Dmitriy
02:30
created

LoggerDecorator   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A log() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Debug\DebugServer;
6
7
use Psr\Log\LoggerInterface;
8
use Psr\Log\LoggerTrait;
9
use Stringable;
10
use Yiisoft\VarDumper\VarDumper;
11
12
final class LoggerDecorator implements LoggerInterface
13
{
14
    use LoggerTrait;
15
16
    public Connection $connection;
17
18
    public function __construct(private LoggerInterface $decorated)
19
    {
20
        $this->connection = Connection::create();
21
    }
22
23
    public function log($level, Stringable|string $message, array $context = []): void
24
    {
25
        $this->connection->broadcast(
26
            Connection::MESSAGE_TYPE_LOGGER,
27
            VarDumper::create(['message' => $message, 'context' => $context])->asJson(false, 1)
28
        );
29
        $this->decorated->log($level, $message, $context);
30
    }
31
}
32