StopWatch   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A start() 0 3 1
A stop() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the PHPProm package.
5
 *
6
 * (c) Philip Lehmann-Böhm <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PHPProm;
13
14
use PHPProm\Storage\AbstractStorage;
15
16
/**
17
 * Class StopWatch
18
 * Small utility class to measure the time of something.
19
 * @package PHPProm
20
 */
21
class StopWatch {
22
23
    /**
24
     * @var AbstractStorage
25
     * the storage to store the result at
26
     */
27
    protected $storage;
28
29
    /**
30
     * @var float
31
     * the moment the measurement started
32
     */
33
    protected $start;
34
35
    /**
36
     * StopWatch constructor.
37
     * @param AbstractStorage $storage
38
     * the storage to store the result at
39
     */
40
    public function __construct(AbstractStorage $storage) {
41
        $this->storage = $storage;
42
    }
43
44
    /**
45
     * To start the measurement.
46
     */
47
    public function start() {
48
        $this->start = microtime(true);
49
    }
50
51
    /**+
52
     * To stop and store the measurement as float seconds.
53
     *
54
     * @param string $metric
55
     * the name of the metric
56
     * @param string $key
57
     * the key
58
     */
59
    public function stop($metric, $key) {
60
        $time = microtime(true) - $this->start;
61
        $this->storage->storeMeasurement($metric, $key, $time);
62
    }
63
64
}
65