Test Failed
Pull Request — master (#660)
by butschster
08:23
created

LogBroadcast   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A authorize() 0 3 1
A publish() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Broadcasting\Driver;
6
7
use Psr\Http\Message\ServerRequestInterface;
8
use Psr\Log\LoggerInterface;
9
use Psr\Log\LogLevel;
10
11
final class LogBroadcast extends AbstractBroadcast
12
{
13
    private LoggerInterface $logger;
14
    private string $level;
15
16
    public function __construct(LoggerInterface $logger, string $level = LogLevel::INFO)
17
    {
18
        $this->logger = $logger;
19
        $this->level = $level;
20
    }
21
22
    public function authorize(ServerRequestInterface $request): bool
23
    {
24
        return true;
25
    }
26
27
    public function publish($topics, $messages): void
28
    {
29
        $topics = implode(', ', $this->formatTopics($this->toArray($topics)));
30
31
        /** @var string $message */
32
        foreach ($this->toArray($messages) as $message) {
33
            assert(\is_string($message), 'Message argument must be a type of string');
34
            $this->logger->log($this->level, 'Broadcasting on channels [' . $topics . '] with payload: ' . $message);
35
        }
36
    }
37
}
38