Config::setFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
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
}