Container::rebind()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sanderdekroon\Parlant;
4
5
class Container
6
{
7
8
    private $registry = [];
9
10
11 35
    public function bind($key, $data)
12
    {
13 35
        if ($this->bound($key)) {
14 4
            return $this->rebind($key, $data);
15
        }
16
17 35
        return $this->registry[$key] = $data;
18
    }
19
20
21 14
    public function append($key, $data)
22
    {
23 14
        return $this->registry[$key][] = $data;
24
    }
25
26
27 28
    public function get($key)
28
    {
29 28
        if (!$this->bound($key)) {
30 11
            return null;
31
        }
32
33 28
        return $this->registry[$key];
34
    }
35
36
37 28
    public function all()
38
    {
39 28
        return $this->registry;
40
    }
41
42
43
    public function has($key)
44
    {
45
        return $this->bound($key);
46
    }
47
48
49 35
    private function bound($key)
50
    {
51 35
        return array_key_exists($key, $this->registry);
52
    }
53
54
55 4
    private function rebind($key, $data)
56
    {
57 4
        return $this->registry[$key] = $data;
58
    }
59
}
60