From 5c25139f7c7ed5dc8af8985ffb4dfd1adf269545 Mon Sep 17 00:00:00 2001 From: Philipp Wahala Date: Mon, 13 May 2024 09:55:19 +0200 Subject: [PATCH] [Stopwatch] Add `getLastPeriod` method to `StopwatchEvent` --- src/Symfony/Component/Stopwatch/CHANGELOG.md | 5 +++++ src/Symfony/Component/Stopwatch/StopwatchEvent.php | 12 ++++++++++++ src/Symfony/Component/Stopwatch/StopwatchPeriod.php | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/Stopwatch/CHANGELOG.md b/src/Symfony/Component/Stopwatch/CHANGELOG.md index f2fd7d0f03de..f0f2e7fc1acc 100644 --- a/src/Symfony/Component/Stopwatch/CHANGELOG.md +++ b/src/Symfony/Component/Stopwatch/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +7.2 +--- + + * Add method `getLastPeriod()` to `StopwatchEvent` + 5.2 --- diff --git a/src/Symfony/Component/Stopwatch/StopwatchEvent.php b/src/Symfony/Component/Stopwatch/StopwatchEvent.php index 08be48924f2f..b2e201c4ede2 100644 --- a/src/Symfony/Component/Stopwatch/StopwatchEvent.php +++ b/src/Symfony/Component/Stopwatch/StopwatchEvent.php @@ -136,6 +136,18 @@ public function getPeriods(): array return $this->periods; } + /** + * Gets the last event period. + */ + public function getLastPeriod(): ?StopwatchPeriod + { + if ([] === $this->periods) { + return null; + } + + return $this->periods[array_key_last($this->periods)]; + } + /** * Gets the relative time of the start of the first period in milliseconds. */ diff --git a/src/Symfony/Component/Stopwatch/StopwatchPeriod.php b/src/Symfony/Component/Stopwatch/StopwatchPeriod.php index 41e8dccb77f9..ef2672ff55d6 100644 --- a/src/Symfony/Component/Stopwatch/StopwatchPeriod.php +++ b/src/Symfony/Component/Stopwatch/StopwatchPeriod.php @@ -12,7 +12,7 @@ namespace Symfony\Component\Stopwatch; /** - * Represents an Period for an Event. + * Represents a Period for an Event. * * @author Fabien Potencier */