Config   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 69
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 2
A getAll() 0 3 1
A get() 0 5 1
A setDirectory() 0 3 1
A setFile() 0 3 1
1
<?php
2
3
namespace Hyperized\Benchmark\Config;
4
5
use Adbar\Dot;
6
use Hyperized\Benchmark\Generic\Visual;
7
use Symfony\Component\Config\FileLocator;
8
9
/**
10
 * Class Config
11
 * @package Hyperized\Benchmark\Config
12
 */
13
class Config
14
{
15
    /**
16
     * @var string
17
     */
18
    private $file = 'config.yml';
19
    /**
20
     * @var string
21
     */
22
    private $directory = 'config';
23
    /**
24
     * @var array
25
     */
26
    private $config;
27
28
    /**
29
     * Config constructor.
30
     */
31
    public function __construct()
32
    {
33
        $locator = new FileLocator([
34
            __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . $this->directory
35
        ]);
36
37
        try {
38
            $loader = new YamlConfigLoader($locator);
39
40
            $this->config = $loader->load(
41
                $locator->locate($this->file)
42
            );
43
        } catch (\Exception $e) {
44
            Visual::print($this->file . ' could not be loaded, please copy ' . $this->directory . '/config.yml.example to ' . $this->directory . '/' . $this->file);
45
        }
46
    }
47
48
    /**
49
     * @param string $file
50
     */
51
    public function setFile(string $file): void
52
    {
53
        $this->file = $file;
54
    }
55
56
    /**
57
     * @param string $directory
58
     */
59
    public function setDirectory(string $directory): void
60
    {
61
        $this->directory = $directory;
62
    }
63
64
    /**
65
     * @param string $field
66
     *
67
     * @return mixed
68
     */
69
    public function get(string $field)
70
    {
71
        $dot = new Dot($this->config);
72
73
        return $dot->get($field);
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    public function getAll(): array
80
    {
81
        return $this->config;
82
    }
83
}