Compare commits

...

1 Commits

Author SHA1 Message Date
Nicolas Grekas e5997fa97e Work around deprecations from doctrine/lexer (#367) 2023-06-01 09:04:22 +02:00
13 changed files with 105 additions and 107 deletions
+4 -6
View File
@@ -213,13 +213,11 @@ class EmailLexer extends AbstractLexer
public function moveNext() : bool public function moveNext() : bool
{ {
if ($this->hasToRecord && $this->previous === self::$nullToken) { if ($this->hasToRecord && $this->previous === self::$nullToken) {
$this->accumulator .= $this->token['value']; $this->accumulator .= ((array) $this->token)['value'];
} }
$this->previous = $this->token instanceof Token $this->previous = (array) $this->token;
? ['value' => $this->token->value, 'type' => $this->token->type, 'position' => $this->token->position]
: $this->token;
if($this->lookahead === null) { if($this->lookahead === null) {
$this->lookahead = self::$nullToken; $this->lookahead = self::$nullToken;
} }
@@ -227,7 +225,7 @@ class EmailLexer extends AbstractLexer
$hasNext = parent::moveNext(); $hasNext = parent::moveNext();
if ($this->hasToRecord) { if ($this->hasToRecord) {
$this->accumulator .= $this->token['value']; $this->accumulator .= ((array) $this->token)['value'];
} }
return $hasNext; return $hasNext;
+3 -3
View File
@@ -29,7 +29,7 @@ abstract class Parser
public function __construct(EmailLexer $lexer) public function __construct(EmailLexer $lexer)
{ {
$this->lexer = $lexer; $this->lexer = $lexer;
} }
public function parse(string $str) : Result public function parse(string $str) : Result
@@ -51,7 +51,7 @@ abstract class Parser
return $localPartResult; return $localPartResult;
} }
$domainPartResult = $this->parseRightFromAt(); $domainPartResult = $this->parseRightFromAt();
if ($domainPartResult->isInvalid()) { if ($domainPartResult->isInvalid()) {
return $domainPartResult; return $domainPartResult;
@@ -73,6 +73,6 @@ abstract class Parser
$this->lexer->moveNext(); $this->lexer->moveNext();
$this->lexer->moveNext(); $this->lexer->moveNext();
return $this->lexer->token['type'] !== EmailLexer::S_AT; return ((array) $this->lexer->token)['type'] !== EmailLexer::S_AT;
} }
} }
+9 -9
View File
@@ -31,15 +31,15 @@ class Comment extends PartParser
public function parse() : Result public function parse() : Result
{ {
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->openedParenthesis++; $this->openedParenthesis++;
if($this->noClosingParenthesis()) { if($this->noClosingParenthesis()) {
return new InvalidEmail(new UnclosedComment(), $this->lexer->token['value']); return new InvalidEmail(new UnclosedComment(), ((array) $this->lexer->token)['value']);
} }
} }
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
return new InvalidEmail(new UnOpenedComment(), $this->lexer->token['value']); return new InvalidEmail(new UnOpenedComment(), ((array) $this->lexer->token)['value']);
} }
$this->warnings[WarningComment::CODE] = new WarningComment(); $this->warnings[WarningComment::CODE] = new WarningComment();
@@ -58,10 +58,10 @@ class Comment extends PartParser
} }
if($this->openedParenthesis >= 1) { if($this->openedParenthesis >= 1) {
return new InvalidEmail(new UnclosedComment(), $this->lexer->token['value']); return new InvalidEmail(new UnclosedComment(), ((array) $this->lexer->token)['value']);
} }
if ($this->openedParenthesis < 0) { if ($this->openedParenthesis < 0) {
return new InvalidEmail(new UnOpenedComment(), $this->lexer->token['value']); return new InvalidEmail(new UnOpenedComment(), ((array) $this->lexer->token)['value']);
} }
$finalValidations = $this->commentStrategy->endOfLoopValidations($this->lexer); $finalValidations = $this->commentStrategy->endOfLoopValidations($this->lexer);
@@ -78,7 +78,7 @@ class Comment extends PartParser
private function warnEscaping() : bool private function warnEscaping() : bool
{ {
//Backslash found //Backslash found
if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) { if (((array) $this->lexer->token)['type'] !== EmailLexer::S_BACKSLASH) {
return false; return false;
} }
@@ -87,12 +87,12 @@ class Comment extends PartParser
} }
$this->warnings[QuotedPart::CODE] = $this->warnings[QuotedPart::CODE] =
new QuotedPart($this->lexer->getPrevious()['type'], $this->lexer->token['type']); new QuotedPart($this->lexer->getPrevious()['type'], ((array) $this->lexer->token)['type']);
return true; return true;
} }
private function noClosingParenthesis() : bool private function noClosingParenthesis() : bool
{ {
try { try {
$this->lexer->find(EmailLexer::S_CLOSEPARENTHESIS); $this->lexer->find(EmailLexer::S_CLOSEPARENTHESIS);
+1 -1
View File
@@ -23,7 +23,7 @@ class DomainComment implements CommentStrategy
{ {
//test for end of string //test for end of string
if (!$lexer->isNextToken(EmailLexer::S_DOT)) { if (!$lexer->isNextToken(EmailLexer::S_DOT)) {
return new InvalidEmail(new ExpectingATEXT('DOT not found near CLOSEPARENTHESIS'), $lexer->token['value']); return new InvalidEmail(new ExpectingATEXT('DOT not found near CLOSEPARENTHESIS'), ((array) $lexer->token)['value']);
} }
//add warning //add warning
//Address is valid within the message but cannot be used unmodified for the envelope //Address is valid within the message but cannot be used unmodified for the envelope
+1 -1
View File
@@ -24,7 +24,7 @@ class LocalComment implements CommentStrategy
public function endOfLoopValidations(EmailLexer $lexer) : Result public function endOfLoopValidations(EmailLexer $lexer) : Result
{ {
if (!$lexer->isNextToken(EmailLexer::S_AT)) { if (!$lexer->isNextToken(EmailLexer::S_AT)) {
return new InvalidEmail(new ExpectingATEXT('ATEX is not expected after closing comments'), $lexer->token['value']); return new InvalidEmail(new ExpectingATEXT('ATEX is not expected after closing comments'), ((array) $lexer->token)['value']);
} }
$this->warnings[CFWSNearAt::CODE] = new CFWSNearAt(); $this->warnings[CFWSNearAt::CODE] = new CFWSNearAt();
return new ValidEmail(); return new ValidEmail();
+11 -11
View File
@@ -39,14 +39,14 @@ class DomainLiteral extends PartParser
$addressLiteral = ''; $addressLiteral = '';
do { do {
if ($this->lexer->token['type'] === EmailLexer::C_NUL) { if (((array) $this->lexer->token)['type'] === EmailLexer::C_NUL) {
return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->token['value']); return new InvalidEmail(new ExpectingDTEXT(), ((array) $this->lexer->token)['value']);
} }
$this->addObsoleteWarnings(); $this->addObsoleteWarnings();
if ($this->lexer->isNextTokenAny(array(EmailLexer::S_OPENBRACKET, EmailLexer::S_OPENBRACKET))) { if ($this->lexer->isNextTokenAny(array(EmailLexer::S_OPENBRACKET, EmailLexer::S_OPENBRACKET))) {
return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->token['value']); return new InvalidEmail(new ExpectingDTEXT(), ((array) $this->lexer->token)['value']);
} }
if ($this->lexer->isNextTokenAny( if ($this->lexer->isNextTokenAny(
@@ -57,21 +57,21 @@ class DomainLiteral extends PartParser
} }
if ($this->lexer->isNextToken(EmailLexer::S_CR)) { if ($this->lexer->isNextToken(EmailLexer::S_CR)) {
return new InvalidEmail(new CRNoLF(), $this->lexer->token['value']); return new InvalidEmail(new CRNoLF(), ((array) $this->lexer->token)['value']);
} }
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH) {
return new InvalidEmail(new UnusualElements($this->lexer->token['value']), $this->lexer->token['value']); return new InvalidEmail(new UnusualElements(((array) $this->lexer->token)['value']), ((array) $this->lexer->token)['value']);
} }
if ($this->lexer->token['type'] === EmailLexer::S_IPV6TAG) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_IPV6TAG) {
$IPv6TAG = true; $IPv6TAG = true;
} }
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEBRACKET) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEBRACKET) {
break; break;
} }
$addressLiteral .= $this->lexer->token['value']; $addressLiteral .= ((array) $this->lexer->token)['value'];
} while ($this->lexer->moveNext()); } while ($this->lexer->moveNext());
@@ -144,7 +144,7 @@ class DomainLiteral extends PartParser
$this->warnings[IPV6Deprecated::CODE] = new IPV6Deprecated(); $this->warnings[IPV6Deprecated::CODE] = new IPV6Deprecated();
} }
} }
public function convertIPv4ToIPv6(string $addressLiteralIPv4) : string public function convertIPv4ToIPv6(string $addressLiteralIPv4) : string
{ {
$matchesIP = []; $matchesIP = [];
@@ -189,7 +189,7 @@ class DomainLiteral extends PartParser
private function addObsoleteWarnings() : void private function addObsoleteWarnings() : void
{ {
if(in_array($this->lexer->token['type'], self::OBSOLETE_WARNINGS)) { if(in_array(((array) $this->lexer->token)['type'], self::OBSOLETE_WARNINGS)) {
$this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT(); $this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT();
} }
} }
+34 -34
View File
@@ -50,8 +50,8 @@ class DomainPart extends PartParser
return $domainChecks; return $domainChecks;
} }
if ($this->lexer->token['type'] === EmailLexer::S_AT) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_AT) {
return new InvalidEmail(new ConsecutiveAt(), $this->lexer->token['value']); return new InvalidEmail(new ConsecutiveAt(), ((array) $this->lexer->token)['value']);
} }
$result = $this->doParseDomainPart(); $result = $this->doParseDomainPart();
@@ -69,7 +69,7 @@ class DomainPart extends PartParser
$length = strlen($this->domainPart); $length = strlen($this->domainPart);
if ($length > self::DOMAIN_MAX_LENGTH) { if ($length > self::DOMAIN_MAX_LENGTH) {
return new InvalidEmail(new DomainTooLong(), $this->lexer->token['value']); return new InvalidEmail(new DomainTooLong(), ((array) $this->lexer->token)['value']);
} }
return new ValidEmail(); return new ValidEmail();
@@ -79,13 +79,13 @@ class DomainPart extends PartParser
{ {
$prev = $this->lexer->getPrevious(); $prev = $this->lexer->getPrevious();
if ($prev['type'] === EmailLexer::S_DOT) { if ($prev['type'] === EmailLexer::S_DOT) {
return new InvalidEmail(new DotAtEnd(), $this->lexer->token['value']); return new InvalidEmail(new DotAtEnd(), ((array) $this->lexer->token)['value']);
} }
if ($prev['type'] === EmailLexer::S_HYPHEN) { if ($prev['type'] === 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['type'] === EmailLexer::S_SP) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_SP) {
return new InvalidEmail(new CRLFAtTheEnd(), $prev['value']); return new InvalidEmail(new CRLFAtTheEnd(), $prev['value']);
} }
return new ValidEmail(); return new ValidEmail();
@@ -98,13 +98,13 @@ class DomainPart extends PartParser
if ($invalidTokens->isInvalid()) { if ($invalidTokens->isInvalid()) {
return $invalidTokens; return $invalidTokens;
} }
$missingDomain = $this->checkEmptyDomain(); $missingDomain = $this->checkEmptyDomain();
if ($missingDomain->isInvalid()) { if ($missingDomain->isInvalid()) {
return $missingDomain; return $missingDomain;
} }
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->warnings[DeprecatedComment::CODE] = new DeprecatedComment(); $this->warnings[DeprecatedComment::CODE] = new DeprecatedComment();
} }
return new ValidEmail(); return new ValidEmail();
@@ -112,12 +112,12 @@ class DomainPart extends PartParser
private function checkEmptyDomain() : Result private function checkEmptyDomain() : Result
{ {
$thereIsNoDomain = $this->lexer->token['type'] === EmailLexer::S_EMPTY || $thereIsNoDomain = ((array) $this->lexer->token)['type'] === EmailLexer::S_EMPTY ||
($this->lexer->token['type'] === EmailLexer::S_SP && (((array) $this->lexer->token)['type'] === EmailLexer::S_SP &&
!$this->lexer->isNextToken(EmailLexer::GENERIC)); !$this->lexer->isNextToken(EmailLexer::GENERIC));
if ($thereIsNoDomain) { if ($thereIsNoDomain) {
return new InvalidEmail(new NoDomainPart(), $this->lexer->token['value']); return new InvalidEmail(new NoDomainPart(), ((array) $this->lexer->token)['value']);
} }
return new ValidEmail(); return new ValidEmail();
@@ -125,11 +125,11 @@ class DomainPart extends PartParser
private function checkInvalidTokensAfterAT() : Result private function checkInvalidTokensAfterAT() : Result
{ {
if ($this->lexer->token['type'] === EmailLexer::S_DOT) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT) {
return new InvalidEmail(new DotAtStart(), $this->lexer->token['value']); return new InvalidEmail(new DotAtStart(), ((array) $this->lexer->token)['value']);
} }
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_HYPHEN) {
return new InvalidEmail(new DomainHyphened('After AT'), $this->lexer->token['value']); return new InvalidEmail(new DomainHyphened('After AT'), ((array) $this->lexer->token)['value']);
} }
return new ValidEmail(); return new ValidEmail();
} }
@@ -156,8 +156,8 @@ class DomainPart extends PartParser
return $notAllowedChars; return $notAllowedChars;
} }
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS || if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS ||
$this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS ) { ((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEPARENTHESIS ) {
$hasComments = true; $hasComments = true;
$commentsResult = $this->parseComments(); $commentsResult = $this->parseComments();
@@ -172,7 +172,7 @@ class DomainPart extends PartParser
return $dotsResult; return $dotsResult;
} }
if ($this->lexer->token['type'] === EmailLexer::S_OPENBRACKET) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENBRACKET) {
$literalResult = $this->parseDomainLiteral(); $literalResult = $this->parseDomainLiteral();
$this->addTLDWarnings($tldMissing); $this->addTLDWarnings($tldMissing);
@@ -189,9 +189,9 @@ class DomainPart extends PartParser
return $FwsResult; return $FwsResult;
} }
$domain .= $this->lexer->token['value']; $domain .= ((array) $this->lexer->token)['value'];
if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::GENERIC)) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::GENERIC)) {
$tldMissing = false; $tldMissing = false;
} }
@@ -201,7 +201,7 @@ class DomainPart extends PartParser
} }
$this->lexer->moveNext(); $this->lexer->moveNext();
} while (null !== $this->lexer->token['type']); } while (null !== ((array) $this->lexer->token)['type']);
$labelCheck = $this->checkLabelLength(true); $labelCheck = $this->checkLabelLength(true);
if ($labelCheck->isInvalid()) { if ($labelCheck->isInvalid()) {
@@ -219,8 +219,8 @@ class DomainPart extends PartParser
private function checkNotAllowedChars($token) : Result private function checkNotAllowedChars($token) : Result
{ {
$notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true]; $notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true];
if (isset($notAllowed[$token['type']])) { if (isset($notAllowed[((array) $token)['type']])) {
return new InvalidEmail(new CharNotAllowed(), $token['value']); return new InvalidEmail(new CharNotAllowed(), ((array) $token)['value']);
} }
return new ValidEmail(); return new ValidEmail();
} }
@@ -233,7 +233,7 @@ class DomainPart extends PartParser
try { try {
$this->lexer->find(EmailLexer::S_CLOSEBRACKET); $this->lexer->find(EmailLexer::S_CLOSEBRACKET);
} catch (\RuntimeException $e) { } catch (\RuntimeException $e) {
return new InvalidEmail(new ExpectingDomainLiteralClose(), $this->lexer->token['value']); return new InvalidEmail(new ExpectingDomainLiteralClose(), ((array) $this->lexer->token)['value']);
} }
$domainLiteralParser = new DomainLiteralParser($this->lexer); $domainLiteralParser = new DomainLiteralParser($this->lexer);
@@ -244,17 +244,17 @@ class DomainPart extends PartParser
protected function checkDomainPartExceptions(array $prev, bool $hasComments) : Result protected function checkDomainPartExceptions(array $prev, bool $hasComments) : Result
{ {
if ($this->lexer->token['type'] === EmailLexer::S_OPENBRACKET && $prev['type'] !== EmailLexer::S_AT) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENBRACKET && $prev['type'] !== EmailLexer::S_AT) {
return new InvalidEmail(new ExpectingATEXT('OPENBRACKET not after AT'), $this->lexer->token['value']); return new InvalidEmail(new ExpectingATEXT('OPENBRACKET not after AT'), ((array) $this->lexer->token)['value']);
} }
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
return new InvalidEmail(new DomainHyphened('Hypen found near DOT'), $this->lexer->token['value']); return new InvalidEmail(new DomainHyphened('Hypen found near DOT'), ((array) $this->lexer->token)['value']);
} }
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH
&& $this->lexer->isNextToken(EmailLexer::GENERIC)) { && $this->lexer->isNextToken(EmailLexer::GENERIC)) {
return new InvalidEmail(new ExpectingATEXT('Escaping following "ATOM"'), $this->lexer->token['value']); return new InvalidEmail(new ExpectingATEXT('Escaping following "ATOM"'), ((array) $this->lexer->token)['value']);
} }
return $this->validateTokens($hasComments); return $this->validateTokens($hasComments);
@@ -273,8 +273,8 @@ class DomainPart extends PartParser
$validDomainTokens[EmailLexer::S_CLOSEPARENTHESIS] = true; $validDomainTokens[EmailLexer::S_CLOSEPARENTHESIS] = true;
} }
if (!isset($validDomainTokens[$this->lexer->token['type']])) { if (!isset($validDomainTokens[((array) $this->lexer->token)['type']])) {
return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . $this->lexer->token['value']), $this->lexer->token['value']); return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . ((array) $this->lexer->token)['value']), ((array) $this->lexer->token)['value']);
} }
return new ValidEmail(); return new ValidEmail();
@@ -282,13 +282,13 @@ class DomainPart extends PartParser
private function checkLabelLength(bool $isEndOfDomain = false) : Result private function checkLabelLength(bool $isEndOfDomain = false) : Result
{ {
if ($this->lexer->token['type'] === EmailLexer::S_DOT || $isEndOfDomain) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT || $isEndOfDomain) {
if ($this->isLabelTooLong($this->label)) { if ($this->isLabelTooLong($this->label)) {
return new InvalidEmail(new LabelTooLong(), $this->lexer->token['value']); return new InvalidEmail(new LabelTooLong(), ((array) $this->lexer->token)['value']);
} }
$this->label = ''; $this->label = '';
} }
$this->label .= $this->lexer->token['value']; $this->label .= ((array) $this->lexer->token)['value'];
return new ValidEmail(); return new ValidEmail();
} }
+10 -10
View File
@@ -30,24 +30,24 @@ class DoubleQuote extends PartParser
EmailLexer::S_CR => true, EmailLexer::S_CR => true,
EmailLexer::S_LF => true EmailLexer::S_LF => true
]; ];
$setSpecialsWarning = true; $setSpecialsWarning = true;
$this->lexer->moveNext(); $this->lexer->moveNext();
while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && null !== $this->lexer->token['type']) { while (((array) $this->lexer->token)['type'] !== EmailLexer::S_DQUOTE && null !== ((array) $this->lexer->token)['type']) {
if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) { if (isset($special[((array) $this->lexer->token)['type']]) && $setSpecialsWarning) {
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS(); $this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
$setSpecialsWarning = false; $setSpecialsWarning = false;
} }
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) {
$this->lexer->moveNext(); $this->lexer->moveNext();
} }
$this->lexer->moveNext(); $this->lexer->moveNext();
if (!$this->escaped() && isset($invalid[$this->lexer->token['type']])) { if (!$this->escaped() && isset($invalid[((array) $this->lexer->token)['type']])) {
return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->token['value']); return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), ((array) $this->lexer->token)['value']);
} }
} }
@@ -59,7 +59,7 @@ class DoubleQuote extends PartParser
} }
if (!$this->lexer->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) { if (!$this->lexer->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) {
return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->token['value']); return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), ((array) $this->lexer->token)['value']);
} }
return new ValidEmail(); return new ValidEmail();
@@ -71,15 +71,15 @@ class DoubleQuote extends PartParser
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) { if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) {
$description = 'https://tools.ietf.org/html/rfc5322#section-3.2.4 - quoted string should be a unit'; $description = 'https://tools.ietf.org/html/rfc5322#section-3.2.4 - quoted string should be a unit';
return new InvalidEmail(new ExpectingATEXT($description), $this->lexer->token['value']); return new InvalidEmail(new ExpectingATEXT($description), ((array) $this->lexer->token)['value']);
} }
try { try {
$this->lexer->find(EmailLexer::S_DQUOTE); $this->lexer->find(EmailLexer::S_DQUOTE);
} catch (\Exception $e) { } catch (\Exception $e) {
return new InvalidEmail(new UnclosedQuotedString(), $this->lexer->token['value']); return new InvalidEmail(new UnclosedQuotedString(), ((array) $this->lexer->token)['value']);
} }
$this->warnings[QuotedString::CODE] = new QuotedString($previous['value'], $this->lexer->token['value']); $this->warnings[QuotedString::CODE] = new QuotedString($previous['value'], ((array) $this->lexer->token)['value']);
return new ValidEmail(); return new ValidEmail();
} }
+10 -10
View File
@@ -36,16 +36,16 @@ class FoldingWhiteSpace extends PartParser
return $resultCRLF; return $resultCRLF;
} }
if ($this->lexer->token['type'] === EmailLexer::S_CR) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_CR) {
return new InvalidEmail(new CRNoLF(), $this->lexer->token['value']); return new InvalidEmail(new CRNoLF(), ((array) $this->lexer->token)['value']);
} }
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] !== EmailLexer::S_AT) { if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] !== EmailLexer::S_AT) {
return new InvalidEmail(new AtextAfterCFWS(), $this->lexer->token['value']); return new InvalidEmail(new AtextAfterCFWS(), ((array) $this->lexer->token)['value']);
} }
if ($this->lexer->token['type'] === EmailLexer::S_LF || $this->lexer->token['type'] === EmailLexer::C_NUL) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_LF || ((array) $this->lexer->token)['type'] === EmailLexer::C_NUL) {
return new InvalidEmail(new ExpectingCTEXT(), $this->lexer->token['value']); return new InvalidEmail(new ExpectingCTEXT(), ((array) $this->lexer->token)['value']);
} }
if ($this->lexer->isNextToken(EmailLexer::S_AT) || $previous['type'] === EmailLexer::S_AT) { if ($this->lexer->isNextToken(EmailLexer::S_AT) || $previous['type'] === EmailLexer::S_AT) {
@@ -59,28 +59,28 @@ class FoldingWhiteSpace extends PartParser
protected function checkCRLFInFWS() : Result protected function checkCRLFInFWS() : Result
{ {
if ($this->lexer->token['type'] !== EmailLexer::CRLF) { if (((array) $this->lexer->token)['type'] !== EmailLexer::CRLF) {
return new ValidEmail(); return new ValidEmail();
} }
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) { if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
return new InvalidEmail(new CRLFX2(), $this->lexer->token['value']); return new InvalidEmail(new CRLFX2(), ((array) $this->lexer->token)['value']);
} }
//this has no coverage. Condition is repeated from above one //this has no coverage. Condition is repeated from above one
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) { if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
return new InvalidEmail(new CRLFAtTheEnd(), $this->lexer->token['value']); return new InvalidEmail(new CRLFAtTheEnd(), ((array) $this->lexer->token)['value']);
} }
return new ValidEmail(); return new ValidEmail();
} }
protected function isFWS() : bool protected function isFWS() : bool
{ {
if ($this->escaped()) { if ($this->escaped()) {
return false; return false;
} }
return in_array($this->lexer->token['type'], self::FWS_TYPES); return in_array(((array) $this->lexer->token)['type'], self::FWS_TYPES);
} }
} }
+1 -1
View File
@@ -10,6 +10,6 @@ class IDLeftPart extends LocalPart
{ {
protected function parseComments(): Result protected function parseComments(): Result
{ {
return new InvalidEmail(new CommentsInIDRight(), $this->lexer->token['value']); return new InvalidEmail(new CommentsInIDRight(), ((array) $this->lexer->token)['value']);
} }
} }
+3 -3
View File
@@ -20,9 +20,9 @@ class IDRightPart extends DomainPart
EmailLexer::S_GREATERTHAN => true, EmailLexer::S_GREATERTHAN => true,
EmailLexer::S_LOWERTHAN => true, EmailLexer::S_LOWERTHAN => true,
]; ];
if (isset($invalidDomainTokens[$this->lexer->token['type']])) { if (isset($invalidDomainTokens[((array) $this->lexer->token)['type']])) {
return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . $this->lexer->token['value']), $this->lexer->token['value']); return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . ((array) $this->lexer->token)['value']), ((array) $this->lexer->token)['value']);
} }
return new ValidEmail(); return new ValidEmail();
} }
+15 -15
View File
@@ -36,12 +36,12 @@ class LocalPart extends PartParser
{ {
$this->lexer->startRecording(); $this->lexer->startRecording();
while ($this->lexer->token['type'] !== EmailLexer::S_AT && null !== $this->lexer->token['type']) { while (((array) $this->lexer->token)['type'] !== EmailLexer::S_AT && null !== ((array) $this->lexer->token)['type']) {
if ($this->hasDotAtStart()) { if ($this->hasDotAtStart()) {
return new InvalidEmail(new DotAtStart(), $this->lexer->token['value']); return new InvalidEmail(new DotAtStart(), ((array) $this->lexer->token)['value']);
} }
if ($this->lexer->token['type'] === EmailLexer::S_DQUOTE) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_DQUOTE) {
$dquoteParsingResult = $this->parseDoubleQuote(); $dquoteParsingResult = $this->parseDoubleQuote();
//Invalid double quote parsing //Invalid double quote parsing
@@ -50,8 +50,8 @@ class LocalPart extends PartParser
} }
} }
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS || if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS ||
$this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS ) { ((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEPARENTHESIS ) {
$commentsResult = $this->parseComments(); $commentsResult = $this->parseComments();
//Invalid comment parsing //Invalid comment parsing
@@ -60,14 +60,14 @@ class LocalPart extends PartParser
} }
} }
if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token['value']); return new InvalidEmail(new ConsecutiveDot(), ((array) $this->lexer->token)['value']);
} }
if ($this->lexer->token['type'] === EmailLexer::S_DOT && if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT &&
$this->lexer->isNextToken(EmailLexer::S_AT) $this->lexer->isNextToken(EmailLexer::S_AT)
) { ) {
return new InvalidEmail(new DotAtEnd(), $this->lexer->token['value']); return new InvalidEmail(new DotAtEnd(), ((array) $this->lexer->token)['value']);
} }
$resultEscaping = $this->validateEscaping(); $resultEscaping = $this->validateEscaping();
@@ -99,8 +99,8 @@ class LocalPart extends PartParser
protected function validateTokens(bool $hasComments) : Result protected function validateTokens(bool $hasComments) : Result
{ {
if (isset(self::INVALID_TOKENS[$this->lexer->token['type']])) { if (isset(self::INVALID_TOKENS[((array) $this->lexer->token)['type']])) {
return new InvalidEmail(new ExpectingATEXT('Invalid token found'), $this->lexer->token['value']); return new InvalidEmail(new ExpectingATEXT('Invalid token found'), ((array) $this->lexer->token)['value']);
} }
return new ValidEmail(); return new ValidEmail();
} }
@@ -110,7 +110,7 @@ class LocalPart extends PartParser
return $this->localPart; return $this->localPart;
} }
private function parseLocalFWS() : Result private function parseLocalFWS() : Result
{ {
$foldingWS = new FoldingWhiteSpace($this->lexer); $foldingWS = new FoldingWhiteSpace($this->lexer);
$resultFWS = $foldingWS->parse(); $resultFWS = $foldingWS->parse();
@@ -122,7 +122,7 @@ class LocalPart extends PartParser
private function hasDotAtStart() : bool private function hasDotAtStart() : bool
{ {
return $this->lexer->token['type'] === EmailLexer::S_DOT && null === $this->lexer->getPrevious()['type']; return ((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && null === $this->lexer->getPrevious()['type'];
} }
private function parseDoubleQuote() : Result private function parseDoubleQuote() : Result
@@ -148,12 +148,12 @@ class LocalPart extends PartParser
private function validateEscaping() : Result private function validateEscaping() : Result
{ {
//Backslash found //Backslash found
if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) { if (((array) $this->lexer->token)['type'] !== EmailLexer::S_BACKSLASH) {
return new ValidEmail(); return new ValidEmail();
} }
if ($this->lexer->isNextToken(EmailLexer::GENERIC)) { if ($this->lexer->isNextToken(EmailLexer::GENERIC)) {
return new InvalidEmail(new ExpectingATEXT('Found ATOM after escaping'), $this->lexer->token['value']); return new InvalidEmail(new ExpectingATEXT('Found ATOM after escaping'), ((array) $this->lexer->token)['value']);
} }
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB, EmailLexer::C_DEL))) { if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB, EmailLexer::C_DEL))) {
+3 -3
View File
@@ -45,8 +45,8 @@ abstract class PartParser
protected function checkConsecutiveDots() : Result protected function checkConsecutiveDots() : Result
{ {
if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) { if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token['value']); return new InvalidEmail(new ConsecutiveDot(), ((array) $this->lexer->token)['value']);
} }
return new ValidEmail(); return new ValidEmail();
@@ -58,6 +58,6 @@ abstract class PartParser
return $previous && $previous['type'] === EmailLexer::S_BACKSLASH return $previous && $previous['type'] === EmailLexer::S_BACKSLASH
&& &&
$this->lexer->token['type'] !== EmailLexer::GENERIC; ((array) $this->lexer->token)['type'] !== EmailLexer::GENERIC;
} }
} }