Numbers::normalize()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 21
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 16
c 0
b 0
f 0
dl 0
loc 21
ccs 19
cts 19
cp 1
rs 9.7333
cc 3
nc 2
nop 2
crap 3
1
<?php
2
3
namespace Riesenia\Pohoda\Common\OptionsResolver\Normalizers;
4
5
class Numbers extends AbstractNormalizer
6
{
7 50
    public function normalize(mixed $options, mixed $value): string
8
    {
9 50
        $preform = \strval(
10 50
            \preg_replace(
11 50
                '/[^0-9,.-]/',
12 50
                '',
13 50
                \strval($value),
14 50
            ),
15 50
        );
16 50
        if ($this->nullable && empty(\strlen($preform))) {
17 1
            return '';
18
        }
19 50
        return \str_replace(
20 50
            ',',
21 50
            '.',
22 50
            \strval(
23 50
                \floatval(
24 50
                    \str_replace(
25 50
                        ',',
26 50
                        '.',
27 50
                        $preform,
28 50
                    ),
29 50
                ),
30 50
            ),
31 50
        );
32
    }
33
}
34