Completed
Push — master ( fefd2b...bbdd37 )
by Vincenzo
02:31
created

TextFormatter::snakeToCamelCase()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 7
nc 2
nop 2
1
<?php
2
namespace App\Lib\Helpers;
3
4
5
/**
6
 * Class TextFormatter
7
 * @package App\Lib\Helpers
8
 */
9
class TextFormatter
10
{
11
12
    /**
13
     * @param $currencyString
14
     * @return float
15
     */
16
    public static function currencyStringToFloat($currencyString)
17
    {
18
        //currency is always in this format € 550
19
20
        return floatval(
21
            str_replace(
22
                ',',
23
                '',
24
                RegExp::getFirstMatch(
25
                    '/([+-]?[0-9]{1,3}(?:,?[0-9]{3})*(?:\.[0-9]{2})?)/',
26
                    $currencyString
27
                )
28
            )
29
        );
30
    }
31
32
    /**
33
     * @param $string
34
     * @param bool $ucFirst
35
     * @return string
36
     */
37
    public static function snakeToCamelCase($string, $ucFirst = true)
38
    {
39
        $string = preg_replace_callback("/(?:^|_)([a-z])/", function ($matches) {
40
            return strtoupper($matches[1]);
41
        }, $string);
42
43
        if (!$ucFirst) {
44
            $string = lcfirst($string);
45
        }
46
        return $string;
47
    }
48
49
}