Created
October 16, 2018 09:12
-
-
Save pelshoff/b677bfcce7c2b9bb22feed83a677c11e 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 | |
class InvalidEmail extends DomainException | |
{ | |
public static function becauseItDoesNotMatchEmailSpec(string $emailAddress): self | |
{ | |
throw new self(sprintf('%s does not conform to a recognized e-mail address format'), $emailAddress); | |
} | |
public static function becauseTldIsNotAllowed(string $emailAddress): self | |
{ | |
throw new self(sprintf('The tld of %s is not allowed'), $emailAddress); | |
} | |
public static function becauseItWasBanned(string $emailAddress, Date $onDate): self | |
{ | |
throw new self(sprintf('The e-mail address %s was banned on %s and is not acceptable for the purposes of this amazing system we have here'), $emailAddress, $onDate->asString()); | |
} | |
} |
Minor suggestion: return new self(...);
and throw it at the site of the error, keeps stack traces a little shorter
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
<3 <3 <3