Inflector::doInflection()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Nip\Inflector;
4
5
use Nip\Inflector\Traits\HasCacheTrait;
6
use Nip\Inflector\Traits\HasDictionaryTrait;
7
use Nip\Inflector\Traits\InflectionCamelizeTrait;
8
use Nip\Inflector\Traits\InflectionClassifyTrait;
9
use Nip\Inflector\Traits\InflectionHyphenizeTrait;
10
use Nip\Inflector\Traits\InflectionOrdinalizeTrait;
11
use Nip\Inflector\Traits\InflectionPluralizeTrait;
12
use Nip\Inflector\Traits\InflectionSingularizeTrait;
13
use Nip\Inflector\Traits\InflectionTableizeTrait;
14
use Nip\Inflector\Traits\InflectionUnclasifyTrait;
15
use Nip\Inflector\Traits\InflectionUnderscoreTrait;
16
use Nip\Inflector\Traits\MagicMethodsTrait;
17
use Nip\Inflector\Traits\SingletonTrait;
18
19
/**
20
 * Class Inflector
21
 * @package Nip\Inflector
22
 * @based on https://github.com/cakephp/cakephp/blob/master/src/Utility/Inflector.php
23
 */
24
class Inflector
25
{
26 1
    use SingletonTrait;
27 1
    use HasCacheTrait;
28 1
    use HasDictionaryTrait;
29 1
    use MagicMethodsTrait;
30 1
    use InflectionCamelizeTrait;
31 1
    use InflectionClassifyTrait;
32 1
    use InflectionHyphenizeTrait;
33 1
    use InflectionOrdinalizeTrait;
34 1
    use InflectionPluralizeTrait;
35 1
    use InflectionSingularizeTrait;
36 1
    use InflectionTableizeTrait;
37 1
    use InflectionUnclasifyTrait;
38 1
    use InflectionUnderscoreTrait;
39
40
    /**
41
     * @param $name
42
     * @return bool
43
     */
44 21
    public function hasInflection($name)
45
    {
46 21
        $method = $this->inflectionMethod($name);
47 21
        return method_exists($this, $method);
48
    }
49
50
    /**
51
     * @param $name
52
     * @param $word
53
     * @return mixed
54
     */
55 21
    public function doInflection($name, $word)
56
    {
57 21
        if (!self::hasString($name, $word)) {
58 15
            $method = $this->inflectionMethod($name);
59 15
            self::setString($name, $word, $this->$method($word));
60
        }
61
62 21
        return self::getString($name, $word);
63
    }
64
65
    /**
66
     * @param $name
67
     * @return string
68
     */
69 21
    protected function inflectionMethod($name)
70
    {
71 21
        return "do" . ucfirst($name);
72
    }
73
}
74