Test Failed
Push — main ( d01f4c...5af89f )
by Bingo
15:56
created

TimeUnit::toNanos()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 22
rs 8.4444
c 1
b 0
f 0
cc 8
nc 8
nop 2
1
<?php
2
3
namespace Jabe\Engine\Impl\Util\Concurrent;
4
5
class TimeUnit
6
{
7
    public const DAYS = 'days';
8
    public const HOURS = 'hours';
9
    public const MICROSECONDS = 'microseconds';
10
    public const MILLISECONDS = 'milliseconds';
11
    public const MINUTES = 'minutes';
12
    public const NANOSECONDS = 'nanoseconds';
13
    public const SECONDS = 'seconds';
14
15
    public static function toNanos(int $duration, string $units): int
16
    {
17
        if (strtolower($units) == self::DAYS) {
18
            return $duration * 86400000000000;
19
        }
20
        if (strtolower($units) == self::HOURS) {
21
            return $duration * 3600000000000;
22
        }
23
        if (strtolower($units) == self::MICROSECONDS) {
24
            return $duration * 1000;
25
        }
26
        if (strtolower($units) == self::MILLISECONDS) {
27
            return $duration * 1000000;
28
        }
29
        if (strtolower($units) == self::MINUTES) {
30
            return $duration * 60000000000;
31
        }
32
        if (strtolower($units) == self::NANOSECONDS) {
33
            return $duration;
34
        }
35
        if (strtolower($units) == self::SECONDS) {
36
            return $duration * 1000000000;
37
        }
0 ignored issues
show
Bug Best Practice introduced by
The function implicitly returns null when the if condition on line 35 is false. This is incompatible with the type-hinted return integer. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
38
    }
39
}
40