Completed
Push — master ( 47ade2...461ffe )
by João Felipe Magro
04:47
created

NumberUtil::convertToDouble()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace Ipag\Classes\Util;
4
5
final class NumberUtil
6
{
7
    /**
8
     * @param mixed $number
9
     * @return float
10
     */
11
    public function convertToDouble($number)
12
    {
13
        $number = str_replace(',', '.', (string) $number);
14
15
        if (!is_numeric($number)) {
16
            throw new \UnexpectedValueException("{$number} não é um número válido");
17
        }
18
19
        return (float) number_format($number, 2, '.', '');
20
    }
21
22
    /**
23
     * @param string $string
24
     * @return string
25
     */
26
    public function getOnlyNumbers($string)
27
    {
28
        return (string) preg_replace('/\D/', '', $string);
29
    }
30
}
31