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

LoggerDecorator::log()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
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