Passed
Push — master ( a74354...254a60 )
by Andrea
18:29 queued 11s
created

StringUtils   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 57.14%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 49
ccs 8
cts 14
cp 0.5714
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toCamelCase() 0 13 3
A underscore() 0 7 1
1
<?php
2
3
namespace Cdf\BiCoreBundle\Utils\String;
4
5
class StringUtils
6
{
7
    /**
8
     * Translates a string with underscores into camel case (e.g. first_name -&gt; firstName).
9
     *
10
     * @param array $parametri
11
     *
12
     * @return string $str translated into camel caps
13
     */
14 3
    public static function toCamelCase($parametri = array())
15
    {
16 3
        $str = $parametri['str'];
17 3
        $capitalise_first_char = isset($parametri['primamaiuscola']) ? $parametri['primamaiuscola'] : false;
18
19 3
        if ($capitalise_first_char) {
20 3
            $str[0] = strtoupper($str[0]);
21
        }
22
        $func = function ($matches) {
23 2
            return strtoupper($matches[1]);
24 3
        };
25
26 3
        return preg_replace_callback('/_([a-z])/', $func, $str);
27
    }
28
29
      /**
30
        * Transforms an under_scored_string to a camelCasedOne
31
        */
32
    /*function camelize($scored) {
33
        return lcfirst(
34
        implode(
35
            '',
36
            array_map(
37
            'ucfirst',
38
            array_map(
39
                'strtolower',
40
                explode(
41
                '_', $scored)))));
42
    }*/
43
44
    /**
45
     * Transforms a camelCasedString to an under_scored_one
46
    */
47
    public static function underscore($cameled)
48
    {
49
        return implode(
50
            '_',
51
            array_map(
52
                'strtolower',
53
                preg_split('/([A-Z]{1}[^A-Z]*)/', $cameled, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY)
0 ignored issues
show
Bug introduced by
It seems like preg_split('/([A-Z]{1}[^...ng\PREG_SPLIT_NO_EMPTY) can also be of type false; however, parameter $arr1 of array_map() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

53
                /** @scrutinizer ignore-type */ preg_split('/([A-Z]{1}[^A-Z]*)/', $cameled, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY)
Loading history...
54
            )
55
        );
56
    }
57
}
58