Double::filterSingle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 9.8666
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3
1
<?php
2
declare(strict_types=1);
3
namespace Sirius\Filtration\Filter;
4
5
class Double extends AbstractFilter
6
{
7
    const OPTION_PRECISION = 'precision';
8
9
    protected $options = [
10
        self::OPTION_PRECISION => 2
11
    ];
12
13 3
    public function filterSingle($value, string $valueIdentifier = null)
14
    {
15 3
        if (is_object($value)) {
16 1
            return $value;
17
        }
18 2
        if ($value == 0) {
19 1
            return 0;
20
        }
21 1
        $value = floatval($value);
22 1
        $multiplier = pow(10, (int) $this->options['precision']);
23 1
        return round($value * $multiplier) / $multiplier;
24
    }
25
}
26