Duration   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 61
ccs 25
cts 25
cp 1
rs 10
wmc 11

11 Methods

Rating   Name   Duplication   Size   Complexity  
A asWeek() 0 3 1
A as() 0 3 1
A asDay() 0 3 1
A asMicrosecond() 0 3 1
A __construct() 0 5 1
A diff() 0 3 1
A asSecond() 0 3 1
A asMillisecond() 0 3 1
A asNanosecond() 0 3 1
A asHour() 0 3 1
A asMinute() 0 3 1
1
<?php
2
3
/**
4
 * For the full copyright and license information, please view
5
 * the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types=1);
9
10
namespace loophp\nanobench\Time;
11
12
final class Duration extends AbstractTime
13
{
14
    private TimeInterface $from;
15
16
    private TimeInterface $to;
17
18 12
    public function __construct(TimeInterface $from, TimeInterface $to, string $unit = TimeUnit::SECOND)
19
    {
20 12
        $this->from = $from;
21 12
        $this->to = $to;
22 12
        $this->unit = $unit;
23 12
    }
24
25 1
    public function as(string $timeUnit): float
26
    {
27 1
        return $this->diff()->as($timeUnit);
28
    }
29
30 1
    public function asDay(): float
31
    {
32 1
        return $this->diff()->asDay();
33
    }
34
35 1
    public function asHour(): float
36
    {
37 1
        return $this->diff()->asHour();
38
    }
39
40 1
    public function asMicrosecond(): float
41
    {
42 1
        return $this->diff()->asMicrosecond();
43
    }
44
45 11
    public function asMillisecond(): float
46
    {
47 11
        return $this->diff()->asMillisecond();
48
    }
49
50 1
    public function asMinute(): float
51
    {
52 1
        return $this->diff()->asMinute();
53
    }
54
55 1
    public function asNanosecond(): float
56
    {
57 1
        return $this->diff()->asNanosecond();
58
    }
59
60 2
    public function asSecond(): float
61
    {
62 2
        return $this->diff()->asSecond();
63
    }
64
65 1
    public function asWeek(): float
66
    {
67 1
        return $this->diff()->asWeek();
68
    }
69
70 12
    private function diff(): TimeInterface
71
    {
72 12
        return new Time(abs($this->from->asSecond() - $this->to->asSecond()));
73
    }
74
}
75