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

FFProbeConfig   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 46
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPlatformDefaultBinary() 0 3 2
A __construct() 0 12 1
A getProcessParams() 0 3 1
A getBinary() 0 3 1
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\ProcessParams;
9
10
class FFProbeConfig implements FFProbeConfigInterface
11
{
12
    public const DEFAULT_TIMEOUT      = null;
13
    public const DEFAULT_IDLE_TIMEOUT = null;
14
    public const DEFAULT_ENV          = [];
15
16
    /** @var string */
17
    protected $binary;
18
19
    /** @var ProcessParamsInterface */
20
    protected $processParams;
21
22
    /**
23
     * @param string                    $ffprobeBinary FFProbeBinary, if null: 'ffprobe' on linux, 'ffmprobe.exe' on windows
24
     * @param float|null                $timeout       max allowed time (in seconds) for conversion, null for no timeout
25
     * @param float|null                $idleTimeout   max allowed idle time (in seconds) for conversion, null for no timeout
26
     * @param array<string, string|int> $env           An array of additional env vars to set when running the ffprobe process
27
     */
28 7
    public function __construct(
29
        ?string $ffprobeBinary = null,
30
        ?float $timeout = self::DEFAULT_TIMEOUT,
31
        ?float $idleTimeout = self::DEFAULT_IDLE_TIMEOUT,
32
        array $env = self::DEFAULT_ENV
33
    ) {
34 7
        $this->binary = $ffprobeBinary ?? self::getPlatformDefaultBinary();
35
36 7
        $this->processParams = new ProcessParams(
37 7
            $timeout,
38 7
            $idleTimeout,
39 7
            $env
40
        );
41 7
    }
42
43 1
    public static function getPlatformDefaultBinary(): string
44
    {
45 1
        return DIRECTORY_SEPARATOR === '\\' ? 'ffprobe.exe' : 'ffprobe';
46
    }
47
48 6
    public function getBinary(): string
49
    {
50 6
        return $this->binary;
51
    }
52
53 3
    public function getProcessParams(): ProcessParamsInterface
54
    {
55 3
        return $this->processParams;
56
    }
57
}
58