Passed
Push — master ( 976aad...1511ac )
by Aleksandr
01:47
created

BenchmarkService::result()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: alex
5
 * Date: 17.11.5
6
 * Time: 13.56
7
 */
8
9
namespace San4io\RequestLogger\Services;
10
11
/**
12
 * Class TimeService
13
 * @package San4io\RequestLogger\Services
14
 */
15
class BenchmarkService
16
{
17
    /**
18
     * @var mixed
19
     */
20
    protected $startTime = LARAVEL_START;
0 ignored issues
show
Bug introduced by
The constant San4io\RequestLogger\Services\LARAVEL_START was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
21
22
    /**
23
     * @var
24
     */
25
    protected $endTime;
26
27
    /**
28
     * @var string
29
     */
30
    protected $name;
31
32
    /**
33
     * TimeService constructor.
34
     * @param string $name
35
     */
36
    public function __construct(string $name)
37
    {
38
        $this->name = $name;
39
    }
40
41
    /**
42
     * Get result
43
     * @return mixed
44
     */
45
    public function result()
46
    {
47
        if (!$this->endTime) {
48
            $this->stop();
49
        }
50
51
        return $this->endTime - $this->startTime;
52
    }
53
54
    /**
55
     * Start measure
56
     */
57
    public function start()
58
    {
59
        $this->startTime = microtime(true);
60
    }
61
62
    /**
63
     * End measure
64
     */
65
    public function stop()
66
    {
67
        $this->endTime = microtime(true);
68
    }
69
70
}