Passed
Push — master ( 03087a...f49b8e )
by Gabriel
01:58
created

HasDictionaryTrait::getString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Nip\Inflector\Traits;
4
5
/**
6
 * Trait HasDictionaryTrait
7
 * @package Nip\Inflector\Traits
8
 *
9
 * @method unclassify($string)
10
 */
11
trait HasDictionaryTrait
12
{
13
14
    protected static $dictionary;
15
16
    /**
17
     * @param $inflection
18
     * @param $string
19
     * @return bool
20
     */
21 19
    protected static function hasString($inflection, $string)
22
    {
23 19
        return isset(self::$dictionary[$inflection][$string]);
24
    }
25
26
    /**
27
     * @param $inflection
28
     * @param $string
29
     * @return bool
30
     */
31 19
    protected static function getString($inflection, $string)
32
    {
33 19
        if (!self::hasString($inflection, $string)) {
34
            throw new \BadMethodCallException("String {$string} is not contained in the {$inflection} dictionary");
35
        }
36 19
        return self::$dictionary[$inflection][$string];
37
    }
38
39
    /**
40
     * @param $inflection
41
     * @param $string
42
     * @param $value
43
     */
44 13
    protected static function setString($inflection, $string, $value)
45
    {
46 13
        self::$dictionary[$inflection][$string] = $value;
47 13
    }
48
}
49