Created
November 3, 2023 20:41
-
-
Save richardDobron/b4204b550ee162330b92e42b4f3fb933 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Use invariant() to assert state which your program assumes to be true. | |
* | |
* @throws Exception | |
*/ | |
function invariant(mixed $condition, string $message = 'Invariant Violation', ...$params): void | |
{ | |
if (! $condition) { | |
if (func_num_args() > 2) { | |
$message = sprintf($message, ...$params); | |
} | |
throw new Exception($message); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment