Str   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 54
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A className() 0 11 2
A variableName() 0 9 2
A underscore() 0 10 2
A methodName() 0 8 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Sirius\Orm\Helpers;
5
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)
50
    {
51
        if (! isset(static::$cache['className'][$str])) {
52
            $str = strtolower($str);
53
            $str = preg_replace("/[^a-z0-9]+/", ' ', $str);
54
            $str = ucwords($str);
55
56
            static::$cache['className'][$str] = str_replace(' ', '', $str);
57
        }
58
59
        return static::$cache['className'][$str];
60
    }
61
}
62