Passed
Push — main ( f0ef6e...5d2f0b )
by Daniel
13:27
created

IoFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 52
ccs 14
cts 14
cp 1
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A createFfmpegTranscoder() 0 9 1
A createSimpleFileStreamable() 0 4 1
A createTranscodingStreamable() 0 6 1
A __construct() 0 6 1
A createPumpStream() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Component\Io;
6
7
use Closure;
8
use GuzzleHttp\Psr7\PumpStream;
9
use Nyholm\Psr7\Factory\Psr17Factory;
10
use Psr\Http\Message\StreamInterface;
11
use Psr\Log\LoggerInterface;
12
use Uxmp\Core\Component\Config\ConfigProviderInterface;
13
use Uxmp\Core\Component\Io\Lib\PopenWrapperInterface;
14
use Uxmp\Core\Component\Io\Transcoder\FfmpegTranscoder;
15
use Uxmp\Core\Component\Io\Transcoder\TranscoderInterface;
16
use Uxmp\Core\Component\Io\Transcoder\TranscodingHandler;
17
18
final class IoFactory implements IoFactoryInterface
19
{
20 4
    public function __construct(
21
        private readonly Psr17Factory $psr17Factory,
22
        private readonly ConfigProviderInterface $configProvider,
23
        private readonly PopenWrapperInterface $popenWrapper,
24
        private readonly LoggerInterface $logger,
25
    ) {
26
    }
27
28 1
    public function createSimpleFileStreamable(): StreamableInterface
29
    {
30 1
        return new SimpleFileStreamable(
31 1
            $this->psr17Factory
32
        );
33
    }
34
35 1
    public function createTranscodingStreamable(
36
        Transcoder\TranscoderInterface $transcoder
37
    ): StreamableInterface {
38 1
        return new TranscodingStreamable(
39
            $this,
40
            $transcoder
41
        );
42
    }
43
44 1
    public function createPumpStream(
45
        TranscoderInterface $transcoder
46
    ): StreamInterface {
47
        /** @var callable $handler */
48 1
        $handler = new TranscodingHandler(
49 1
            $this->logger,
50
            $transcoder
51
        );
52
53 1
        return new PumpStream($handler);
54
    }
55
56
    /**
57
     * Creates a ffmpeg transcoder
58
     *
59
     * If the given transcoding options aren't allowed, the default config will be used
60
     */
61 1
    public function createFfmpegTranscoder(
62
        string $codec,
63
        int $bitrate,
64
    ): Transcoder\TranscoderInterface {
65 1
        return new FfmpegTranscoder(
66 1
            $this->configProvider,
67 1
            $this->popenWrapper,
68
            $codec,
69
            $bitrate,
70
        );
71
    }
72
}
73