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

Helper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 61
Duplicated Lines 32.79 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A dashesToCamelCase() 10 10 2
A underscoreToCamelCase() 10 10 2
A generateRandomString() 0 19 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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