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; } }