Skip to content

Commit 5f35e41

Browse files
authored
Allow doctrine/lexer 2 (#345)
1 parent 0170967 commit 5f35e41

File tree

6 files changed

+86
-34
lines changed

6 files changed

+86
-34
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
},
1515
"require": {
1616
"php": ">=7.2",
17-
"doctrine/lexer": "^1.2",
17+
"doctrine/lexer": "^1.2|^2",
1818
"symfony/polyfill-intl-idn": "^1.15"
1919
},
2020
"require-dev": {

composer.lock

Lines changed: 55 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

psalm.baseline.xml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="3.8.3@389af1bfc739bfdff3f9e3dc7bd6499aee51a831">
3-
<file src="src/EmailLexer.php">
4-
<DocblockTypeContradiction occurrences="1">
5-
<code>self::$nullToken</code>
6-
</DocblockTypeContradiction>
7-
</file>
8-
<file src="src/Parser/Parser.php">
9-
<MissingReturnType occurrences="1">
10-
<code>parse</code>
11-
</MissingReturnType>
12-
</file>
13-
<file src="src/Validation/SpoofCheckValidation.php">
14-
<UndefinedClass occurrences="2">
15-
<code>Spoofchecker</code>
16-
<code>Spoofchecker</code>
17-
</UndefinedClass>
2+
<files psalm-version="5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863">
3+
<file src="src/Parser/DomainPart.php">
4+
<RedundantConditionGivenDocblockType occurrences="1">
5+
<code>null !== $this-&gt;lexer-&gt;token['type']</code>
6+
</RedundantConditionGivenDocblockType>
187
</file>
198
</files>

psalm.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns="https://getpsalm.org/schema/config"
55
xsi:schemaLocation="https://getpsalm.org/schema/config ./vendor/vimeo/psalm/config.xsd"
6-
errorBaseline="./psalm.baseline.xml"
6+
errorBaseline="psalm.baseline.xml"
77
>
88
<projectFiles>
99
<directory name="src" />
@@ -13,5 +13,11 @@
1313
</projectFiles>
1414

1515
<issueHandlers>
16+
<DeprecatedMethod>
17+
<errorLevel type="suppress">
18+
<!-- This issue needs to be resolved before upgrading to Lexer 3 -->
19+
<referencedMethod name="Doctrine\Common\Lexer\Token::offsetGet"/>
20+
</errorLevel>
21+
</DeprecatedMethod>
1622
</issueHandlers>
1723
</psalm>

src/EmailLexer.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
namespace Egulias\EmailValidator;
44

55
use Doctrine\Common\Lexer\AbstractLexer;
6+
use Doctrine\Common\Lexer\Token;
67

8+
/**
9+
* @extends AbstractLexer<int, string>
10+
*/
711
class EmailLexer extends AbstractLexer
812
{
913
//ASCII values
@@ -140,18 +144,20 @@ class EmailLexer extends AbstractLexer
140144
/**
141145
* The last matched/seen token.
142146
*
143-
* @var array
147+
* @var array|Token
144148
*
145149
* @psalm-suppress NonInvariantDocblockPropertyType
146-
* @psalm-var array{value:string, type:null|int, position:int}
147-
* @psalm-suppress NonInvariantDocblockPropertyType
150+
* @psalm-var array{value:string, type:null|int, position:int}|Token<int, string>
148151
*/
149152
public $token;
150153

151154
/**
152155
* The next token in the input.
153156
*
154-
* @var array{position: int, type: int|null|string, value: int|string}|null
157+
* @var array|Token|null
158+
*
159+
* @psalm-suppress NonInvariantDocblockPropertyType
160+
* @psalm-var array{position: int, type: int|null|string, value: int|string}|Token<int, string>|null
155161
*/
156162
public $lookahead;
157163

@@ -210,7 +216,9 @@ public function moveNext() : bool
210216
$this->accumulator .= $this->token['value'];
211217
}
212218

213-
$this->previous = $this->token;
219+
$this->previous = $this->token instanceof Token
220+
? ['value' => $this->token->value, 'type' => $this->token->type, 'position' => $this->token->position]
221+
: $this->token;
214222

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

src/Parser/DomainPart.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Egulias\EmailValidator\Parser;
44

5+
use Doctrine\Common\Lexer\Token;
56
use Egulias\EmailValidator\EmailLexer;
67
use Egulias\EmailValidator\Warning\TLD;
78
use Egulias\EmailValidator\Result\Result;
@@ -212,7 +213,10 @@ protected function doParseDomainPart() : Result
212213
return new ValidEmail();
213214
}
214215

215-
private function checkNotAllowedChars(array $token) : Result
216+
/**
217+
* @psalm-param array|Token<int, string> $token
218+
*/
219+
private function checkNotAllowedChars($token) : Result
216220
{
217221
$notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true];
218222
if (isset($notAllowed[$token['type']])) {

0 commit comments

Comments
 (0)