Skip to content

Commit 2ea870f

Browse files
committed
feature symfony#54855 [Stopwatch] Add getLastPeriod method to StopwatchEvent (hacfi)
This PR was merged into the 7.2 branch. Discussion ---------- [Stopwatch] Add `getLastPeriod` method to `StopwatchEvent` | Q | A | ------------- | --- | Branch? | 7.1 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | - | License | MIT It's often useful to just get the last period (if you start and stop an event several times). ### Example https://github.com/doctrine/migrations/blob/3.7.x/lib/Doctrine/Migrations/Version/DbalExecutor.php#L167-L168 This adds a simple `getLastPeriod` method on the `StopwatchEvent` class. Commits ------- 5c25139 [Stopwatch] Add `getLastPeriod` method to `StopwatchEvent`
2 parents b94aad4 + 5c25139 commit 2ea870f

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)