ArrayLoader::createFromFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4286
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
4
namespace Dotor\Loader;
5
6
7
use Dotor\Loader;
8
9
class ArrayLoader implements Loader
10
{
11
12
    private $config = [];
13
14
    /**
15
     * @param array $config
16
     * @return ArrayLoader
17
     */
18
    public static function create($config = [])
19
    {
20
        $instance = new ArrayLoader();
21
        $instance->load($config);
22
        return $instance;
23
    }
24
25
    /**
26
     * @param array $config
27
     */
28
    public function load($config = [])
29
    {
30
        $this->config = $config;
31
    }
32
33
    /**
34
     * @param string $path
35
     * @return ArrayLoader
36
     */
37
    public static function createFromFile($path)
38
    {
39
        $instance = new ArrayLoader();
40
        $instance->loadFromFile($path);
41
        return $instance;
42
    }
43
44
    /**
45
     * @param string $path
46
     * @throws Exception\FileNotReturnAnArrayException
47
     * @throws Exception\FileIsNotReadableException
48
     */
49
    public function loadFromFile($path)
50
    {
51
        if (!is_readable($path)) {
52
            throw new Loader\Exception\FileIsNotReadableException();
53
        }
54
55
        $config = include($path);
56
57
        if (!is_array($config)) {
58
            throw new Loader\Exception\FileNotReturnAnArrayException();
59
        }
60
61
        $this->load($config);
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    public function get()
68
    {
69
        return $this->config;
70
    }
71
}
72