Total Complexity | 8 |
Total Lines | 54 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
6 | class Str |
||
7 | { |
||
8 | protected static $cache = [ |
||
9 | 'underscore' => [], |
||
10 | 'methodName' => [], |
||
11 | 'methodName' => [], |
||
12 | 'variableName' => [], |
||
13 | 'className' => [], |
||
14 | ]; |
||
15 | |||
16 | public static function underscore($str) |
||
17 | { |
||
18 | if (! isset(static::$cache['underscore'][$str])) { |
||
19 | $str = strtolower($str); |
||
20 | $str = preg_replace("/[^a-z0-9]+/", ' ', $str); |
||
21 | |||
22 | static::$cache['underscore'][$str] = str_replace(' ', '_', $str); |
||
23 | } |
||
24 | |||
25 | return static::$cache['underscore'][$str]; |
||
26 | } |
||
27 | |||
28 | public static function methodName($str, $verb) |
||
29 | { |
||
30 | $key = $verb . $str; |
||
31 | if (! isset(static::$cache['methodName'][$key])) { |
||
32 | static::$cache['methodName'][$key] = strtolower($verb) . static::className($str); |
||
33 | } |
||
34 | |||
35 | return static::$cache['methodName'][$key]; |
||
36 | } |
||
37 | |||
38 | public static function variableName($str) |
||
39 | { |
||
40 | if (! isset(static::$cache['variableName'][$str])) { |
||
41 | $class = static::className($str); |
||
42 | |||
43 | static::$cache['variableName'][$str] = strtolower(substr($class, 0, 1)) . substr($class, 1); |
||
44 | } |
||
45 | |||
46 | return static::$cache['variableName'][$str]; |
||
47 | } |
||
48 | |||
49 | public static function className($str) |
||
60 | } |
||
61 | } |
||
62 |