Completed
Pull Request — master (#104)
by Joshua
02:18
created

Inflector::camelize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace As3\Modlr\Util;
4
5
class Inflector
6
{
7
    /**
8
     * Convert word into underscore format (e.g. some_name_here).
9
     *
10
     * @param   string  $word
11
     * @return  string
12
     */
13
    public function underscore($word)
14
    {
15
        if (false !== stristr($word, '-')) {
16
            $parts = explode('-', $word);
17
            foreach ($parts as &$part) {
18
                $part = ucfirst(strtolower($part));
19
            }
20
            $word = implode('', $parts);
21
        }
22
        return strtolower(preg_replace('~(?<=\\w)([A-Z])~', '_$1', $word));
23
    }
24
25
    /**
26
     * Convert word into dasherized format (e.g. some-name-here).
27
     *
28
     * @param   string  $word
29
     * @return  string
30
     */
31
    public function dasherize($word)
32
    {
33
        return str_replace('_', '-', $this->underscore($word));
34
    }
35
36
    /**
37
     * Convert word into camelized format (e.g. someNameHere).
38
     *
39
     * @param   string  $word
40
     * @return  string
41
     */
42
    public function camelize($word)
43
    {
44
        return lcfirst($this->studlify($word));
45
    }
46
47
    /**
48
     * Convert word into studly caps format (e.g. SomeNameHere).
49
     *
50
     * @param   string  $word
51
     * @return  string
52
     */
53
    public function studlify($word)
54
    {
55
        return str_replace(" ", "", $this->wordify($word));
56
    }
57
58
    /**
59
     * Convert word into wordified format (e.g. Some Name Here).
60
     *
61
     * @param   string  $word
62
     * @return  string
63
     */
64
    public function wordify($word)
65
    {
66
        return ucwords(strtr($this->underscore($word), "_", " "));
67
    }
68
}
69