FFProbeConfig   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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
/**
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