Config::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Core;
4
5
class Config
6
{
7
    private $settings = [];
8
    private static $_instance;
9
10
    /**
11
     *Get the configuration variables
12
     * @param string $file ex: __DIR__. '/config/config.php'
13
     * @return Config
14
     */
15
    public static function getInstance(string $file): Config
16
    {
17
        if (is_null(self::$_instance)) {
18
            self::$_instance = new Config($file);
19
        }
20
        return self::$_instance;
21
    }
22
23
    public function __construct(string $file)
24
    {
25
        $this->settings = require($file);
26
    }
27
28
    /**
29
     * Access to a configuration variable
30
     * @param string $key
31
     * @return mixed
32
     */
33
    public function get(string $key)
34
    {
35
        return $this->settings[$key] ?? \null;
36
    }
37
}
38