Passed
Push — master ( 2b6224...357a76 )
by Radu
01:41
created

AbstractLibrary::setSetting()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace WebServCo\Framework;
3
4
abstract class AbstractLibrary
5
{
6
    private $settings = [];
7
    protected $data = [];
8
9
    public function __construct($settings = [])
10
    {
11
        if (is_array($settings)) {
12
            $this->settings = $settings;
13
        }
14
    }
15
16
    /**
17
     * @param mixed $key Can be an array, a string,
18
     *                          or a special formatted string
19
     *                          (eg 'app/path/project').
20
     * @param mixed $value The value to be stored.
21
     *
22
     * @return bool True on success and false on failure.
23
     */
24
    final public function setData($key, $value)
25
    {
26
        if (empty($key)) {
27
            return false;
28
        }
29
        $this->data = \WebServCo\Framework\ArrayStorage::set($this->data, $key, $value);
30
        return true;
31
    }
32
33
    /**
34
     * @param mixed $key Can be an array, a string,
35
     *                          or a special formatted string
36
     *                          (eg 'app/path/project').
37
     * @param mixed $value The value to be stored.
38
     *
39
     * @return bool True on success and false on failure.
40
     */
41
    final public function setSetting($key, $value)
42
    {
43
        if (empty($key)) {
44
            return false;
45
        }
46
        $this->settings = \WebServCo\Framework\ArrayStorage::set($this->settings, $key, $value);
47
        return true;
48
    }
49
50
    final public function getData()
51
    {
52
        return $this->data;
53
    }
54
55
    final public function setting($key, $defaultValue = false)
56
    {
57
        return \WebServCo\Framework\ArrayStorage::get(
58
            $this->settings,
59
            $key,
60
            $defaultValue
61
        );
62
    }
63
64
    final public function data($key, $defaultValue = false)
65
    {
66
        return \WebServCo\Framework\ArrayStorage::get(
67
            $this->data,
68
            $key,
69
            $defaultValue
70
        );
71
    }
72
}
73