Passed
Push — master ( bed015...129377 )
by Sébastien
04:15
created

FFMpegConfig::getAdapter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Video\Config;
6
7
use Soluble\MediaTools\Common\Process\ProcessParamsInterface;
8
use Soluble\MediaTools\Video\Adapter\ConverterAdapterInterface;
9
use Soluble\MediaTools\Video\Adapter\FFMpegAdapter;
10
use Soluble\MediaTools\Video\ProcessParams;
11
12
class FFMpegConfig implements FFMpegConfigInterface
13
{
14
    public const DEFAULT_THREADS      = null;
15
    public const DEFAULT_TIMEOUT      = null;
16
    public const DEFAULT_IDLE_TIMEOUT = null;
17
    public const DEFAULT_ENV          = [];
18
19
    /** @var string */
20
    protected $binary;
21
22
    /** @var int|null */
23
    protected $threads;
24
25
    /** @var FFMpegAdapter */
26
    protected $ffmpegAdapter;
27
28
    /** @var ProcessParams */
29
    protected $processParams;
30
31
    /**
32
     * @param string|null               $ffmpegBinary if null will return 'ffmpeg' on linux, 'ffmpeg.exe' on windows
33
     * @param int|null                  $threads      number fo threads used for conversion, null means single threads, 0 all cores, ....
34
     * @param float|null                $timeout      max allowed time (in seconds) for conversion, null for no timeout
35
     * @param float|null                $idleTimeout  max allowed idle time (in seconds) for conversion, null for no timeout
36
     * @param array<string, string|int> $env          An array of additional env vars to set when running the ffmpeg conversion process
37
     */
38 31
    public function __construct(
39
        ?string $ffmpegBinary = null,
40
        ?int $threads = self::DEFAULT_THREADS,
41
        ?float $timeout = self::DEFAULT_TIMEOUT,
42
        ?float $idleTimeout = self::DEFAULT_IDLE_TIMEOUT,
43
        array $env = self::DEFAULT_ENV
44
    ) {
45 31
        $this->binary = $ffmpegBinary ?? self::getPlatformDefaultBinary();
46
47 31
        $this->threads     = $threads;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 5 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
48
49 31
        $this->processParams = new ProcessParams(
50 31
            $timeout,
51 31
            $idleTimeout,
52 31
            $env
53
        );
54 31
    }
55
56 5
    public static function getPlatformDefaultBinary(): string
57
    {
58 5
        return (DIRECTORY_SEPARATOR === '\\') ? 'ffmpeg.exe' : 'ffmpeg';
59
    }
60
61 20
    public function getBinary(): string
62
    {
63 20
        return $this->binary;
64
    }
65
66 14
    public function getThreads(): ?int
67
    {
68 14
        return $this->threads;
69
    }
70
71 14
    public function getProcessParams(): ProcessParamsInterface
72
    {
73 14
        return $this->processParams;
74
    }
75
76
    /**
77
     * @return FFMpegAdapter
78
     */
79 16
    public function getAdapter(): ConverterAdapterInterface
80
    {
81 16
        if ($this->ffmpegAdapter === null) {
82 16
            $this->ffmpegAdapter = new FFMpegAdapter($this);
83
        }
84
85 16
        return $this->ffmpegAdapter;
86
    }
87
}
88