is_negative()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 6
ccs 3
cts 3
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 55
    if ($value === false) {
12 1
        $value = -1;
13
    }
14 55
    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 85
    if ($value < $min) {
28 4
        $value = $min;
29 81
    } elseif ($value > $max) {
30 5
        $value = $max;
31
    }
32 85
    return $value;
33
}
34
35
/**
36
 * @param string $numeric
37
 * @return string
38
 */
39
function trim_zeros(string $numeric): string
40
{
41
    $numeric =
42 17
        \ltrim(
43 17
            false !== \strpos($numeric, '.') ? \rtrim(\rtrim($numeric, '0'), '.') : $numeric,
44 17
            '0, '
45
        );
46
    return
47 17
        '' === $numeric ? '0' : $numeric;
48
}
49