Completed
Push — master ( 2402fb...6f9376 )
by Elan
01:35 queued 10s
created

Config   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 63
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 5 1
A read() 0 8 2
A all() 0 4 1
A write() 0 4 1
A clear() 0 4 1
1
<?php
2
3
namespace XHGui;
4
5
/**
6
 * Loads and reads config file.
7
 */
8
class Config
9
{
10
    private static $config = [];
11
12
    /**
13
     * Load a config file, it will replace
14
     * all the currently loaded configuration.
15
     *
16
     * @return void
17
     */
18
    public static function load($file)
19
    {
20
        $config = include $file;
21
        self::$config = array_merge(self::$config, $config);
22
    }
23
24
    /**
25
     * Read a config value.
26
     *
27
     * @param string $name The name of the config variable
28
     * @return mixed The value or null.
29
     */
30
    public static function read($name)
31
    {
32
        if (isset(self::$config[$name])) {
33
            return self::$config[$name];
34
        }
35
36
        return null;
37
    }
38
39
    /**
40
     * Get all the configuration options.
41
     *
42
     * @return array
43
     */
44
    public static function all()
45
    {
46
        return self::$config;
47
    }
48
49
    /**
50
     * Write a config value.
51
     *
52
     * @param string $name The name of the config variable
53
     * @param mixed $value The value of the config variable
54
     * @return void
55
     */
56
    public static function write($name, $value)
57
    {
58
        self::$config[$name] = $value;
59
    }
60
61
    /**
62
     * Clear out the data stored in the config class.
63
     *
64
     * @return void
65
     */
66
    public static function clear()
67
    {
68
        self::$config = [];
69
    }
70
}
71