From 10f80be40ce20d8d0ecf7da379df5a6f70f8ce5f Mon Sep 17 00:00:00 2001
From: Baspa <hello@baspa.dev>
Date: Tue, 28 May 2024 18:04:56 +0200
Subject: [PATCH] Fix duplicate metric error

---
 src/Traits/Google/MetricTrait.php | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/Traits/Google/MetricTrait.php b/src/Traits/Google/MetricTrait.php
index 64dc23f..1995f3e 100644
--- a/src/Traits/Google/MetricTrait.php
+++ b/src/Traits/Google/MetricTrait.php
@@ -10,6 +10,12 @@ trait MetricTrait
 
     public function addMetric(string $name): self
     {
+        foreach ($this->metrics as $metric) {
+            if ($metric->getName() === $name) {
+                return $this;
+            }
+        }
+
         $this->metrics[] = new Metric([
             'name' => $name,
         ]);
@@ -25,4 +31,4 @@ public function addMetrics(string ...$metrics): self
 
         return $this;
     }
-}
+}
\ No newline at end of file