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

HasDictionaryTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
dl 0
loc 38
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

3 Methods

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