diff --git a/src/Egulias/EmailValidator/EmailValidator.php b/src/Egulias/EmailValidator/EmailValidator.php index cb3e7a0..40892df 100644 --- a/src/Egulias/EmailValidator/EmailValidator.php +++ b/src/Egulias/EmailValidator/EmailValidator.php @@ -11,8 +11,6 @@ use Egulias\EmailValidator\InvalidEmail; */ class EmailValidator { - const ERR_DOMAINHYPHENSTART = 143; - const ERR_DOMAINHYPHENEND = 144; const ERR_UNCLOSEDQUOTEDSTR = 145; const ERR_UNCLOSEDCOMMENT = 146; const ERR_UNCLOSEDDOMLIT = 147; diff --git a/src/Egulias/EmailValidator/Exception/DomainHyphened.php b/src/Egulias/EmailValidator/Exception/DomainHyphened.php new file mode 100644 index 0000000..1b496ff --- /dev/null +++ b/src/Egulias/EmailValidator/Exception/DomainHyphened.php @@ -0,0 +1,11 @@ +lexer->token['type'] === EmailLexer::S_HYPHEN) { - throw new \InvalidArgumentException('ERR_DOMAINHYPHENEND'); + throw new DomainHyphened(); } if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) { @@ -48,7 +49,7 @@ class DomainPart extends Parser throw new DotAtEnd(); } if ($prev['type'] === EmailLexer::S_HYPHEN) { - throw new \InvalidArgumentException('ERR_DOMAINHYPHENEND'); + throw new DomainHyphened(); } if ($length > self::DOMAIN_MAX_LENGTH) { $this->warnings[] = EmailValidator::RFC5322_DOMAIN_TOOLONG; @@ -274,7 +275,7 @@ class DomainPart extends Parser } if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) { - throw new \InvalidArgumentException('ERR_DOMAINHYPHENEND'); + throw new DomainHyphened(); } if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH diff --git a/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php b/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php index 8ab9bee..17700b0 100644 --- a/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php +++ b/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php @@ -6,6 +6,7 @@ use Egulias\EmailValidator\EmailValidator; use Egulias\EmailValidator\Exception\AtextAfterCFWS; use Egulias\EmailValidator\Exception\ConsecutiveAt; use Egulias\EmailValidator\Exception\ConsecutiveDot; +use Egulias\EmailValidator\Exception\DomainHyphened; use Egulias\EmailValidator\Exception\DotAtEnd; use Egulias\EmailValidator\Exception\DotAtStart; use Egulias\EmailValidator\Exception\ExpectingATEXT; @@ -150,8 +151,8 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase return array( array(NoLocalPart::CODE, '@example.co.uk'), array(NoDomainPart::CODE, 'example@'), - array(EmailValidator::ERR_DOMAINHYPHENEND, 'example@example-.co.uk'), - array(EmailValidator::ERR_DOMAINHYPHENEND, 'example@example-'), + array(DomainHyphened::CODE, 'example@example-.co.uk'), + array(DomainHyphened::CODE, 'example@example-'), array(ConsecutiveAt::CODE, 'example@@example.co.uk'), array(ConsecutiveDot::CODE, 'example..example@example.co.uk'), array(ConsecutiveDot::CODE, 'example@example..co.uk'),