Completed
Push — master ( 477c6b...8b3cf8 )
by Sébastien
04:39 queued 01:53
created

ConfigTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 57.89%

Importance

Changes 0
Metric Value
wmc 6
dl 0
loc 34
ccs 11
cts 19
cp 0.5789
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFFProbeConfig() 0 14 3
A getFFMpegConfig() 0 16 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Config;
6
7
use Psr\Container\ContainerInterface;
8
use Soluble\MediaTools\Exception\InvalidConfigException;
9
10
trait ConfigTrait
11
{
12 1
    protected function getFFMpegConfig(ContainerInterface $container): FFMpegConfig
13
    {
14 1
        $key    = 'ffmpeg.binary';
15 1
        $config = $container->get('config')['soluble-mediatools'] ?? [];
16
17 1
        if (!isset($config[$key]) || trim($config[$key]) === '') {
18
            throw new InvalidConfigException(
19
                sprintf(
20
                    'The [\'%s\'] value is missing in config [\'soluble-mediatools\']',
21
                    $key
22
                )
23
            );
24
        }
25 1
        $threads = $config['ffmpeg.threads'] ?? null;
26
27 1
        return new FFMpegConfig($config[$key], $threads);
28
    }
29
30 1
    protected function getFFProbeConfig(ContainerInterface $container): FFProbeConfig
31
    {
32 1
        $key    = 'ffprobe.binary';
33 1
        $config = $container->get('config')['soluble-mediatools'] ?? [];
34 1
        if (!isset($config[$key]) || trim($config[$key]) === '') {
35
            throw new InvalidConfigException(
36
                sprintf(
37
                    'The [\'%s\'] value is missing in config [\'soluble-mediatools\']',
38
                    $key
39
                )
40
            );
41
        }
42
43 1
        return new FFProbeConfig($config[$key]);
44
    }
45
}
46