ServerConfig   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 5
Bugs 2 Features 1
Metric Value
c 5
b 2
f 1
dl 0
loc 46
rs 10
wmc 5
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A get() 0 5 2
A set() 0 7 1
A getAll() 0 4 1
1
<?php
2
namespace Sovereign\Lib;
3
4
/**
5
 * Class ServerConfig
6
 * @package Sovereign\Lib
7
 */
8
class ServerConfig
9
{
10
    /**
11
     * @var Db
12
     */
13
    protected $db;
14
15
    /**
16
     * ServerConfig constructor.
17
     * @param Db $db
18
     */
19
    public function __construct(Db $db)
20
    {
21
        $this->db = $db;
22
    }
23
24
    /**
25
     * @param string $key
26
     */
27
    public function get($guildID, $key)
28
    {
29
        $data = json_decode($this->db->queryField("SELECT settings FROM settings WHERE serverID = :serverID", "settings", array(":serverID" => $guildID)));
30
        return isset($data->{$key}) ? $data->{$key} : null;
31
    }
32
33
    /**
34
     * @param string $key
35
     */
36
    public function set($guildID, $key, $value)
37
    {
38
        $json = $this->getAll($guildID);
39
        $json->{$key} = $value;
40
        $data = json_encode($json);
41
        $this->db->execute("INSERT INTO settings (serverID, settings) VALUES (:serverID, :settings) ON DUPLICATE KEY UPDATE settings = :settings", array(":serverID" => $guildID, ":settings" => $data));
42
    }
43
44
    /**
45
     * @param $guildID
46
     * @return mixed
47
     */
48
    public function getAll($guildID)
49
    {
50
        return json_decode($this->db->queryField("SELECT settings FROM settings WHERE serverID = :serverID", "settings", array(":serverID" => $guildID)));
51
    }
52
53
}