Passed
Pull Request — master (#480)
by Def
02:10
created

NumericHelper::normalize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 4
c 2
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Helper;
6
7
use Yiisoft\Db\Exception\InvalidArgumentException;
8
9
final class NumericHelper
10
{
11
    /**
12
     * Returns string representation of a number value without thousands separators and with dot as decimal separator.
13
     *
14
     * @param float|string $value
15
     *
16
     * @return string
17
     */
18
    public static function normalize(float|string $value): string
19
    {
20
        if (is_float($value)) {
21
            $value = (string)$value;
22
        }
23
24
        $value = str_replace([' ', ','], ['', '.'], $value);
25
        return preg_replace('/\.(?=.*\.)/', '', $value);
26
    }
27
}
28