Skip to content

Commit 5c25139

Browse files
committed
[Stopwatch] Add getLastPeriod method to StopwatchEvent
1 parent 5a00a8b commit 5c25139

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/Symfony/Component/Stopwatch/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.2
5+
---
6+
7+
* Add method `getLastPeriod()` to `StopwatchEvent`
8+
49
5.2
510
---
611

src/Symfony/Component/Stopwatch/StopwatchEvent.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ public function getPeriods(): array
136136
return $this->periods;
137137
}
138138

139+
/**
140+
* Gets the last event period.
141+
*/
142+
public function getLastPeriod(): ?StopwatchPeriod
143+
{
144+
if ([] === $this->periods) {
145+
return null;
146+
}
147+
148+
return $this->periods[array_key_last($this->periods)];
149+
}
150+
139151
/**
140152
* Gets the relative time of the start of the first period in milliseconds.
141153
*/

src/Symfony/Component/Stopwatch/StopwatchPeriod.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Symfony\Component\Stopwatch;
1313

1414
/**
15-
* Represents an Period for an Event.
15+
* Represents a Period for an Event.
1616
*
1717
* @author Fabien Potencier <[email protected]>
1818
*/

0 commit comments

Comments
 (0)