From a036897167517a897c3dd5b67d6c3ec389ae37d0 Mon Sep 17 00:00:00 2001 From: Antonio Carlos Ribeiro Date: Sun, 17 May 2020 18:18:40 +0200 Subject: [PATCH] Refactor it a bit --- src/InstrumentationKey.php | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/InstrumentationKey.php b/src/InstrumentationKey.php index 7fccb7c..e1bd832 100644 --- a/src/InstrumentationKey.php +++ b/src/InstrumentationKey.php @@ -20,7 +20,6 @@ public function __construct() $this->setInstrumentationKey(); } - /** * @throws InvalidMSInstrumentationKeyException * @@ -56,12 +55,23 @@ protected function checkInstrumentationKeyValidity($instrumentationKey) return true; } - if (static::$alreadyThrown) { + if ($this->InvalidKeyExceptionWasNotThrown()) { + throw new InvalidMSInstrumentationKeyException( + "'{$instrumentationKey}' is not a valid Microsoft Application Insights instrumentation key." + ); + } + + return false; + } + + protected function InvalidKeyExceptionWasNotThrown() + { + if (!static::$alreadyThrown) { + static::$alreadyThrown = true; + return false; } - static::$alreadyThrown = true; - - throw new InvalidMSInstrumentationKeyException("'{$instrumentationKey}' is not a valid Microsoft Application Insights instrumentation key."); + return true; } }