Completed
Push — master ( 9baf8b...adb887 )
by Artem
03:01
created

StaticDictionary::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 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
     * {@inheritdoc}
24
     */
25 1
    public static function all()
26
    {
27 1
        return static::$dictionary;
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 1
    public static function get($key)
34
    {
35 1
        if (array_key_exists($key, static::$dictionary)) {
36 1
            return static::$dictionary[$key];
37
        }
38
        else {
39 1
            return static::FALLBACK === null ? null : static::$dictionary[static::FALLBACK];
40
        }
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public static function has($key)
47
    {
48 1
        return array_key_exists($key, static::$dictionary);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public static function find($value)
55
    {
56 1
        $key = array_search($value, static::$dictionary);
57
58 1
        return $key === false ? static::FALLBACK : $key;
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64 1
    public static function keys()
65
    {
66 1
        return array_keys(static::$dictionary);
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 1
    public static function values()
73
    {
74 1
        return array_values(static::$dictionary);
75
    }
76
}
77