Passed
Push — master ( 98954f...37aea2 )
by Andrea
16:13 queued 12s
created

StringUtils   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 31
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toCamelCase() 0 13 3
A underscore() 0 3 1
1
<?php
2
3
namespace Cdf\BiCoreBundle\Utils\String;
4
5
use Symfony\Component\String\UnicodeString;
6
7
class StringUtils
8
{
9
10
    /**
11
     * Translates a string with underscores into camel case (e.g. first_name -&gt; firstName).
12
     *
13
     * @param array<mixed> $parametri
14
     *
15
     * @return string $str translated into camel caps
16
     */
17 3
    public static function toCamelCase($parametri = array()): string
18
    {
19 3
        $str = $parametri['str'];
20 3
        $capitalise_first_char = isset($parametri['primamaiuscola']) ? $parametri['primamaiuscola'] : false;
21
22 3
        if ($capitalise_first_char) {
23 3
            $str[0] = strtoupper($str[0]);
24
        }
25 3
        $func = function ($matches) {
26 2
            return strtoupper($matches[1]);
27 3
        };
28
29 3
        return preg_replace_callback('/_([a-z])/', $func, $str);
30
    }
31
32
    /**
33
     * Transforms a camelCasedString to an under_scored_one
34
     */
35
    public static function underscore(string $cameled): string
36
    {
37
        return (new UnicodeString($cameled))->snake();
38
    }
39
}
40