Passed
Push — master ( 864fd9...c2eae6 )
by Sébastien
03:26
created

NumberConversion   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 3
eloc 5
dl 0
loc 14
ccs 5
cts 7
cp 0.7143
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A truncateFloat() 0 8 2
A __construct() 0 2 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @see       https://github.com/soluble-io/soluble-mediatools for the canonical repository
7
 *
8
 * @copyright Copyright (c) 2018-2019 Sébastien Vanvelthem. (https://github.com/belgattitude)
9
 * @license   https://github.com/soluble-io/soluble-mediatools/blob/master/LICENSE.md MIT
10
 */
11
12
namespace Soluble\MediaTools\Common\Math;
13
14
final class NumberConversion
15
{
16
    private function __construct()
17
    {
18
    }
19
20 2
    public static function truncateFloat(float $number, int $decimals): float
21
    {
22 2
        $power = 10 ** $decimals;
23 2
        if ($number > 0) {
24 2
            return floor($number * $power) / $power;
25
        }
26
27 1
        return ceil($number * $power) / $power;
28
    }
29
}
30