mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-08-25 03:28:23 +00:00
Dtext exception and improvement over exception InvalidEmail
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -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";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Egulias\EmailValidator\Exception;
|
||||
|
||||
use Egulias\EmailValidator\InvalidEmail;
|
||||
|
||||
class ExpectingDTEXT extends InvalidEmail
|
||||
{
|
||||
const CODE = 129;
|
||||
const REASON = "Expected DTEXT";
|
||||
}
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
namespace Egulias\EmailValidator;
|
||||
|
||||
class InvalidEmail extends \InvalidArgumentException
|
||||
abstract class InvalidEmail extends \InvalidArgumentException
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(static::REASON, static::CODE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace Egulias\EmailValidator\Parser;
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Exception\ConsecutiveAt;
|
||||
use Egulias\EmailValidator\Exception\DotAtStart;
|
||||
use Egulias\EmailValidator\Exception\ExpectingDTEXT;
|
||||
use Egulias\EmailValidator\Parser\Parser;
|
||||
use Egulias\EmailValidator\EmailValidator;
|
||||
|
||||
@@ -19,7 +20,7 @@ class DomainPart extends Parser
|
||||
$this->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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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]"),
|
||||
|
||||
Reference in New Issue
Block a user