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

NumberUtil::getOnlyNumbers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
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