Passed
Push — master ( 221c35...fdb910 )
by Petr
02:59
created

Integers::normalize()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 3

Importance

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