Completed
Push — master ( 4c5280...5cdc1d )
by Alec
08:43
created

trim_zeros()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace AlecRabbit\Helpers;
4
5
/**
6
 * @param bool|float|int|null $value
7
 * @return bool
8
 */
9
function is_negative($value): bool
10
{
11 53
    if ($value === false) {
12 1
        $value = -1;
13
    }
14 53
    return ((float)$value < 0);
15
}
16
17
/**
18
 * Puts value in bounds
19
 *
20
 * @param float $value
21
 * @param float $min [optional] Default -1
22
 * @param float $max [optional] Default 1
23
 * @return float
24
 */
25
function bounds(float $value, float $min = -1.0, float $max = 1.0): float
26
{
27 86
    if ($value < $min) {
28 4
        $value = $min;
29 82
    } elseif ($value > $max) {
30 5
        $value = $max;
31
    }
32 86
    return $value;
33
}
34
35
/**
36
 * @param string $numeric
37
 * @return string
38
 */
39
function trim_zeros(string $numeric): string
40
{
41 7
    return false !== \strpos($numeric, '.') ? \rtrim(\rtrim($numeric, '0'), '.') : $numeric;
42
}
43