diff --git a/src/Egulias/EmailValidator/EmailValidator.php b/src/Egulias/EmailValidator/EmailValidator.php index 2541528..c07aeea 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_CONSECUTIVEDOTS = 132; - const ERR_ATEXT_AFTER_CFWS = 133; const ERR_ATEXT_AFTER_QS = 134; const ERR_ATEXT_AFTER_DOMLIT = 135; const ERR_EXPECTING_QPAIR = 136; diff --git a/src/Egulias/EmailValidator/Exception/AtextAfterCFWS.php b/src/Egulias/EmailValidator/Exception/AtextAfterCFWS.php new file mode 100644 index 0000000..e9f9dd6 --- /dev/null +++ b/src/Egulias/EmailValidator/Exception/AtextAfterCFWS.php @@ -0,0 +1,11 @@ +lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] !== EmailLexer::S_AT) { - throw new \InvalidArgumentException("ERR_ATEXT_AFTER_CFWS"); + throw new AtextAfterCFWS(); } if ($this->lexer->token['type'] === EmailLexer::S_LF || $this->lexer->token['type'] === EmailLexer::C_NUL) { diff --git a/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php b/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php index 0ccf121..781831d 100644 --- a/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php +++ b/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php @@ -3,7 +3,9 @@ namespace Egulias\Tests\EmailValidator; use Egulias\EmailValidator\EmailValidator; +use Egulias\EmailValidator\Exception\AtextAfterCFWS; use Egulias\EmailValidator\Exception\ConsecutiveAt; +use Egulias\EmailValidator\Exception\ConsecutiveDot; use Egulias\EmailValidator\Exception\DotAtStart; use Egulias\EmailValidator\Exception\ExpectingDTEXT; use Egulias\EmailValidator\Exception\NoDomainPart; @@ -149,8 +151,8 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase array(EmailValidator::ERR_DOMAINHYPHENEND, 'example@example-.co.uk'), array(EmailValidator::ERR_DOMAINHYPHENEND, 'example@example-'), array(ConsecutiveAt::CODE, 'example@@example.co.uk'), - array(EmailValidator::ERR_CONSECUTIVEDOTS, 'example..example@example.co.uk'), - array(EmailValidator::ERR_CONSECUTIVEDOTS, 'example@example..co.uk'), + array(ConsecutiveDot::CODE, 'example..example@example.co.uk'), + array(ConsecutiveDot::CODE, 'example@example..co.uk'), array(EmailValidator::ERR_EXPECTING_ATEXT, '@example.fr'), array(DotAtStart::CODE, '.example@localhost'), array(DotAtStart::CODE, 'example@.localhost'), @@ -161,9 +163,9 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase array(EmailValidator::ERR_EXPECTING_ATEXT, 'exa"mple@localhost'), //This was the original. But atext is not allowed after \n //array(EmailValidator::ERR_EXPECTING_ATEXT, "exampl\ne@example.co.uk"), - array(EmailValidator::ERR_ATEXT_AFTER_CFWS, "exampl\ne@example.co.uk"), + array(AtextAfterCFWS::CODE, "exampl\ne@example.co.uk"), array(ExpectingDTEXT::CODE, "example@[[]"), - array(EmailValidator::ERR_ATEXT_AFTER_CFWS, "exampl\te@example.co.uk"), + array(AtextAfterCFWS::CODE, "exampl\te@example.co.uk"), array(EmailValidator::ERR_CR_NO_LF, "example@exa\rmple.co.uk"), array(EmailValidator::ERR_CR_NO_LF, "example@[\r]"), array(EmailValidator::ERR_CR_NO_LF, "exam\rple@example.co.uk"),