Skip to content

Commit e5997fa

Browse files
Work around deprecations from doctrine/lexer (#367)
1 parent b531a23 commit e5997fa

13 files changed

+105
-107
lines changed

src/EmailLexer.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,21 +213,19 @@ public function find($type) : bool
213213
public function moveNext() : bool
214214
{
215215
if ($this->hasToRecord && $this->previous === self::$nullToken) {
216-
$this->accumulator .= $this->token['value'];
216+
$this->accumulator .= ((array) $this->token)['value'];
217217
}
218218

219-
$this->previous = $this->token instanceof Token
220-
? ['value' => $this->token->value, 'type' => $this->token->type, 'position' => $this->token->position]
221-
: $this->token;
222-
219+
$this->previous = (array) $this->token;
220+
223221
if($this->lookahead === null) {
224222
$this->lookahead = self::$nullToken;
225223
}
226224

227225
$hasNext = parent::moveNext();
228226

229227
if ($this->hasToRecord) {
230-
$this->accumulator .= $this->token['value'];
228+
$this->accumulator .= ((array) $this->token)['value'];
231229
}
232230

233231
return $hasNext;

src/Parser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ abstract protected function preLeftParsing() : Result;
2929

3030
public function __construct(EmailLexer $lexer)
3131
{
32-
$this->lexer = $lexer;
32+
$this->lexer = $lexer;
3333
}
3434

3535
public function parse(string $str) : Result
@@ -51,7 +51,7 @@ public function parse(string $str) : Result
5151
return $localPartResult;
5252
}
5353

54-
$domainPartResult = $this->parseRightFromAt();
54+
$domainPartResult = $this->parseRightFromAt();
5555

5656
if ($domainPartResult->isInvalid()) {
5757
return $domainPartResult;
@@ -73,6 +73,6 @@ protected function hasAtToken() : bool
7373
$this->lexer->moveNext();
7474
$this->lexer->moveNext();
7575

76-
return $this->lexer->token['type'] !== EmailLexer::S_AT;
76+
return ((array) $this->lexer->token)['type'] !== EmailLexer::S_AT;
7777
}
7878
}

src/Parser/Comment.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ public function __construct(EmailLexer $lexer, CommentStrategy $commentStrategy)
3131

3232
public function parse() : Result
3333
{
34-
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
34+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS) {
3535
$this->openedParenthesis++;
3636
if($this->noClosingParenthesis()) {
37-
return new InvalidEmail(new UnclosedComment(), $this->lexer->token['value']);
37+
return new InvalidEmail(new UnclosedComment(), ((array) $this->lexer->token)['value']);
3838
}
3939
}
4040

41-
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
42-
return new InvalidEmail(new UnOpenedComment(), $this->lexer->token['value']);
41+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
42+
return new InvalidEmail(new UnOpenedComment(), ((array) $this->lexer->token)['value']);
4343
}
4444

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

6060
if($this->openedParenthesis >= 1) {
61-
return new InvalidEmail(new UnclosedComment(), $this->lexer->token['value']);
61+
return new InvalidEmail(new UnclosedComment(), ((array) $this->lexer->token)['value']);
6262
}
6363
if ($this->openedParenthesis < 0) {
64-
return new InvalidEmail(new UnOpenedComment(), $this->lexer->token['value']);
64+
return new InvalidEmail(new UnOpenedComment(), ((array) $this->lexer->token)['value']);
6565
}
6666

6767
$finalValidations = $this->commentStrategy->endOfLoopValidations($this->lexer);
@@ -78,7 +78,7 @@ public function parse() : Result
7878
private function warnEscaping() : bool
7979
{
8080
//Backslash found
81-
if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) {
81+
if (((array) $this->lexer->token)['type'] !== EmailLexer::S_BACKSLASH) {
8282
return false;
8383
}
8484

@@ -87,12 +87,12 @@ private function warnEscaping() : bool
8787
}
8888

8989
$this->warnings[QuotedPart::CODE] =
90-
new QuotedPart($this->lexer->getPrevious()['type'], $this->lexer->token['type']);
90+
new QuotedPart($this->lexer->getPrevious()['type'], ((array) $this->lexer->token)['type']);
9191
return true;
9292

9393
}
9494

95-
private function noClosingParenthesis() : bool
95+
private function noClosingParenthesis() : bool
9696
{
9797
try {
9898
$this->lexer->find(EmailLexer::S_CLOSEPARENTHESIS);

src/Parser/CommentStrategy/DomainComment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function endOfLoopValidations(EmailLexer $lexer) : Result
2323
{
2424
//test for end of string
2525
if (!$lexer->isNextToken(EmailLexer::S_DOT)) {
26-
return new InvalidEmail(new ExpectingATEXT('DOT not found near CLOSEPARENTHESIS'), $lexer->token['value']);
26+
return new InvalidEmail(new ExpectingATEXT('DOT not found near CLOSEPARENTHESIS'), ((array) $lexer->token)['value']);
2727
}
2828
//add warning
2929
//Address is valid within the message but cannot be used unmodified for the envelope

src/Parser/CommentStrategy/LocalComment.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function exitCondition(EmailLexer $lexer, int $openedParenthesis) : bool
2424
public function endOfLoopValidations(EmailLexer $lexer) : Result
2525
{
2626
if (!$lexer->isNextToken(EmailLexer::S_AT)) {
27-
return new InvalidEmail(new ExpectingATEXT('ATEX is not expected after closing comments'), $lexer->token['value']);
27+
return new InvalidEmail(new ExpectingATEXT('ATEX is not expected after closing comments'), ((array) $lexer->token)['value']);
2828
}
2929
$this->warnings[CFWSNearAt::CODE] = new CFWSNearAt();
3030
return new ValidEmail();

src/Parser/DomainLiteral.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public function parse() : Result
3939
$addressLiteral = '';
4040

4141
do {
42-
if ($this->lexer->token['type'] === EmailLexer::C_NUL) {
43-
return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->token['value']);
42+
if (((array) $this->lexer->token)['type'] === EmailLexer::C_NUL) {
43+
return new InvalidEmail(new ExpectingDTEXT(), ((array) $this->lexer->token)['value']);
4444
}
4545

4646
$this->addObsoleteWarnings();
4747

4848
if ($this->lexer->isNextTokenAny(array(EmailLexer::S_OPENBRACKET, EmailLexer::S_OPENBRACKET))) {
49-
return new InvalidEmail(new ExpectingDTEXT(), $this->lexer->token['value']);
49+
return new InvalidEmail(new ExpectingDTEXT(), ((array) $this->lexer->token)['value']);
5050
}
5151

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

5959
if ($this->lexer->isNextToken(EmailLexer::S_CR)) {
60-
return new InvalidEmail(new CRNoLF(), $this->lexer->token['value']);
60+
return new InvalidEmail(new CRNoLF(), ((array) $this->lexer->token)['value']);
6161
}
6262

63-
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH) {
64-
return new InvalidEmail(new UnusualElements($this->lexer->token['value']), $this->lexer->token['value']);
63+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH) {
64+
return new InvalidEmail(new UnusualElements(((array) $this->lexer->token)['value']), ((array) $this->lexer->token)['value']);
6565
}
66-
if ($this->lexer->token['type'] === EmailLexer::S_IPV6TAG) {
66+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_IPV6TAG) {
6767
$IPv6TAG = true;
6868
}
6969

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

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

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

@@ -144,7 +144,7 @@ public function checkIPV6Tag($addressLiteral, $maxGroups = 8) : void
144144
$this->warnings[IPV6Deprecated::CODE] = new IPV6Deprecated();
145145
}
146146
}
147-
147+
148148
public function convertIPv4ToIPv6(string $addressLiteralIPv4) : string
149149
{
150150
$matchesIP = [];
@@ -189,7 +189,7 @@ protected function checkIPV4Tag($addressLiteral) : bool
189189

190190
private function addObsoleteWarnings() : void
191191
{
192-
if(in_array($this->lexer->token['type'], self::OBSOLETE_WARNINGS)) {
192+
if(in_array(((array) $this->lexer->token)['type'], self::OBSOLETE_WARNINGS)) {
193193
$this->warnings[ObsoleteDTEXT::CODE] = new ObsoleteDTEXT();
194194
}
195195
}

src/Parser/DomainPart.php

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ public function parse() : Result
5050
return $domainChecks;
5151
}
5252

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

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

7070
$length = strlen($this->domainPart);
7171
if ($length > self::DOMAIN_MAX_LENGTH) {
72-
return new InvalidEmail(new DomainTooLong(), $this->lexer->token['value']);
72+
return new InvalidEmail(new DomainTooLong(), ((array) $this->lexer->token)['value']);
7373
}
7474

7575
return new ValidEmail();
@@ -79,13 +79,13 @@ private function checkEndOfDomain() : Result
7979
{
8080
$prev = $this->lexer->getPrevious();
8181
if ($prev['type'] === EmailLexer::S_DOT) {
82-
return new InvalidEmail(new DotAtEnd(), $this->lexer->token['value']);
82+
return new InvalidEmail(new DotAtEnd(), ((array) $this->lexer->token)['value']);
8383
}
8484
if ($prev['type'] === EmailLexer::S_HYPHEN) {
8585
return new InvalidEmail(new DomainHyphened('Hypen found at the end of the domain'), $prev['value']);
8686
}
8787

88-
if ($this->lexer->token['type'] === EmailLexer::S_SP) {
88+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_SP) {
8989
return new InvalidEmail(new CRLFAtTheEnd(), $prev['value']);
9090
}
9191
return new ValidEmail();
@@ -98,38 +98,38 @@ private function performDomainStartChecks() : Result
9898
if ($invalidTokens->isInvalid()) {
9999
return $invalidTokens;
100100
}
101-
101+
102102
$missingDomain = $this->checkEmptyDomain();
103103
if ($missingDomain->isInvalid()) {
104104
return $missingDomain;
105105
}
106106

107-
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
107+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENPARENTHESIS) {
108108
$this->warnings[DeprecatedComment::CODE] = new DeprecatedComment();
109109
}
110110
return new ValidEmail();
111111
}
112112

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

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

123123
return new ValidEmail();
124124
}
125125

126126
private function checkInvalidTokensAfterAT() : Result
127127
{
128-
if ($this->lexer->token['type'] === EmailLexer::S_DOT) {
129-
return new InvalidEmail(new DotAtStart(), $this->lexer->token['value']);
128+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT) {
129+
return new InvalidEmail(new DotAtStart(), ((array) $this->lexer->token)['value']);
130130
}
131-
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN) {
132-
return new InvalidEmail(new DomainHyphened('After AT'), $this->lexer->token['value']);
131+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_HYPHEN) {
132+
return new InvalidEmail(new DomainHyphened('After AT'), ((array) $this->lexer->token)['value']);
133133
}
134134
return new ValidEmail();
135135
}
@@ -156,8 +156,8 @@ protected function doParseDomainPart() : Result
156156
return $notAllowedChars;
157157
}
158158

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

@@ -172,7 +172,7 @@ protected function doParseDomainPart() : Result
172172
return $dotsResult;
173173
}
174174

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

178178
$this->addTLDWarnings($tldMissing);
@@ -189,9 +189,9 @@ protected function doParseDomainPart() : Result
189189
return $FwsResult;
190190
}
191191

192-
$domain .= $this->lexer->token['value'];
192+
$domain .= ((array) $this->lexer->token)['value'];
193193

194-
if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::GENERIC)) {
194+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::GENERIC)) {
195195
$tldMissing = false;
196196
}
197197

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

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

206206
$labelCheck = $this->checkLabelLength(true);
207207
if ($labelCheck->isInvalid()) {
@@ -219,8 +219,8 @@ protected function doParseDomainPart() : Result
219219
private function checkNotAllowedChars($token) : Result
220220
{
221221
$notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true];
222-
if (isset($notAllowed[$token['type']])) {
223-
return new InvalidEmail(new CharNotAllowed(), $token['value']);
222+
if (isset($notAllowed[((array) $token)['type']])) {
223+
return new InvalidEmail(new CharNotAllowed(), ((array) $token)['value']);
224224
}
225225
return new ValidEmail();
226226
}
@@ -233,7 +233,7 @@ protected function parseDomainLiteral() : Result
233233
try {
234234
$this->lexer->find(EmailLexer::S_CLOSEBRACKET);
235235
} catch (\RuntimeException $e) {
236-
return new InvalidEmail(new ExpectingDomainLiteralClose(), $this->lexer->token['value']);
236+
return new InvalidEmail(new ExpectingDomainLiteralClose(), ((array) $this->lexer->token)['value']);
237237
}
238238

239239
$domainLiteralParser = new DomainLiteralParser($this->lexer);
@@ -244,17 +244,17 @@ protected function parseDomainLiteral() : Result
244244

245245
protected function checkDomainPartExceptions(array $prev, bool $hasComments) : Result
246246
{
247-
if ($this->lexer->token['type'] === EmailLexer::S_OPENBRACKET && $prev['type'] !== EmailLexer::S_AT) {
248-
return new InvalidEmail(new ExpectingATEXT('OPENBRACKET not after AT'), $this->lexer->token['value']);
247+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_OPENBRACKET && $prev['type'] !== EmailLexer::S_AT) {
248+
return new InvalidEmail(new ExpectingATEXT('OPENBRACKET not after AT'), ((array) $this->lexer->token)['value']);
249249
}
250250

251-
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
252-
return new InvalidEmail(new DomainHyphened('Hypen found near DOT'), $this->lexer->token['value']);
251+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_HYPHEN && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
252+
return new InvalidEmail(new DomainHyphened('Hypen found near DOT'), ((array) $this->lexer->token)['value']);
253253
}
254254

255-
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH
255+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH
256256
&& $this->lexer->isNextToken(EmailLexer::GENERIC)) {
257-
return new InvalidEmail(new ExpectingATEXT('Escaping following "ATOM"'), $this->lexer->token['value']);
257+
return new InvalidEmail(new ExpectingATEXT('Escaping following "ATOM"'), ((array) $this->lexer->token)['value']);
258258
}
259259

260260
return $this->validateTokens($hasComments);
@@ -273,22 +273,22 @@ protected function validateTokens(bool $hasComments) : Result
273273
$validDomainTokens[EmailLexer::S_CLOSEPARENTHESIS] = true;
274274
}
275275

276-
if (!isset($validDomainTokens[$this->lexer->token['type']])) {
277-
return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . $this->lexer->token['value']), $this->lexer->token['value']);
276+
if (!isset($validDomainTokens[((array) $this->lexer->token)['type']])) {
277+
return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . ((array) $this->lexer->token)['value']), ((array) $this->lexer->token)['value']);
278278
}
279279

280280
return new ValidEmail();
281281
}
282282

283283
private function checkLabelLength(bool $isEndOfDomain = false) : Result
284284
{
285-
if ($this->lexer->token['type'] === EmailLexer::S_DOT || $isEndOfDomain) {
285+
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT || $isEndOfDomain) {
286286
if ($this->isLabelTooLong($this->label)) {
287-
return new InvalidEmail(new LabelTooLong(), $this->lexer->token['value']);
287+
return new InvalidEmail(new LabelTooLong(), ((array) $this->lexer->token)['value']);
288288
}
289289
$this->label = '';
290290
}
291-
$this->label .= $this->lexer->token['value'];
291+
$this->label .= ((array) $this->lexer->token)['value'];
292292
return new ValidEmail();
293293
}
294294

0 commit comments

Comments
 (0)