Settings   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 4
Bugs 1 Features 1
Metric Value
c 4
b 1
f 1
dl 0
loc 37
rs 10
wmc 3
lcom 1
cbo 1

3 Methods

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