Test Failed
Pull Request — master (#660)
by butschster
09:30
created

LogBroadcast::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Broadcasting\Driver;
6
7
use Psr\Log\LoggerInterface;
8
use Psr\Log\LogLevel;
9
10
final class LogBroadcast extends AbstractBroadcast
11
{
12
    private LoggerInterface $logger;
13
    private string $level;
14
15
    public function __construct(LoggerInterface $logger, string $level = LogLevel::INFO)
16
    {
17
        $this->logger = $logger;
18
        $this->level = $level;
19
    }
20
21
    public function publish($topics, $messages): void
22
    {
23
        $topics = implode(', ', $this->formatTopics($this->toArray($topics)));
24
25
        /** @var string $message */
26
        foreach ($this->toArray($messages) as $message) {
27
            assert(\is_string($message), 'Message argument must be a type of string');
28
            $this->logger->log($this->level, 'Broadcasting on channels [' . $topics . '] with payload: ' . $message);
29
        }
30
    }
31
}
32