HasDictionaryTrait::hasString()   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 1
Bugs 0 Features 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 1
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
    protected static $dictionary;
14
15
    /**
16
     * @param $inflection
17
     * @param $string
18
     * @return bool
19
     */
20 21
    protected static function hasString($inflection, $string)
21
    {
22 21
        return isset(self::$dictionary[$inflection][$string]);
23
    }
24
25
    /**
26
     * @param $inflection
27
     * @param $string
28
     * @return bool
29
     */
30 21
    protected static function getString($inflection, $string)
31
    {
32 21
        if (!self::hasString($inflection, $string)) {
33
            throw new \BadMethodCallException("String {$string} is not contained in the {$inflection} dictionary");
34
        }
35 21
        return self::$dictionary[$inflection][$string];
36
    }
37
38
    /**
39
     * @param $inflection
40
     * @param $string
41
     * @param $value
42
     */
43 15
    protected static function setString($inflection, $string, $value)
44
    {
45 15
        self::$dictionary[$inflection][$string] = $value;
46 15
    }
47
}
48