mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-09-11 02:26:36 +00:00
Apply feedbacks
This commit is contained in:
+4
-11
@@ -133,30 +133,23 @@ class EmailLexer extends AbstractLexer
|
||||
|
||||
/**
|
||||
* @var Token
|
||||
*
|
||||
* @psalm-var array{value:string, type:null|int, position:int}|array<empty, empty>
|
||||
*/
|
||||
protected $previous = null;
|
||||
|
||||
/**
|
||||
* The last matched/seen token.
|
||||
*
|
||||
* @var object
|
||||
*
|
||||
* @psalm-suppress NonInvariantDocblockPropertyType
|
||||
* @psalm-var array{value:string, type:null|int, position:int}
|
||||
* @psalm-suppress NonInvariantDocblockPropertyType
|
||||
* @var Token
|
||||
*/
|
||||
public $token;
|
||||
|
||||
/**
|
||||
* The next token in the input.
|
||||
*
|
||||
* @var array{position: int, type: int|null|string, value: int|string}|null
|
||||
* @var Token|null
|
||||
*/
|
||||
public $lookahead;
|
||||
|
||||
/** @psalm-var array{value:'', type:null, position:0} */
|
||||
private $nullToken = null;
|
||||
|
||||
/** @var string */
|
||||
@@ -283,9 +276,9 @@ class EmailLexer extends AbstractLexer
|
||||
/**
|
||||
* getPrevious
|
||||
*
|
||||
* @return object
|
||||
* @return Token
|
||||
*/
|
||||
public function getPrevious(): object
|
||||
public function getPrevious(): Token
|
||||
{
|
||||
return $this->previous;
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class MessageIDParser extends Parser
|
||||
protected function preLeftParsing(): Result
|
||||
{
|
||||
if (!$this->hasAtToken()) {
|
||||
return new InvalidEmail(new NoLocalPart(), $this->lexer->value);
|
||||
return new InvalidEmail(new NoLocalPart(), $this->lexer->token->value);
|
||||
}
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ abstract class Parser
|
||||
$this->lexer->setInput($str);
|
||||
|
||||
if ($this->lexer->hasInvalidTokens()) {
|
||||
return new InvalidEmail(new ExpectingATEXT("Invalid tokens found"), $this->lexer->token["value"]);
|
||||
return new InvalidEmail(new ExpectingATEXT("Invalid tokens found"), $this->lexer->token->value);
|
||||
}
|
||||
|
||||
$preParsingResult = $this->preLeftParsing();
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Egulias\EmailValidator\Parser;
|
||||
|
||||
use Doctrine\Common\Lexer\Token;
|
||||
use Egulias\EmailValidator\EmailLexer;
|
||||
use Egulias\EmailValidator\Warning\TLD;
|
||||
use Egulias\EmailValidator\Result\Result;
|
||||
@@ -81,11 +82,11 @@ class DomainPart extends PartParser
|
||||
return new InvalidEmail(new DotAtEnd(), $this->lexer->token->value);
|
||||
}
|
||||
if ($prev->isA(EmailLexer::S_HYPHEN)) {
|
||||
return new InvalidEmail(new DomainHyphened('Hypen found at the end of the domain'), $prev['value']);
|
||||
return new InvalidEmail(new DomainHyphened('Hypen found at the end of the domain'), $prev->value);
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_SP)) {
|
||||
return new InvalidEmail(new CRLFAtTheEnd(), $prev['value']);
|
||||
return new InvalidEmail(new CRLFAtTheEnd(), $prev->value);
|
||||
}
|
||||
return new ValidEmail();
|
||||
}
|
||||
@@ -212,7 +213,7 @@ class DomainPart extends PartParser
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
private function checkNotAllowedChars(object $token): Result
|
||||
private function checkNotAllowedChars(Token $token): Result
|
||||
{
|
||||
$notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH => true];
|
||||
if (isset($notAllowed[$token->type])) {
|
||||
@@ -238,7 +239,7 @@ class DomainPart extends PartParser
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function checkDomainPartExceptions(object $prev, bool $hasComments): Result
|
||||
protected function checkDomainPartExceptions(Token $prev, bool $hasComments): Result
|
||||
{
|
||||
if ($this->lexer->token->isA(EmailLexer::S_OPENBRACKET) && $prev->type !== EmailLexer::S_AT) {
|
||||
return new InvalidEmail(new ExpectingATEXT('OPENBRACKET not after AT'), $this->lexer->token->value);
|
||||
|
||||
@@ -179,7 +179,7 @@ class DNSCheckValidation implements EmailValidation
|
||||
}
|
||||
|
||||
// "Null MX" record indicates the domain accepts no mail (https://tools.ietf.org/html/rfc7505)
|
||||
if (empty($dnsRecord['target']) || $dnsRecord['target'] === '.') {
|
||||
if (empty($dnsRecord->target) || $dnsRecord->target === '.') {
|
||||
$this->error = new InvalidEmail(new DomainAcceptsNoMail(), "");
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user