Completed
Push — master ( 8c1053...9934c8 )
by Woody
07:00
created

ConfigFactory   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 49
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

4 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 11 2
A __construct() 0 4 2
A forDirectory() 0 4 1
A forEnvironment() 0 7 1
1
<?php
2
3
namespace Northwoods\Config;
4
5
use Northwoods\Config\Loader\LoaderFactory;
6
7
class ConfigFactory
8
{
9
    /**
10
     * @return ConfigInterface
11
     */
12 3
    public static function make(array $options, LoaderFactory $loader = null)
13
    {
14 3
        $factory = new static($loader);
15 3
        $type = array_path($options, 'type', 'php');
16
17 3
        if (!empty($options['environment'])) {
18 2
            return $factory->forEnvironment($options['directory'], $options['environment'], $type);
19
        }
20
21 1
        return $factory->forDirectory($options['directory'], $type);
22
    }
23
24
    /**
25
     * @var LoaderFactory
26
     */
27
    private $loader;
28
29 3
    public function __construct(LoaderFactory $loader = null)
30
    {
31 3
        $this->loader = $loader ?: new LoaderFactory();
32 3
    }
33
34
    /**
35
     * @param string $directory
36
     * @return ConfigDirectory
37
     */
38 3
    public function forDirectory($directory, $type = 'php')
39
    {
40 3
        return new ConfigDirectory($directory, $this->loader->forType($type));
41
    }
42
43
    /**
44
     * @param string $directory
45
     * @param string $environment
46
     * @return ConfigCollection
47
     */
48 2
    public function forEnvironment($directory, $environment, $type = 'php')
49
    {
50 2
        return new ConfigCollection(
51 2
            $this->forDirectory("$directory/$environment", $type),
52 2
            $this->forDirectory($directory, $type)
53 2
        );
54
    }
55
}
56