StreamerFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 2 Features 0
Metric Value
wmc 7
eloc 21
c 3
b 2
f 0
dl 0
loc 46
ccs 19
cts 19
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A createStreamer() 0 27 6
1
<?php
2
3
namespace App\Factories;
4
5
use App\Models\Song;
6
use App\Services\Streamers\DirectStreamerInterface;
7
use App\Services\Streamers\ObjectStorageStreamerInterface;
8
use App\Services\Streamers\StreamerInterface;
9
use App\Services\Streamers\TranscodingStreamerInterface;
10
use App\Services\TranscodingService;
11
12
class StreamerFactory
13
{
14
    private $directStreamer;
15
    private $transcodingStreamer;
16
    private $objectStorageStreamer;
17
    private $transcodingService;
18
19 11
    public function __construct(
20
        DirectStreamerInterface $directStreamer,
21
        TranscodingStreamerInterface $transcodingStreamer,
22
        ObjectStorageStreamerInterface $objectStorageStreamer,
23
        TranscodingService $transcodingService
24
    ) {
25 11
        $this->directStreamer = $directStreamer;
26 11
        $this->transcodingStreamer = $transcodingStreamer;
27 11
        $this->objectStorageStreamer = $objectStorageStreamer;
28 11
        $this->transcodingService = $transcodingService;
29 11
    }
30
31 6
    public function createStreamer(
32
        Song $song,
33
        ?bool $transcode = null,
34
        ?int $bitRate = null,
35
        float $startTime = 0.0
36
    ): StreamerInterface {
37 6
        if ($song->s3_params) {
38 1
            $this->objectStorageStreamer->setSong($song);
39
40 1
            return $this->objectStorageStreamer;
41
        }
42
43 5
        if ($transcode === null && $this->transcodingService->songShouldBeTranscoded($song)) {
44 1
            $transcode = true;
45
        }
46
47 5
        if ($transcode) {
48 2
            $this->transcodingStreamer->setSong($song);
49 2
            $this->transcodingStreamer->setBitRate($bitRate ?: config('koel.streaming.bitrate'));
50 2
            $this->transcodingStreamer->setStartTime($startTime);
51
52 2
            return $this->transcodingStreamer;
53
        }
54
55 3
        $this->directStreamer->setSong($song);
56
57 3
        return $this->directStreamer;
58
    }
59
}
60