mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-08-17 22:12:01 +00:00
Use php nullsafe operator to fix type issues
This commit is contained in:
+1
-3
@@ -140,9 +140,7 @@ class EmailLexer extends AbstractLexer
|
||||
/**
|
||||
* The last matched/seen token.
|
||||
*
|
||||
* @var Token<int, string>
|
||||
*
|
||||
* @psalm-suppress NonInvariantDocblockPropertyType
|
||||
* @var Token<int, string>|null
|
||||
*/
|
||||
public Token|null $token;
|
||||
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ class EmailParser extends Parser
|
||||
protected function preLeftParsing(): Result
|
||||
{
|
||||
if (!$this->hasAtToken()) {
|
||||
return new InvalidEmail(new NoLocalPart(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new NoLocalPart(), $this->lexer->token?->value);
|
||||
}
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class MessageIDParser extends Parser
|
||||
protected function preLeftParsing(): Result
|
||||
{
|
||||
if (!$this->hasAtToken()) {
|
||||
return new InvalidEmail(new NoLocalPart(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new NoLocalPart(), $this->lexer->token?->value);
|
||||
}
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
+2
-2
@@ -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();
|
||||
@@ -73,6 +73,6 @@ abstract class Parser
|
||||
$this->lexer->moveNext();
|
||||
$this->lexer->moveNext();
|
||||
|
||||
return !$this->lexer->token->isA(EmailLexer::S_AT);
|
||||
return !$this->lexer->token?->isA(EmailLexer::S_AT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,15 +31,15 @@ class Comment extends PartParser
|
||||
|
||||
public function parse(): Result
|
||||
{
|
||||
if ($this->lexer->token->isA(EmailLexer::S_OPENPARENTHESIS)) {
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_OPENPARENTHESIS)) {
|
||||
$this->openedParenthesis++;
|
||||
if ($this->noClosingParenthesis()) {
|
||||
return new InvalidEmail(new UnclosedComment(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new UnclosedComment(), $this->lexer->token?->value);
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_CLOSEPARENTHESIS)) {
|
||||
return new InvalidEmail(new UnOpenedComment(), $this->lexer->token->value);
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_CLOSEPARENTHESIS)) {
|
||||
return new InvalidEmail(new UnOpenedComment(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
$this->warnings[WarningComment::CODE] = new WarningComment();
|
||||
@@ -58,10 +58,10 @@ class Comment extends PartParser
|
||||
}
|
||||
|
||||
if ($this->openedParenthesis >= 1) {
|
||||
return new InvalidEmail(new UnclosedComment(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new UnclosedComment(), $this->lexer->token?->value);
|
||||
}
|
||||
if ($this->openedParenthesis < 0) {
|
||||
return new InvalidEmail(new UnOpenedComment(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new UnOpenedComment(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
$finalValidations = $this->commentStrategy->endOfLoopValidations($this->lexer);
|
||||
@@ -78,7 +78,7 @@ class Comment extends PartParser
|
||||
private function warnEscaping(): bool
|
||||
{
|
||||
//Backslash found
|
||||
if (!$this->lexer->token->isA(EmailLexer::S_BACKSLASH)) {
|
||||
if (!$this->lexer->token?->isA(EmailLexer::S_BACKSLASH)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ class Comment extends PartParser
|
||||
}
|
||||
|
||||
$this->warnings[QuotedPart::CODE] =
|
||||
new QuotedPart($this->lexer->getPrevious()->type, $this->lexer->token->type);
|
||||
new QuotedPart($this->lexer->getPrevious()->type, $this->lexer->token?->type);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class DomainComment implements CommentStrategy
|
||||
{
|
||||
//test for end of string
|
||||
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'), $lexer->token?->value);
|
||||
}
|
||||
//add warning
|
||||
//Address is valid within the message but cannot be used unmodified for the envelope
|
||||
|
||||
@@ -24,7 +24,7 @@ class LocalComment implements CommentStrategy
|
||||
public function endOfLoopValidations(EmailLexer $lexer): Result
|
||||
{
|
||||
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'), $lexer->token?->value);
|
||||
}
|
||||
$this->warnings[CFWSNearAt::CODE] = new CFWSNearAt();
|
||||
return new ValidEmail();
|
||||
|
||||
@@ -40,14 +40,14 @@ class DomainLiteral extends PartParser
|
||||
$addressLiteral = '';
|
||||
|
||||
do {
|
||||
if ($this->lexer->token->isA(EmailLexer::C_NUL)) {
|
||||
return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->token->value);
|
||||
if ($this->lexer->token?->isA(EmailLexer::C_NUL)) {
|
||||
return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
$this->addObsoleteWarnings();
|
||||
|
||||
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(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextTokenAny(
|
||||
@@ -58,21 +58,21 @@ class DomainLiteral extends PartParser
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_CR)) {
|
||||
return new InvalidEmail(new CRNoLF(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new CRNoLF(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_BACKSLASH)) {
|
||||
return new InvalidEmail(new UnusualElements($this->lexer->token->value), $this->lexer->token->value);
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_BACKSLASH)) {
|
||||
return new InvalidEmail(new UnusualElements($this->lexer->token?->value), $this->lexer->token?->value);
|
||||
}
|
||||
if ($this->lexer->token->isA(EmailLexer::S_IPV6TAG)) {
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_IPV6TAG)) {
|
||||
$IPv6TAG = true;
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_CLOSEBRACKET)) {
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_CLOSEBRACKET)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$addressLiteral .= $this->lexer->token->value;
|
||||
$addressLiteral .= $this->lexer->token?->value;
|
||||
} while ($this->lexer->moveNext());
|
||||
|
||||
|
||||
@@ -189,7 +189,7 @@ class DomainLiteral extends PartParser
|
||||
|
||||
private function addObsoleteWarnings(): void
|
||||
{
|
||||
if (in_array($this->lexer->token->type, self::OBSOLETE_WARNINGS)) {
|
||||
if (in_array($this->lexer->token?->type, self::OBSOLETE_WARNINGS)) {
|
||||
$this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT();
|
||||
}
|
||||
}
|
||||
|
||||
+31
-31
@@ -50,8 +50,8 @@ class DomainPart extends PartParser
|
||||
return $domainChecks;
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_AT)) {
|
||||
return new InvalidEmail(new ConsecutiveAt(), $this->lexer->token->value);
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_AT)) {
|
||||
return new InvalidEmail(new ConsecutiveAt(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
$result = $this->doParseDomainPart();
|
||||
@@ -69,7 +69,7 @@ class DomainPart extends PartParser
|
||||
|
||||
$length = strlen($this->domainPart);
|
||||
if ($length > self::DOMAIN_MAX_LENGTH) {
|
||||
return new InvalidEmail(new DomainTooLong(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new DomainTooLong(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
return new ValidEmail();
|
||||
@@ -79,13 +79,13 @@ class DomainPart extends PartParser
|
||||
{
|
||||
$prev = $this->lexer->getPrevious();
|
||||
if ($prev->isA(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new DotAtEnd(), $this->lexer->token->value);
|
||||
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);
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_SP)) {
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_SP)) {
|
||||
return new InvalidEmail(new CRLFAtTheEnd(), $prev->value);
|
||||
}
|
||||
return new ValidEmail();
|
||||
@@ -103,7 +103,7 @@ class DomainPart extends PartParser
|
||||
return $missingDomain;
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_OPENPARENTHESIS)) {
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_OPENPARENTHESIS)) {
|
||||
$this->warnings[DeprecatedComment::CODE] = new DeprecatedComment();
|
||||
}
|
||||
return new ValidEmail();
|
||||
@@ -111,12 +111,12 @@ class DomainPart extends PartParser
|
||||
|
||||
private function checkEmptyDomain(): Result
|
||||
{
|
||||
$thereIsNoDomain = $this->lexer->token->isA(EmailLexer::S_EMPTY) ||
|
||||
($this->lexer->token->isA(EmailLexer::S_SP) &&
|
||||
$thereIsNoDomain = $this->lexer->token?->isA(EmailLexer::S_EMPTY) ||
|
||||
($this->lexer->token?->isA(EmailLexer::S_SP) &&
|
||||
!$this->lexer->isNextToken(EmailLexer::GENERIC));
|
||||
|
||||
if ($thereIsNoDomain) {
|
||||
return new InvalidEmail(new NoDomainPart(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new NoDomainPart(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
return new ValidEmail();
|
||||
@@ -124,11 +124,11 @@ class DomainPart extends PartParser
|
||||
|
||||
private function checkInvalidTokensAfterAT(): Result
|
||||
{
|
||||
if ($this->lexer->token->isA(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new DotAtStart(), $this->lexer->token->value);
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new DotAtStart(), $this->lexer->token?->value);
|
||||
}
|
||||
if ($this->lexer->token->isA(EmailLexer::S_HYPHEN)) {
|
||||
return new InvalidEmail(new DomainHyphened('After AT'), $this->lexer->token->value);
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_HYPHEN)) {
|
||||
return new InvalidEmail(new DomainHyphened('After AT'), $this->lexer->token?->value);
|
||||
}
|
||||
return new ValidEmail();
|
||||
}
|
||||
@@ -156,8 +156,8 @@ class DomainPart extends PartParser
|
||||
}
|
||||
|
||||
if (
|
||||
$this->lexer->token->isA(EmailLexer::S_OPENPARENTHESIS) ||
|
||||
$this->lexer->token->isA(EmailLexer::S_CLOSEPARENTHESIS)
|
||||
$this->lexer->token?->isA(EmailLexer::S_OPENPARENTHESIS) ||
|
||||
$this->lexer->token?->isA(EmailLexer::S_CLOSEPARENTHESIS)
|
||||
) {
|
||||
$hasComments = true;
|
||||
$commentsResult = $this->parseComments();
|
||||
@@ -173,7 +173,7 @@ class DomainPart extends PartParser
|
||||
return $dotsResult;
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_OPENBRACKET)) {
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_OPENBRACKET)) {
|
||||
$literalResult = $this->parseDomainLiteral();
|
||||
|
||||
$this->addTLDWarnings($tldMissing);
|
||||
@@ -190,9 +190,9 @@ class DomainPart extends PartParser
|
||||
return $FwsResult;
|
||||
}
|
||||
|
||||
$domain .= $this->lexer->token->value;
|
||||
$domain .= $this->lexer->token?->value;
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_DOT) && $this->lexer->isNextToken(EmailLexer::GENERIC)) {
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_DOT) && $this->lexer->isNextToken(EmailLexer::GENERIC)) {
|
||||
$tldMissing = false;
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ class DomainPart extends PartParser
|
||||
return $exceptionsResult;
|
||||
}
|
||||
$this->lexer->moveNext();
|
||||
} while (!$this->lexer->token->isA(EmailLexer::S_EMPTY));
|
||||
} while (!$this->lexer->token?->isA(EmailLexer::S_EMPTY));
|
||||
|
||||
$labelCheck = $this->checkLabelLength(true);
|
||||
if ($labelCheck->isInvalid()) {
|
||||
@@ -235,7 +235,7 @@ class DomainPart extends PartParser
|
||||
try {
|
||||
$this->lexer->find(EmailLexer::S_CLOSEBRACKET);
|
||||
} catch (\RuntimeException $e) {
|
||||
return new InvalidEmail(new ExpectingDomainLiteralClose(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new ExpectingDomainLiteralClose(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
$domainLiteralParser = new DomainLiteralParser($this->lexer);
|
||||
@@ -252,19 +252,19 @@ class DomainPart extends PartParser
|
||||
*/
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_HYPHEN) && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new DomainHyphened('Hypen found near DOT'), $this->lexer->token->value);
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_HYPHEN) && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new DomainHyphened('Hypen found near DOT'), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
if (
|
||||
$this->lexer->token->isA(EmailLexer::S_BACKSLASH)
|
||||
$this->lexer->token?->isA(EmailLexer::S_BACKSLASH)
|
||||
&& $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"'), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
return $this->validateTokens($hasComments);
|
||||
@@ -283,8 +283,8 @@ class DomainPart extends PartParser
|
||||
$validDomainTokens[EmailLexer::S_CLOSEPARENTHESIS] = true;
|
||||
}
|
||||
|
||||
if (!isset($validDomainTokens[$this->lexer->token->type])) {
|
||||
return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . $this->lexer->token->value), $this->lexer->token->value);
|
||||
if (!isset($validDomainTokens[$this->lexer->token?->type])) {
|
||||
return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . $this->lexer->token?->value), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
return new ValidEmail();
|
||||
@@ -292,13 +292,13 @@ class DomainPart extends PartParser
|
||||
|
||||
private function checkLabelLength(bool $isEndOfDomain = false): Result
|
||||
{
|
||||
if ($this->lexer->token->isA(EmailLexer::S_DOT) || $isEndOfDomain) {
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_DOT) || $isEndOfDomain) {
|
||||
if ($this->isLabelTooLong($this->label)) {
|
||||
return new InvalidEmail(new LabelTooLong(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new LabelTooLong(), $this->lexer->token?->value);
|
||||
}
|
||||
$this->label = '';
|
||||
}
|
||||
$this->label .= $this->lexer->token->value;
|
||||
$this->label .= $this->lexer->token?->value;
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
|
||||
@@ -36,19 +36,19 @@ class DoubleQuote extends PartParser
|
||||
|
||||
$this->lexer->moveNext();
|
||||
|
||||
while (!$this->lexer->token->isA(EmailLexer::S_DQUOTE) && !$this->lexer->token->isA(EmailLexer::S_EMPTY)) {
|
||||
if (isset($special[$this->lexer->token->type]) && $setSpecialsWarning) {
|
||||
while (!$this->lexer->token?->isA(EmailLexer::S_DQUOTE) && !$this->lexer->token?->isA(EmailLexer::S_EMPTY)) {
|
||||
if (isset($special[$this->lexer->token?->type]) && $setSpecialsWarning) {
|
||||
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
|
||||
$setSpecialsWarning = false;
|
||||
}
|
||||
if ($this->lexer->token->isA(EmailLexer::S_BACKSLASH) && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) {
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_BACKSLASH) && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) {
|
||||
$this->lexer->moveNext();
|
||||
}
|
||||
|
||||
$this->lexer->moveNext();
|
||||
|
||||
if (!$this->escaped() && isset($invalid[$this->lexer->token->type])) {
|
||||
return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->token->value);
|
||||
if (!$this->escaped() && isset($invalid[$this->lexer->token?->type])) {
|
||||
return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->token?->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class DoubleQuote extends PartParser
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextToken(EmailLexer::S_AT) && !$prev->isA(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"), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
return new ValidEmail();
|
||||
@@ -72,15 +72,15 @@ class DoubleQuote extends PartParser
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous->isA(EmailLexer::GENERIC)) {
|
||||
$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), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->lexer->find(EmailLexer::S_DQUOTE);
|
||||
} catch (\Exception $e) {
|
||||
return new InvalidEmail(new UnclosedQuotedString(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new UnclosedQuotedString(), $this->lexer->token?->value);
|
||||
}
|
||||
$this->warnings[QuotedString::CODE] = new QuotedString($previous->value, $this->lexer->token->value);
|
||||
$this->warnings[QuotedString::CODE] = new QuotedString($previous->value, $this->lexer->token?->value);
|
||||
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
@@ -37,16 +37,16 @@ class FoldingWhiteSpace extends PartParser
|
||||
return $resultCRLF;
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_CR)) {
|
||||
return new InvalidEmail(new CRNoLF(), $this->lexer->token->value);
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_CR)) {
|
||||
return new InvalidEmail(new CRNoLF(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && !$previous->isA(EmailLexer::S_AT)) {
|
||||
return new InvalidEmail(new AtextAfterCFWS(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new AtextAfterCFWS(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_LF) || $this->lexer->token->isA(EmailLexer::C_NUL)) {
|
||||
return new InvalidEmail(new ExpectingCTEXT(), $this->lexer->token->value);
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_LF) || $this->lexer->token?->isA(EmailLexer::C_NUL)) {
|
||||
return new InvalidEmail(new ExpectingCTEXT(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_AT) || $previous->isA(EmailLexer::S_AT)) {
|
||||
@@ -60,17 +60,17 @@ class FoldingWhiteSpace extends PartParser
|
||||
|
||||
protected function checkCRLFInFWS(): Result
|
||||
{
|
||||
if (!$this->lexer->token->isA(EmailLexer::CRLF)) {
|
||||
if (!$this->lexer->token?->isA(EmailLexer::CRLF)) {
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
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(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
//this has no coverage. Condition is repeated from above one
|
||||
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(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
return new ValidEmail();
|
||||
@@ -82,6 +82,6 @@ class FoldingWhiteSpace extends PartParser
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array($this->lexer->token->type, self::FWS_TYPES);
|
||||
return in_array($this->lexer->token?->type, self::FWS_TYPES);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@ class IDLeftPart extends LocalPart
|
||||
{
|
||||
protected function parseComments(): Result
|
||||
{
|
||||
return new InvalidEmail(new CommentsInIDRight(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new CommentsInIDRight(), $this->lexer->token?->value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ class IDRightPart extends DomainPart
|
||||
EmailLexer::S_LOWERTHAN => true,
|
||||
];
|
||||
|
||||
if (isset($invalidDomainTokens[$this->lexer->token->type])) {
|
||||
return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . $this->lexer->token->value), $this->lexer->token->value);
|
||||
if (isset($invalidDomainTokens[$this->lexer->token?->type])) {
|
||||
return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . $this->lexer->token?->value), $this->lexer->token?->value);
|
||||
}
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
+14
-14
@@ -36,12 +36,12 @@ class LocalPart extends PartParser
|
||||
{
|
||||
$this->lexer->startRecording();
|
||||
|
||||
while (!$this->lexer->token->isA(EmailLexer::S_AT) && !$this->lexer->token->isA(EmailLexer::S_EMPTY)) {
|
||||
while (!$this->lexer->token?->isA(EmailLexer::S_AT) && !$this->lexer->token?->isA(EmailLexer::S_EMPTY)) {
|
||||
if ($this->hasDotAtStart()) {
|
||||
return new InvalidEmail(new DotAtStart(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new DotAtStart(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_DQUOTE)) {
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_DQUOTE)) {
|
||||
$dquoteParsingResult = $this->parseDoubleQuote();
|
||||
|
||||
//Invalid double quote parsing
|
||||
@@ -51,8 +51,8 @@ class LocalPart extends PartParser
|
||||
}
|
||||
|
||||
if (
|
||||
$this->lexer->token->isA(EmailLexer::S_OPENPARENTHESIS) ||
|
||||
$this->lexer->token->isA(EmailLexer::S_CLOSEPARENTHESIS)
|
||||
$this->lexer->token?->isA(EmailLexer::S_OPENPARENTHESIS) ||
|
||||
$this->lexer->token?->isA(EmailLexer::S_CLOSEPARENTHESIS)
|
||||
) {
|
||||
$commentsResult = $this->parseComments();
|
||||
|
||||
@@ -62,15 +62,15 @@ class LocalPart extends PartParser
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->lexer->token->isA(EmailLexer::S_DOT) && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token->value);
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_DOT) && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
if (
|
||||
$this->lexer->token->isA(EmailLexer::S_DOT) &&
|
||||
$this->lexer->token?->isA(EmailLexer::S_DOT) &&
|
||||
$this->lexer->isNextToken(EmailLexer::S_AT)
|
||||
) {
|
||||
return new InvalidEmail(new DotAtEnd(), $this->lexer->token->value);
|
||||
return new InvalidEmail(new DotAtEnd(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
$resultEscaping = $this->validateEscaping();
|
||||
@@ -102,8 +102,8 @@ class LocalPart extends PartParser
|
||||
|
||||
protected function validateTokens(bool $hasComments): Result
|
||||
{
|
||||
if (isset(self::INVALID_TOKENS[$this->lexer->token->type])) {
|
||||
return new InvalidEmail(new ExpectingATEXT('Invalid token found'), $this->lexer->token->value);
|
||||
if (isset(self::INVALID_TOKENS[$this->lexer->token?->type])) {
|
||||
return new InvalidEmail(new ExpectingATEXT('Invalid token found'), $this->lexer->token?->value);
|
||||
}
|
||||
return new ValidEmail();
|
||||
}
|
||||
@@ -125,7 +125,7 @@ class LocalPart extends PartParser
|
||||
|
||||
private function hasDotAtStart(): bool
|
||||
{
|
||||
return $this->lexer->token->isA(EmailLexer::S_DOT) && $this->lexer->getPrevious()->isA(EmailLexer::S_EMPTY);
|
||||
return $this->lexer->token?->isA(EmailLexer::S_DOT) && $this->lexer->getPrevious()->isA(EmailLexer::S_EMPTY);
|
||||
}
|
||||
|
||||
private function parseDoubleQuote(): Result
|
||||
@@ -151,12 +151,12 @@ class LocalPart extends PartParser
|
||||
private function validateEscaping(): Result
|
||||
{
|
||||
//Backslash found
|
||||
if (!$this->lexer->token->isA(EmailLexer::S_BACKSLASH)) {
|
||||
if (!$this->lexer->token?->isA(EmailLexer::S_BACKSLASH)) {
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
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'), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB, EmailLexer::C_DEL))) {
|
||||
|
||||
@@ -45,8 +45,8 @@ abstract class PartParser
|
||||
|
||||
protected function checkConsecutiveDots(): Result
|
||||
{
|
||||
if ($this->lexer->token->isA(EmailLexer::S_DOT) && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token->value);
|
||||
if ($this->lexer->token?->isA(EmailLexer::S_DOT) && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token?->value);
|
||||
}
|
||||
|
||||
return new ValidEmail();
|
||||
@@ -57,6 +57,6 @@ abstract class PartParser
|
||||
$previous = $this->lexer->getPrevious();
|
||||
|
||||
return $previous->isA(EmailLexer::S_BACKSLASH)
|
||||
&& !$this->lexer->token->isA(EmailLexer::GENERIC);
|
||||
&& !$this->lexer->token?->isA(EmailLexer::GENERIC);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class EmailLexerTest extends TestCase
|
||||
$lexer->setInput($str);
|
||||
$lexer->moveNext();
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals($token, $lexer->token->type);
|
||||
$this->assertEquals($token, $lexer->token?->type);
|
||||
}
|
||||
|
||||
public function testLexerParsesMultipleSpaces()
|
||||
@@ -33,9 +33,9 @@ class EmailLexerTest extends TestCase
|
||||
$lexer->setInput(' ');
|
||||
$lexer->moveNext();
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::S_SP, $lexer->token->type);
|
||||
$this->assertEquals(EmailLexer::S_SP, $lexer->token?->type);
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::S_SP, $lexer->token->type);
|
||||
$this->assertEquals(EmailLexer::S_SP, $lexer->token?->type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,7 +48,7 @@ class EmailLexerTest extends TestCase
|
||||
$lexer->moveNext();
|
||||
$lexer->moveNext();
|
||||
|
||||
$this->assertEquals(EmailLexer::INVALID, $lexer->token->type);
|
||||
$this->assertEquals(EmailLexer::INVALID, $lexer->token?->type);
|
||||
}
|
||||
|
||||
public function invalidUTF8CharsProvider()
|
||||
@@ -101,7 +101,7 @@ class EmailLexerTest extends TestCase
|
||||
$lexer->moveNext();
|
||||
$lexer->skipUntil(EmailLexer::S_HTAB);
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::S_HTAB, $lexer->token->type);
|
||||
$this->assertEquals(EmailLexer::S_HTAB, $lexer->token?->type);
|
||||
}
|
||||
|
||||
public function testLexerForUTF8()
|
||||
@@ -110,9 +110,9 @@ class EmailLexerTest extends TestCase
|
||||
$lexer->setInput("áÇ@bar.com");
|
||||
$lexer->moveNext();
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::GENERIC, $lexer->token->type);
|
||||
$this->assertEquals(EmailLexer::GENERIC, $lexer->token?->type);
|
||||
$lexer->moveNext();
|
||||
$this->assertEquals(EmailLexer::GENERIC, $lexer->token->type);
|
||||
$this->assertEquals(EmailLexer::GENERIC, $lexer->token?->type);
|
||||
}
|
||||
|
||||
public function testLexerSearchToken()
|
||||
|
||||
Reference in New Issue
Block a user