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

Timer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 6
c 1
b 0
f 0
dl 0
loc 16
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
A start() 0 3 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