diff --git a/src/Symfony/Component/Stopwatch/CHANGELOG.md b/src/Symfony/Component/Stopwatch/CHANGELOG.md index f2fd7d0f03de1..f0f2e7fc1acce 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 08be48924f2f4..b2e201c4ede2b 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 41e8dccb77f93..ef2672ff55d67 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 */