Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work around deprecations from doctrine/lexer #367

Merged
merged 1 commit into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/EmailLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,19 @@ public function find($type) : bool
public function moveNext() : bool
{
if ($this->hasToRecord && $this->previous === self::$nullToken) {
$this->accumulator .= $this->token['value'];
$this->accumulator .= ((array) $this->token)['value'];
}

$this->previous = $this->token instanceof Token
? ['value' => $this->token->value, 'type' => $this->token->type, 'position' => $this->token->position]
: $this->token;

$this->previous = (array) $this->token;

if($this->lookahead === null) {
$this->lookahead = self::$nullToken;
}

$hasNext = parent::moveNext();

if ($this->hasToRecord) {
$this->accumulator .= $this->token['value'];
$this->accumulator .= ((array) $this->token)['value'];
}

return $hasNext;
Expand Down
6 changes: 3 additions & 3 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ abstract protected function preLeftParsing() : Result;

public function __construct(EmailLexer $lexer)
{
$this->lexer = $lexer;
$this->lexer = $lexer;
}

public function parse(string $str) : Result
Expand All @@ -51,7 +51,7 @@ public function parse(string $str) : Result
return $localPartResult;
}

$domainPartResult = $this->parseRightFromAt();
$domainPartResult = $this->parseRightFromAt();

if ($domainPartResult->isInvalid()) {
return $domainPartResult;
Expand All @@ -73,6 +73,6 @@ protected function hasAtToken() : bool
$this->lexer->moveNext();
$this->lexer->moveNext();

return $this->lexer->token['type'] !== EmailLexer::S_AT;
return ((array) $this->lexer->token)['type'] !== EmailLexer::S_AT;
}
}
18 changes: 9 additions & 9 deletions src/Parser/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ public function __construct(EmailLexer $lexer, CommentStrategy $commentStrategy)

public function parse() : Result
{
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->openedParenthesis++;
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) {
return new InvalidEmail(new UnOpenedComment(), $this->lexer->token['value']);
if (((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
return new InvalidEmail(new UnOpenedComment(), ((array) $this->lexer->token)['value']);
}

$this->warnings[WarningComment::CODE] = new WarningComment();
Expand All @@ -58,10 +58,10 @@ public function parse() : Result
}

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) {
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);
Expand All @@ -78,7 +78,7 @@ public function parse() : Result
private function warnEscaping() : bool
{
//Backslash found
if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) {
if (((array) $this->lexer->token)['type'] !== EmailLexer::S_BACKSLASH) {
return false;
}

Expand All @@ -87,12 +87,12 @@ private function warnEscaping() : bool
}

$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;

}

private function noClosingParenthesis() : bool
private function noClosingParenthesis() : bool
{
try {
$this->lexer->find(EmailLexer::S_CLOSEPARENTHESIS);
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/CommentStrategy/DomainComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function endOfLoopValidations(EmailLexer $lexer) : Result
{
//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'), ((array) $lexer->token)['value']);
}
//add warning
//Address is valid within the message but cannot be used unmodified for the envelope
Expand Down
2 changes: 1 addition & 1 deletion src/Parser/CommentStrategy/LocalComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function exitCondition(EmailLexer $lexer, int $openedParenthesis) : bool
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'), ((array) $lexer->token)['value']);
}
$this->warnings[CFWSNearAt::CODE] = new CFWSNearAt();
return new ValidEmail();
Expand Down
22 changes: 11 additions & 11 deletions src/Parser/DomainLiteral.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public function parse() : Result
$addressLiteral = '';

do {
if ($this->lexer->token['type'] === EmailLexer::C_NUL) {
return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->token['value']);
if (((array) $this->lexer->token)['type'] === EmailLexer::C_NUL) {
return new InvalidEmail(new ExpectingDTEXT(), ((array) $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(), ((array) $this->lexer->token)['value']);
}

if ($this->lexer->isNextTokenAny(
Expand All @@ -57,21 +57,21 @@ public function parse() : Result
}

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) {
return new InvalidEmail(new UnusualElements($this->lexer->token['value']), $this->lexer->token['value']);
if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH) {
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;
}

if ($this->lexer->token['type'] === EmailLexer::S_CLOSEBRACKET) {
if (((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEBRACKET) {
break;
}

$addressLiteral .= $this->lexer->token['value'];
$addressLiteral .= ((array) $this->lexer->token)['value'];

} while ($this->lexer->moveNext());

Expand Down Expand Up @@ -144,7 +144,7 @@ public function checkIPV6Tag($addressLiteral, $maxGroups = 8) : void
$this->warnings[IPV6Deprecated::CODE] = new IPV6Deprecated();
}
}

public function convertIPv4ToIPv6(string $addressLiteralIPv4) : string
{
$matchesIP = [];
Expand Down Expand Up @@ -189,7 +189,7 @@ protected function checkIPV4Tag($addressLiteral) : bool

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();
}
}
Expand Down
68 changes: 34 additions & 34 deletions src/Parser/DomainPart.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public function parse() : Result
return $domainChecks;
}

if ($this->lexer->token['type'] === EmailLexer::S_AT) {
return new InvalidEmail(new ConsecutiveAt(), $this->lexer->token['value']);
if (((array) $this->lexer->token)['type'] === EmailLexer::S_AT) {
return new InvalidEmail(new ConsecutiveAt(), ((array) $this->lexer->token)['value']);
}

$result = $this->doParseDomainPart();
Expand All @@ -69,7 +69,7 @@ public function parse() : Result

$length = strlen($this->domainPart);
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();
Expand All @@ -79,13 +79,13 @@ private function checkEndOfDomain() : Result
{
$prev = $this->lexer->getPrevious();
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) {
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 ValidEmail();
Expand All @@ -98,38 +98,38 @@ private function performDomainStartChecks() : Result
if ($invalidTokens->isInvalid()) {
return $invalidTokens;
}

$missingDomain = $this->checkEmptyDomain();
if ($missingDomain->isInvalid()) {
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();
}
return new ValidEmail();
}

private function checkEmptyDomain() : Result
{
$thereIsNoDomain = $this->lexer->token['type'] === EmailLexer::S_EMPTY ||
($this->lexer->token['type'] === EmailLexer::S_SP &&
$thereIsNoDomain = ((array) $this->lexer->token)['type'] === EmailLexer::S_EMPTY ||
(((array) $this->lexer->token)['type'] === EmailLexer::S_SP &&
!$this->lexer->isNextToken(EmailLexer::GENERIC));

if ($thereIsNoDomain) {
return new InvalidEmail(new NoDomainPart(), $this->lexer->token['value']);
return new InvalidEmail(new NoDomainPart(), ((array) $this->lexer->token)['value']);
}

return new ValidEmail();
}

private function checkInvalidTokensAfterAT() : Result
{
if ($this->lexer->token['type'] === EmailLexer::S_DOT) {
return new InvalidEmail(new DotAtStart(), $this->lexer->token['value']);
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT) {
return new InvalidEmail(new DotAtStart(), ((array) $this->lexer->token)['value']);
}
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN) {
return new InvalidEmail(new DomainHyphened('After AT'), $this->lexer->token['value']);
if (((array) $this->lexer->token)['type'] === EmailLexer::S_HYPHEN) {
return new InvalidEmail(new DomainHyphened('After AT'), ((array) $this->lexer->token)['value']);
}
return new ValidEmail();
}
Expand All @@ -156,8 +156,8 @@ protected function doParseDomainPart() : Result
return $notAllowedChars;
}

if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS ||
$this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS ) {
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS ||
((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEPARENTHESIS ) {
$hasComments = true;
$commentsResult = $this->parseComments();

Expand All @@ -172,7 +172,7 @@ protected function doParseDomainPart() : Result
return $dotsResult;
}

if ($this->lexer->token['type'] === EmailLexer::S_OPENBRACKET) {
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENBRACKET) {
$literalResult = $this->parseDomainLiteral();

$this->addTLDWarnings($tldMissing);
Expand All @@ -189,9 +189,9 @@ protected function doParseDomainPart() : Result
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;
}

Expand All @@ -201,7 +201,7 @@ protected function doParseDomainPart() : Result
}
$this->lexer->moveNext();

} while (null !== $this->lexer->token['type']);
} while (null !== ((array) $this->lexer->token)['type']);

$labelCheck = $this->checkLabelLength(true);
if ($labelCheck->isInvalid()) {
Expand All @@ -219,8 +219,8 @@ protected function doParseDomainPart() : Result
private function checkNotAllowedChars($token) : Result
{
$notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true];
if (isset($notAllowed[$token['type']])) {
return new InvalidEmail(new CharNotAllowed(), $token['value']);
if (isset($notAllowed[((array) $token)['type']])) {
return new InvalidEmail(new CharNotAllowed(), ((array) $token)['value']);
}
return new ValidEmail();
}
Expand All @@ -233,7 +233,7 @@ protected function parseDomainLiteral() : Result
try {
$this->lexer->find(EmailLexer::S_CLOSEBRACKET);
} 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);
Expand All @@ -244,17 +244,17 @@ protected function parseDomainLiteral() : Result

protected function checkDomainPartExceptions(array $prev, bool $hasComments) : Result
{
if ($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']);
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENBRACKET && $prev['type'] !== EmailLexer::S_AT) {
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)) {
return new InvalidEmail(new DomainHyphened('Hypen found near DOT'), $this->lexer->token['value']);
if (((array) $this->lexer->token)['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
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)) {
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);
Expand All @@ -273,22 +273,22 @@ protected function validateTokens(bool $hasComments) : Result
$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[((array) $this->lexer->token)['type']])) {
return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . ((array) $this->lexer->token)['value']), ((array) $this->lexer->token)['value']);
}

return new ValidEmail();
}

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)) {
return new InvalidEmail(new LabelTooLong(), $this->lexer->token['value']);
return new InvalidEmail(new LabelTooLong(), ((array) $this->lexer->token)['value']);
}
$this->label = '';
}
$this->label .= $this->lexer->token['value'];
$this->label .= ((array) $this->lexer->token)['value'];
return new ValidEmail();
}

Expand Down
Loading