FFProbeConfig::getBinary()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @see       https://github.com/soluble-io/soluble-mediatools for the canonical repository
7
 *
8
 * @copyright Copyright (c) 2018-2020 Sébastien Vanvelthem. (https://github.com/belgattitude)
9
 * @license   https://github.com/soluble-io/soluble-mediatools/blob/master/LICENSE.md MIT
10
 */
11
12
namespace Soluble\MediaTools\Video\Config;
13
14
use Soluble\MediaTools\Common\Process\ProcessParamsInterface;
15
use Soluble\MediaTools\Video\Process\ProcessParams;
16
17
final class FFProbeConfig implements FFProbeConfigInterface
18
{
19
    public const DEFAULT_TIMEOUT      = null;
20
    public const DEFAULT_IDLE_TIMEOUT = null;
21
    public const DEFAULT_ENV          = [];
22
23
    /** @var string */
24
    private $binary;
25
26
    /** @var ProcessParamsInterface */
27
    private $processParams;
28
29
    /**
30
     * @param string                    $ffprobeBinary FFProbeBinary, if null: 'ffprobe' on linux, 'ffmprobe.exe' on windows
31
     * @param float|null                $timeout       max allowed time (in seconds) for conversion, null for no timeout
32
     * @param float|null                $idleTimeout   max allowed idle time (in seconds) for conversion, null for no timeout
33
     * @param array<string, string|int> $env           An array of additional env vars to set when running the ffprobe process
34
     */
35 35
    public function __construct(
36
        ?string $ffprobeBinary = null,
37
        ?float $timeout = self::DEFAULT_TIMEOUT,
38
        ?float $idleTimeout = self::DEFAULT_IDLE_TIMEOUT,
39
        array $env = self::DEFAULT_ENV
40
    ) {
41 35
        $this->binary = $ffprobeBinary ?? self::getPlatformDefaultBinary();
42
43 35
        $this->processParams = new ProcessParams(
44 35
            $timeout,
45
            $idleTimeout,
46
            $env
47
        );
48 35
    }
49
50 1
    public static function getPlatformDefaultBinary(): string
51
    {
52 1
        return DIRECTORY_SEPARATOR === '\\' ? 'ffprobe.exe' : 'ffprobe';
53
    }
54
55 18
    public function getBinary(): string
56
    {
57 18
        return $this->binary;
58
    }
59
60 15
    public function getProcessParams(): ProcessParamsInterface
61
    {
62 15
        return $this->processParams;
63
    }
64
}
65