Completed
Push — dev-master ( dd6200...6fdc6b )
by Derek Stephen
03:03 queued 01:56
created

Registry::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
4
namespace Bone\Mvc;
5
6
/**
7
 * Ahoy there! This here class will store all o' t' configuration
8
 * variables we have for our app'ication
9
 * Class Registry
10
 * @package Bone\Mvc
11
 */
12
class Registry
13
{
14
    /**
15
     * @var array
16
     * @access private
17
     */
18
    private $vars = [];
19
20
21
    /**
22
     *  There be nay feckin wi' constructors on board this ship
23
     *  There be nay copyin' o' th'ship either
24
     *  This ship is a singleton!
25
     */
26
    public function __construct(){}
27
    public function __clone(){}
28
29
30
    /**
31
     *  Ahoy! There nay be boardin' without yer configuration
32
33
     * @return Registry
34
     */
35 40
    public static function ahoy(): Registry
36 40
    {
37 40
        static $inst = null;
38 40
        if($inst === null)
39
        {
40 1
            $inst = new Registry();
41
        }
42 40
        return $inst;
43
    }
44
45
    /**
46
     * What would you like us t' remember for you?
47
     * @param $index
48
     * @param $value
49
     */
50 35
    public function set(string $index, $value)
51 35
    {
52 35
        $this->vars[$index] = $value;
53 35
    }
54
55
    /**
56
     * You would like t' remember somethin'?
57
     * @param string $index
58
     * @return mixed
59
     */
60 35
    public function get($index)
61 35
    {
62 35
        return isset($this->vars[$index]) ? $this->vars[$index] : null;
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    public function getAll(): array
69
    {
70
        return $this->vars;
71
    }
72
}