Helper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 66
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A dashesToCamelCase() 0 4 1
A underscoreToCamelCase() 0 4 1
A generateRandomString() 0 18 2
A replace() 0 10 2
1
<?php
2
namespace App\Common;
3
4
class Helper
5
{
6
    /**
7
     * @param string  $string
8
     * @param bool    $capitalizeFirstChar
9
     *
10
     * @return string
11
     */
12
    public static function dashesToCamelCase($string, $capitalizeFirstChar = false)
13
    {
14
        return self::replace($string, '-', $capitalizeFirstChar);
15
    }
16
17
    /**
18
     * @param string $string
19
     * @param bool   $capitalizeFirstChar
20
     *
21
     * @return string
22
     */
23
    public static function underscoreToCamelCase($string, $capitalizeFirstChar = false)
24
    {
25
        return self::replace($string, '_', $capitalizeFirstChar);
26
    }
27
28
    /**
29
     * @param int $length
30
     *
31
     * @return string
32
     */
33
    public static function generateRandomString($length = 32)
34
    {
35
        $chars      = 'abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ023456789';
36
        $charsCount = strlen($chars);
37
38
        srand((double)microtime() * 1000000);
39
        $i     = 1;
40
        $token = '';
41
42
        while ($i <= $length) {
43
            $num = rand() % $charsCount;
44
            $tmp = substr($chars, $num, 1);
45
            $token .= $tmp;
46
            $i++;
47
        }
48
49
        return $token;
50
    }
51
52
    /**
53
     * @param string $string
54
     * @param string $symbol
55
     * @param bool   $capitalizeFirstChar
56
     *
57
     * @return string
58
     */
59
    private static function replace($string, $symbol, $capitalizeFirstChar = false)
60
    {
61
        $str = str_replace(' ', '', ucwords(str_replace($symbol, ' ', $string)));
62
63
        if (!$capitalizeFirstChar) {
64
            $str = lcfirst($str);
65
        }
66
67
        return $str;
68
    }
69
}
70