ArrayLoader   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 6 1
A load() 0 4 1
A createFromFile() 0 6 1
A loadFromFile() 0 14 3
A get() 0 4 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