Skip to content

Commit 8db7c3d

Browse files
committed
Merge pull request php-debugbar#115 from snapshotpl/has-measure
Adding the possibility to verify whether measure exists
2 parents bcd98fd + 0dc7d01 commit 8db7c3d

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

src/DebugBar/DataCollector/TimeDataCollector.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,25 @@
1818
*/
1919
class TimeDataCollector extends DataCollector implements Renderable
2020
{
21+
22+
/**
23+
* @var float
24+
*/
2125
protected $requestStartTime;
2226

27+
/**
28+
* @var float
29+
*/
2330
protected $requestEndTime;
2431

32+
/**
33+
* @var array
34+
*/
2535
protected $startedMeasures = array();
2636

37+
/**
38+
* @var array
39+
*/
2740
protected $measures = array();
2841

2942
/**
@@ -56,6 +69,17 @@ public function startMeasure($name, $label = null)
5669
);
5770
}
5871

72+
/**
73+
* Check a measure exists
74+
*
75+
* @param string $name
76+
* @return bool
77+
*/
78+
public function hasStartedMeasure($name)
79+
{
80+
return isset($this->startedMeasures[$name]);
81+
}
82+
5983
/**
6084
* Stops a measure
6185
*
@@ -64,7 +88,7 @@ public function startMeasure($name, $label = null)
6488
public function stopMeasure($name)
6589
{
6690
$end = microtime(true);
67-
if (!isset($this->startedMeasures[$name])) {
91+
if (!$this->hasStartedMeasure($name)) {
6892
throw new DebugBarException("Failed stopping measure '$name' because it hasn't been started");
6993
}
7094
$this->addMeasure($this->startedMeasures[$name]['label'], $this->startedMeasures[$name]['start'], $end);

0 commit comments

Comments
 (0)