Completed
Push — master ( adb887...f59408 )
by Artem
08:25
created

StaticDictionary   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 10
c 5
b 0
f 0
lcom 1
cbo 0
dl 0
loc 72
ccs 18
cts 18
cp 1
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A dictionary() 0 4 1
A all() 0 4 1
A get() 0 11 3
A has() 0 4 1
A find() 0 6 2
A keys() 0 4 1
A values() 0 4 1
1
<?php
2
3
//----------------------------------------------------------------------
4
//
5
//  Copyright (C) 2015 Artem Rodygin
6
//
7
//  You should have received a copy of the MIT License along with
8
//  this file. If not, see <http://opensource.org/licenses/MIT>.
9
//
10
//----------------------------------------------------------------------
11
12
namespace Dictionary;
13
14
/**
15
 * Abstract static dictionary of key/value pairs.
16
 */
17
abstract class StaticDictionary implements StaticDictionaryInterface
18
{
19
    /** @var array Dictionary values (to be overloaded). */
20
    protected static $dictionary = [];
21
22
    /**
23
     * Returns dictionary.
24
     *
25
     * @return  array
26
     */
27 6
    protected static function dictionary()
28
    {
29 6
        return static::$dictionary;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35 1
    public static function all()
36
    {
37 1
        return static::dictionary();
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 1
    public static function get($key)
44
    {
45 1
        $dictionary = static::dictionary();
46
47 1
        if (array_key_exists($key, $dictionary)) {
48 1
            return $dictionary[$key];
49
        }
50
        else {
51 1
            return static::FALLBACK === null ? null : $dictionary[static::FALLBACK];
52
        }
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58 1
    public static function has($key)
59
    {
60 1
        return array_key_exists($key, static::dictionary());
61
    }
62
63
    /**
64
     * {@inheritdoc}
65
     */
66 1
    public static function find($value)
67
    {
68 1
        $key = array_search($value, static::dictionary());
69
70 1
        return $key === false ? static::FALLBACK : $key;
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76 1
    public static function keys()
77
    {
78 1
        return array_keys(static::dictionary());
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 1
    public static function values()
85
    {
86 1
        return array_values(static::dictionary());
87
    }
88
}
89