Completed
Push — develop ( e56745...98584e )
by Mathieu
01:51
created

Registry   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Test Coverage

Coverage 69.23%

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 55
ccs 18
cts 26
cp 0.6923
rs 10
c 0
b 0
f 0
wmc 11

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getProperty() 0 9 3
A clean() 0 4 1
A getFromContext() 0 10 3
A get() 0 8 2
A set() 0 4 1
A exists() 0 5 1
1
<?php
2
namespace Suricate;
3
4
class Registry
5
{
6
    protected static $data = [];
7
    protected static $context;
8
9 1
    public static function get($key, $defaultValue = null)
10
    {
11 1
        $data = &static::getFromContext();
12 1
        if (isset($data[$key])) {
13 1
            return $data[$key];
14
        }
15
        
16 1
        return $defaultValue;
17
    }
18
19
    public static function getProperty($key, $property, $defaultValue = null)
20
    {
21
        if ($object = static::get($key)) {
22
            if (isset($object->$property)) {
23
                return $object->$property;
24
            }
25
        }
26
27
        return $defaultValue;
28
    }
29
30 1
    public static function set($key, $value)
31
    {
32 1
        $data = &static::getFromContext();
33 1
        $data[$key] = $value;
34 1
    }
35
36 1
    public static function exists($key)
37
    {
38 1
        $data = &static::getFromContext();
39
40 1
        return isset($data[$key]);
41
    }
42
43 1
    private static function &getFromContext()
44
    {
45 1
        if (static::$context !== null) {
46
            if (!isset(static::$data[static::$context])) {
47
                static::$data[static::$context] = array();
48
            }
49
            return static::$data[static::$context];
50
        }
51
52 1
        return static::$data;
53
    }
54
55 1
    public static function clean()
56
    {
57 1
        $data = &static::getFromContext();
58 1
        $data = array();
59 1
    }
60
}
61