Passed
Push — master ( 253500...76e950 )
by Sébastien
03:02 queued 48s
created

ConfigProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 78.95%

Importance

Changes 0
Metric Value
wmc 8
eloc 29
dl 0
loc 84
ccs 15
cts 19
cp 0.7895
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getDependencies() 0 5 1
A getAliases() 0 12 1
A getFactories() 0 12 1
A __invoke() 0 4 1
A getDefaultConfiguration() 0 15 4
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-2019 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\Video\VideoAnalyzer;
15
use Soluble\MediaTools\Video\VideoAnalyzerFactory;
16
use Soluble\MediaTools\Video\VideoAnalyzerInterface;
17
use Soluble\MediaTools\Video\VideoConverter;
18
use Soluble\MediaTools\Video\VideoConverterFactory;
19
use Soluble\MediaTools\Video\VideoConverterInterface;
20
use Soluble\MediaTools\Video\VideoInfoReader;
21
use Soluble\MediaTools\Video\VideoInfoReaderFactory;
22
use Soluble\MediaTools\Video\VideoInfoReaderInterface;
23
use Soluble\MediaTools\Video\VideoThumbGenerator;
24
use Soluble\MediaTools\Video\VideoThumbGeneratorFactory;
25
use Soluble\MediaTools\Video\VideoThumbGeneratorInterface;
26
27
class ConfigProvider
28
{
29
    /**
30
     * @return array<string, array<string,array<string,mixed>>>
31
     */
32 1
    public function __invoke(): array
33
    {
34
        return [
35 1
            'dependencies' => $this->getDependencies(),
36
        ];
37
    }
38
39
    /**
40
     * @return array<string, array<string,string>>
41
     */
42 48
    public function getDependencies(): array
43
    {
44
        return [
45 48
            'aliases'   => $this->getAliases(),
46 48
            'factories' => $this->getFactories(),
47
        ];
48
    }
49
50
    /**
51
     * Return concrete implementation aliases if needed.
52
     *
53
     * @return array<string, string>
54
     */
55 48
    public function getAliases(): array
56
    {
57
        return [
58
            // Configuration holders
59 48
            FFMpegConfig::class  => FFMpegConfigInterface::class,
60
            FFProbeConfig::class => FFProbeConfigInterface::class,
61
62
            // Services
63
            VideoConverter::class      => VideoConverterInterface::class,
64
            VideoInfoReader::class     => VideoInfoReaderInterface::class,
65
            VideoAnalyzer::class       => VideoAnalyzerInterface::class,
66
            VideoThumbGenerator::class => VideoThumbGeneratorInterface::class,
67
        ];
68
    }
69
70
    /**
71
     * Return interface based factories.
72
     *
73
     * @return array<string, string>
74
     */
75 48
    public function getFactories(): array
76
    {
77
        return [
78
            // Configuration holders
79 48
            FFMpegConfigInterface::class  => FFMpegConfigFactory::class,
80
            FFProbeConfigInterface::class => FFProbeConfigFactory::class,
81
82
            // Services classes
83
            VideoConverterInterface::class      => VideoConverterFactory::class,
84
            VideoInfoReaderInterface::class     => VideoInfoReaderFactory::class,
85
            VideoAnalyzerInterface::class       => VideoAnalyzerFactory::class,
86
            VideoThumbGeneratorInterface::class => VideoThumbGeneratorFactory::class,
87
88
            // Logger
89
            //LoggerConfigInterface::class    => <Factory to create / too much choice>
90
        ];
91
    }
92
93
    /**
94
     * @return array<string, array<string,mixed>>
95
     */
96 1
    public static function getDefaultConfiguration(): array
97
    {
98 1
        $baseDir = dirname(__DIR__, 3);
99 1
        if (!is_dir($baseDir)) {
100
            throw new \RuntimeException(sprintf(
101
                'Cannot locate library directory: %s',
102
                $baseDir
103
            ));
104
        }
105 1
        $config = implode(DIRECTORY_SEPARATOR, [$baseDir, 'config', 'soluble-mediatools.config.php']);
106 1
        if (!is_file($config) || !is_readable($config)) {
107
            throw new \RuntimeException(sprintf('Missing project default configuration: %s', $config));
108
        }
109
110 1
        return require $config;
111
    }
112
}
113