Completed
Pull Request — master (#997)
by Andrzej
02:14
created

Timer::resetTimer()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Robo\Common;
4
5
trait Timer
6
{
7
    /**
8
     * @var \Robo\Common\TimeKeeper|null
9
     */
10
    protected $timer;
11
12
    protected function startTimer()
13
    {
14
        if (!isset($this->timer)) {
15
            $this->timer = new TimeKeeper();
16
        }
17
        $this->timer->start();
18
    }
19
20
    protected function stopTimer()
21
    {
22
        if (!isset($this->timer)) {
23
            return;
24
        }
25
        $this->timer->stop();
26
    }
27
28
    protected function resetTimer()
29
    {
30
        $this->timer->reset();
31
    }
32
33
    /**
34
     * @return float|null
35
     */
36
    protected function getExecutionTime()
37
    {
38
        if (!isset($this->timer)) {
39
            return null;
40
        }
41
        return $this->timer->elapsed();
42
    }
43
}
44