Passed
Push — main ( 7dcca1...e70bce )
by Daniel
04:22
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
wmc 5
eloc 15
c 1
b 0
f 0
dl 0
loc 52
ccs 23
cts 23
cp 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Uxmp\Core\Component\Io;
6
7
use GuzzleHttp\Psr7\PumpStream;
8
use Nyholm\Psr7\Factory\Psr17Factory;
9
use Psr\Http\Message\StreamInterface;
10
use Psr\Log\LoggerInterface;
11
use Uxmp\Core\Component\Config\ConfigProviderInterface;
12
use Uxmp\Core\Component\Io\Lib\PopenWrapperInterface;
13
use Uxmp\Core\Component\Io\Transcoder\FfmpegTranscoder;
14
use Uxmp\Core\Component\Io\Transcoder\TranscoderInterface;
15
use Uxmp\Core\Component\Io\Transcoder\TranscodingHandler;
16
17
final readonly class IoFactory implements IoFactoryInterface
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_READONLY, expecting T_CLASS on line 17 at column 6
Loading history...
18
{
19 4
    public function __construct(
20
        private Psr17Factory $psr17Factory,
21
        private ConfigProviderInterface $configProvider,
22
        private PopenWrapperInterface $popenWrapper,
23
        private LoggerInterface $logger,
24
    ) {
25 4
    }
26
27 1
    public function createSimpleFileStreamable(): StreamableInterface
28
    {
29 1
        return new SimpleFileStreamable(
30 1
            $this->psr17Factory
31 1
        );
32
    }
33
34 1
    public function createTranscodingStreamable(
35
        TranscoderInterface $transcoder
36
    ): StreamableInterface {
37 1
        return new TranscodingStreamable(
38 1
            $this,
39 1
            $transcoder
40 1
        );
41
    }
42
43 1
    public function createPumpStream(
44
        TranscoderInterface $transcoder
45
    ): StreamInterface {
46
        /** @var callable(int):mixed $handler */
47 1
        $handler = new TranscodingHandler(
48 1
            $this->logger,
49 1
            $transcoder
50 1
        );
51
52 1
        return new PumpStream($handler);
53
    }
54
55
    /**
56
     * Creates a ffmpeg transcoder
57
     *
58
     * If the given transcoding options aren't allowed, the default config will be used
59
     */
60 1
    public function createFfmpegTranscoder(
61
        string $codec,
62
        int $bitrate,
63
    ): TranscoderInterface {
64 1
        return new FfmpegTranscoder(
65 1
            $this->configProvider,
66 1
            $this->popenWrapper,
67 1
            $codec,
68 1
            $bitrate,
69 1
        );
70
    }
71
}
72