diff --git a/src/Egulias/EmailValidator/EmailValidator.php b/src/Egulias/EmailValidator/EmailValidator.php index 81eda17..8228730 100644 --- a/src/Egulias/EmailValidator/EmailValidator.php +++ b/src/Egulias/EmailValidator/EmailValidator.php @@ -11,7 +11,6 @@ use Egulias\EmailValidator\InvalidEmail; */ class EmailValidator { - const ERR_EXPECTING_DTEXT = 129; const ERR_NOLOCALPART = 130; const ERR_NODOMAIN = 131; const ERR_CONSECUTIVEDOTS = 132; diff --git a/src/Egulias/EmailValidator/Exception/ConsecutiveAt.php b/src/Egulias/EmailValidator/Exception/ConsecutiveAt.php index 8fa19ab..9c20fe6 100644 --- a/src/Egulias/EmailValidator/Exception/ConsecutiveAt.php +++ b/src/Egulias/EmailValidator/Exception/ConsecutiveAt.php @@ -7,9 +7,5 @@ use Egulias\EmailValidator\InvalidEmail; class ConsecutiveAt extends InvalidEmail { const CODE = 128; - - public function __construct() - { - parent::__construct("Consecutive AT", self::CODE); - } + const REASON = "Consecutive AT"; } diff --git a/src/Egulias/EmailValidator/Exception/DotAtStart.php b/src/Egulias/EmailValidator/Exception/DotAtStart.php index 6aa3324..d16301a 100644 --- a/src/Egulias/EmailValidator/Exception/DotAtStart.php +++ b/src/Egulias/EmailValidator/Exception/DotAtStart.php @@ -7,9 +7,5 @@ use Egulias\EmailValidator\InvalidEmail; class DotAtStart extends InvalidEmail { const CODE = 141; - - public function __construct($part) - { - parent::__construct("Found DOT at start in " . $part, self::CODE); - } + const REASON = "Found DOT at start"; } diff --git a/src/Egulias/EmailValidator/Exception/ExpectingDTEXT.php b/src/Egulias/EmailValidator/Exception/ExpectingDTEXT.php new file mode 100644 index 0000000..b175f59 --- /dev/null +++ b/src/Egulias/EmailValidator/Exception/ExpectingDTEXT.php @@ -0,0 +1,11 @@ +lexer->moveNext(); if ($this->lexer->token['type'] === EmailLexer::S_DOT) { - throw new DotAtStart('domain'); + throw new DotAtStart(); } if ($this->lexer->token['type'] === EmailLexer::S_EMPTY) { @@ -160,7 +161,7 @@ class DomainPart extends Parser $addressLiteral = ''; do { if ($this->lexer->token['type'] === EmailLexer::C_NUL) { - throw new \InvalidArgumentException('ERR_EXPECTING_DTEXT'); + throw new ExpectingDTEXT(); } if ($this->lexer->token['type'] === EmailLexer::INVALID || @@ -171,7 +172,7 @@ class DomainPart extends Parser } if ($this->lexer->isNextTokenAny(array(EmailLexer::S_OPENQBRACKET, EmailLexer::S_OPENBRACKET))) { - throw new \InvalidArgumentException('ERR_EXPECTING_DTEXT'); + throw new ExpectingDTEXT(); } if ($this->lexer->isNextTokenAny( diff --git a/src/Egulias/EmailValidator/Parser/LocalPart.php b/src/Egulias/EmailValidator/Parser/LocalPart.php index d42894f..45a4682 100644 --- a/src/Egulias/EmailValidator/Parser/LocalPart.php +++ b/src/Egulias/EmailValidator/Parser/LocalPart.php @@ -17,7 +17,7 @@ class LocalPart extends Parser while ($this->lexer->token['type'] !== EmailLexer::S_AT && $this->lexer->token) { if ($this->lexer->token['type'] === EmailLexer::S_DOT && !$this->lexer->getPrevious()) { - throw new DotAtStart('local'); + throw new DotAtStart(); } $closingQuote = $this->checkDQUOTE($closingQuote); diff --git a/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php b/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php index 3c751b0..4168847 100644 --- a/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php +++ b/tests/egulias/Tests/EmailValidator/EmailValidatorTest.php @@ -5,6 +5,7 @@ namespace Egulias\Tests\EmailValidator; use Egulias\EmailValidator\EmailValidator; use Egulias\EmailValidator\Exception\ConsecutiveAt; use Egulias\EmailValidator\Exception\DotAtStart; +use Egulias\EmailValidator\Exception\ExpectingDTEXT; class EmailValidatorTest extends \PHPUnit_Framework_TestCase { @@ -159,7 +160,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase //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(EmailValidator::ERR_EXPECTING_DTEXT, "example@[[]"), + array(ExpectingDTEXT::CODE, "example@[[]"), array(EmailValidator::ERR_ATEXT_AFTER_CFWS, "exampl\te@example.co.uk"), array(EmailValidator::ERR_CR_NO_LF, "example@exa\rmple.co.uk"), array(EmailValidator::ERR_CR_NO_LF, "example@[\r]"),