FFProbeConfigFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
ccs 3
cts 3
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 Psr\Container\ContainerInterface;
15
use Soluble\MediaTools\Common\Config\ContainerConfigLocator;
16
use Soluble\MediaTools\Common\Config\SafeConfigReader;
17
use Soluble\MediaTools\Common\Exception\InvalidConfigException;
18
19
final class FFProbeConfigFactory
20
{
21
    public const DEFAULT_ENTRY_NAME = 'config';
22
    public const DEFAULT_CONFIG_KEY = 'soluble-mediatools';
23
24
    /** @var string */
25
    private $entryName;
26
27
    /** @var null|string */
28
    private $configKey;
29
30 38
    public function __construct(
31
        string $entryName = self::DEFAULT_ENTRY_NAME,
32
        ?string $configKey = self::DEFAULT_CONFIG_KEY
33
    ) {
34 38
        $this->entryName = $entryName;
35 38
        $this->configKey = $configKey;
36 38
    }
37
38
    /**
39
     * @throws InvalidConfigException
40
     */
41 38
    public function __invoke(ContainerInterface $container): FFProbeConfigInterface
42
    {
43 38
        $config = (new ContainerConfigLocator($container, $this->entryName))->getConfig($this->configKey);
44
45 36
        $scr = new SafeConfigReader($config, $this->configKey ?? '');
46
47 36
        return new FFProbeConfig(
48 36
            $scr->getNullableString('ffprobe.binary', null),
49 35
            $scr->getNullableFloat('ffprobe.timeout', FFProbeConfig::DEFAULT_TIMEOUT),
50 35
            $scr->getNullableFloat('ffprobe.idle_timeout', FFProbeConfig::DEFAULT_IDLE_TIMEOUT),
51 35
            $scr->getArray('ffprobe.env', FFProbeConfig::DEFAULT_ENV)
52
        );
53
    }
54
}
55