Passed
Push — master ( 03282d...f5631a )
by Alexander
32:32 queued 17:38
created

Timer::start()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
namespace App;
3
4
final class Timer
5
{
6
    private array $timers = [];
7
8
    public function start(string $name): void
9
    {
10
        $this->timers[$name] = microtime(true);
11
    }
12
13
    public function get(string $name): float
14
    {
15
        if (!array_key_exists($name, $this->timers)) {
16
            throw new \InvalidArgumentException("There is no \"$name\" timer started");
17
        }
18
19
        return microtime(true) - $this->timers[$name];
20
    }
21
}
22