Passed
Push — master ( 083961...8c32c7 )
by butschster
08:05 queued 12s
created

AbstractBroadcast::formatTopics()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Broadcasting\Driver;
6
7
use Spiral\Broadcasting\BroadcastInterface;
8
9
abstract class AbstractBroadcast implements BroadcastInterface
10
{
11
    /**
12
     * Format the topic array into an array of strings.
13
     *
14
     * @param string[]|\Stringable[] $topics
15
     * @return string[]
16
     */
17 5
    protected function formatTopics(array $topics): array
18
    {
19 5
        return array_map(fn ($topic) => (string)$topic, $topics);
20
    }
21
22
    /**
23
     * @template T of mixed
24
     * @param iterable<T>|T $entries
25
     * @return array<T>
26
     */
27 5
    protected function toArray($entries): array
28
    {
29
        switch (true) {
30 5
            case \is_array($entries):
31 3
                return $entries;
32
33 4
            case $entries instanceof \Traversable:
34
                return \iterator_to_array($entries, false);
35
36
            default:
37 4
                return [$entries];
38
        }
39
    }
40
}
41