Passed
Pull Request — master (#660)
by butschster
07:40
created

LogBroadcast   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 22
ccs 9
cts 9
cp 1
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 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
10
final class LogBroadcast extends AbstractBroadcast
11
{
12
    private LoggerInterface $logger;
13
14 5
    public function __construct(LoggerInterface $logger)
15
    {
16 5
        $this->logger = $logger;
17
    }
18
19 1
    public function authorize(ServerRequestInterface $request): bool
20
    {
21 1
        return true;
22
    }
23
24 4
    public function publish($topics, $messages): void
25
    {
26 4
        $topics = implode(', ', $this->formatTopics($this->toArray($topics)));
27
28
        /** @var string $message */
29 4
        foreach ($this->toArray($messages) as $message) {
30 4
            assert(\is_string($message), 'Message argument must be a type of string');
31 4
            $this->logger->info('Broadcasting on channels [' . $topics . '] with payload: ' . $message);
32
        }
33
    }
34
}
35