NumberUtil   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getOnlyNumbers() 0 3 1
A convertToDouble() 0 9 2
1
<?php
2
3
namespace Ipag\Classes\Util;
4
5
final class NumberUtil
6
{
7
    /**
8
     * @param mixed $number
9
     *
10
     * @return float
11
     */
12
    public function convertToDouble($number)
13
    {
14
        $number = str_replace(',', '.', (string) $number);
15
16
        if (!is_numeric($number)) {
17
            throw new \UnexpectedValueException("{$number} não é um número válido");
18
        }
19
20
        return (float) number_format($number, 2, '.', '');
0 ignored issues
show
Bug introduced by
$number of type string is incompatible with the type double expected by parameter $num of number_format(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

20
        return (float) number_format(/** @scrutinizer ignore-type */ $number, 2, '.', '');
Loading history...
21
    }
22
23
    /**
24
     * @param string $string
25
     *
26
     * @return string
27
     */
28
    public function getOnlyNumbers($string)
29
    {
30
        return (string) preg_replace('/\D/', '', $string);
31
    }
32
}
33