FloatTransformation::apply()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Cerbero\Transformer\Transformations;
4
5
/**
6
 * Transform a value into a float.
7
 *
8
 */
9
class FloatTransformation extends AbstractTransformation
10
{
11
    /**
12
     * Apply the transformation
13
     *
14
     * @param array $parameters
15
     * @return mixed
16
     */
17 27
    public function apply(array $parameters)
18
    {
19 27
        $value = floatval($this->value);
20
21 27
        if (!isset($parameters[0])) {
22 3
            return $value;
23
        }
24
25 27
        $exponent = pow(10, $parameters[0]);
26
27 27
        return floor($value * $exponent) / $exponent;
28
    }
29
}
30