From eb573e143e6b5b17efb26fd3e97004736cb66024 Mon Sep 17 00:00:00 2001 From: Andrey Savchenko Date: Mon, 17 Dec 2018 18:15:59 +0200 Subject: [PATCH] Added optional description to Stopwatch records. --- src/Record/Stopwatch_Record.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Record/Stopwatch_Record.php b/src/Record/Stopwatch_Record.php index 5c18e4b..60238ba 100644 --- a/src/Record/Stopwatch_Record.php +++ b/src/Record/Stopwatch_Record.php @@ -16,13 +16,18 @@ class Stopwatch_Record implements Record_Interface { /** @var StopwatchEvent */ protected $stopwatch_event; + /** @var string */ + protected $description = ''; + /** * @param string $name Event name. * @param StopwatchEvent $stopwatch_event Stopwatch event instance. + * @param string $description Optional description for the event. */ - public function __construct( string $name, StopwatchEvent $stopwatch_event ) { + public function __construct( string $name, StopwatchEvent $stopwatch_event, string $description = '' ) { $this->name = $name; $this->stopwatch_event = $stopwatch_event; + $this->description = $description; } /** @@ -37,10 +42,11 @@ class Stopwatch_Record implements Record_Interface { */ public function get_description(): string { - $duration = round( $this->stopwatch_event->getDuration() ); - $memory = $this->stopwatch_event->getMemory() / 1024 / 1024; + $duration = round( $this->stopwatch_event->getDuration() ); + $memory = $this->stopwatch_event->getMemory() / 1024 / 1024; + $description = '' !== $this->description ? "
{$this->description}" : ''; - return "{$this->name} – {$duration} ms – {$memory} MB"; + return "{$this->name} – {$duration} ms – {$memory} MB{$description}"; } /**