FFProbeConfigFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 14
c 0
b 0
f 0
dl 0
loc 33
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __invoke() 0 11 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 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