Config   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 8
c 1
b 0
f 0
dl 0
loc 31
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 6 2
A __construct() 0 3 1
A get() 0 3 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