HasDictionaryTrait   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 35
ccs 7
cts 8
cp 0.875
rs 10
c 1
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasString() 0 3 1
A getString() 0 6 2
A setString() 0 3 1
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