Skip to content

Commit

Permalink
Refactor it a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioribeiro committed May 17, 2020
1 parent 147b3e6 commit a036897
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/InstrumentationKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function __construct()
$this->setInstrumentationKey();
}


/**
* @throws InvalidMSInstrumentationKeyException
*
Expand Down Expand Up @@ -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;
}
}

0 comments on commit a036897

Please sign in to comment.