TextFormatter::currencyStringToFloat()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 14
rs 9.4285
cc 1
eloc 8
nc 1
nop 1
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
		//currency is always in this format € 550
18
19
		return floatval(
20
			str_replace(
21
				',',
22
				'',
23
				RegExp::getFirstMatch(
24
					'/([+-]?[0-9]{1,3}(?:,?[0-9]{3})*(?:\.[0-9]{2})?)/',
25
					$currencyString
26
				)
27
			)
28
		);
29
	}
30
31
}