Completed
Push — master ( f65d8f...4f3de5 )
by Pavel
04:14 queued 01:54
created

Helper::dashesToCamelCase()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 2
dl 10
loc 10
rs 9.4285
c 1
b 0
f 0
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 View Code Duplication
    public static function dashesToCamelCase($string, $capitalizeFirstChar = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
    {
14
        $str = str_replace(' ', '', ucwords(str_replace('-', ' ', $string)));
15
16
        if (!$capitalizeFirstChar) {
17
            $str = lcfirst($str);
18
        }
19
20
        return $str;
21
    }
22
23
    /**
24
     * @param string $string
25
     * @param bool   $capitalizeFirstChar
26
     *
27
     * @return string
28
     */
29 View Code Duplication
    public static function underscoreToCamelCase($string, $capitalizeFirstChar = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31
        $str = str_replace(' ', '', ucwords(str_replace('_', ' ', $string)));
32
33
        if (!$capitalizeFirstChar) {
34
            $str = lcfirst($str);
35
        }
36
37
        return $str;
38
    }
39
40
    /**
41
     * @param int $length
42
     *
43
     * @return string
44
     */
45
    public static function generateRandomString($length=32)
46
    {
47
        $chars      = 'abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ023456789';
48
        $charsCount = strlen($chars);
49
50
        srand((double)microtime()*1000000);
51
        $i     = 1;
52
        $token = '';
53
54
        while ($i <= $length)
55
        {
56
            $num = rand() % $charsCount;
57
            $tmp = substr($chars, $num, 1);
58
            $token .= $tmp;
59
            $i++;
60
        }
61
62
        return $token;
63
    }
64
}
65