ConfigurationFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 3
Bugs 1 Features 2
Metric Value
wmc 6
c 3
b 1
f 2
lcom 0
cbo 0
dl 0
loc 42
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 17 4
A getVendors() 0 8 2
1
<?php
2
3
namespace Libcast\AssetDistributor\Configuration;
4
5
use Psr\Log\LoggerInterface;
6
7
class ConfigurationFactory
8
{
9
    /**
10
     *
11
     * @param $vendor
12
     * @param $path
13
     * @return Configuration
14
     * @throws \Exception
15
     */
16
    public static function build($vendor, $path, LoggerInterface $logger = null)
17
    {
18
        if (!$configuration = parse_ini_file($path, true)) {
19
            throw new \Exception("File '$path' is not a valid PHP configuration file");
20
        }
21
22
        if (!in_array($vendor, array_keys($configuration))) {
23
            throw new \Exception("Missing $vendor configuration");
24
        }
25
26
        $class = sprintf('\Libcast\AssetDistributor\%1$s\%1$sConfiguration', $vendor);
27
        if (!class_exists($class)) {
28
            throw new \Exception("Missing configuration class for $vendor");
29
        }
30
31
        return new $class($configuration[$vendor], $logger);
32
    }
33
34
    /**
35
     *
36
     * @param $path
37
     * @return array
38
     * @throws \Exception
39
     */
40
    public static function getVendors($path)
41
    {
42
        if (!$configuration = parse_ini_file($path, true)) {
43
            throw new \Exception("File '$path' is not a valid PHP configuration file");
44
        }
45
46
        return array_keys($configuration);
47
    }
48
}
49