diff --git a/composer.json b/composer.json index d598d1b..c03990e 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ }, "require": { "php": ">=7.2", - "doctrine/lexer": "^1.2", + "doctrine/lexer": "^1.2|^2", "symfony/polyfill-intl-idn": "^1.15" }, "require-dev": { diff --git a/composer.lock b/composer.lock index 15d9667..af6cf80 100644 --- a/composer.lock +++ b/composer.lock @@ -4,35 +4,80 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a77d36b64bc1213fecf4d4f92d759c3b", + "content-hash": "9b420b2279da45fe448cd428cf568d87", "packages": [ + { + "name": "doctrine/deprecations", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/deprecations.git", + "reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/deprecations/zipball/0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de", + "reference": "0e2a4f1f8cdfc7a92ec3b01c9334898c806b30de", + "shasum": "" + }, + "require": { + "php": "^7.1|^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^9", + "phpunit/phpunit": "^7.5|^8.5|^9.5", + "psr/log": "^1|^2|^3" + }, + "suggest": { + "psr/log": "Allows logging deprecations via PSR-3 logger implementation" + }, + "type": "library", + "autoload": { + "psr-4": { + "Doctrine\\Deprecations\\": "lib/Doctrine/Deprecations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A small layer on top of trigger_error(E_USER_DEPRECATED) or PSR-3 logging with options to disable all deprecations or selectively for packages.", + "homepage": "https://www.doctrine-project.org/", + "support": { + "issues": "https://github.com/doctrine/deprecations/issues", + "source": "https://github.com/doctrine/deprecations/tree/v1.0.0" + }, + "time": "2022-05-02T15:47:09+00:00" + }, { "name": "doctrine/lexer", - "version": "1.2.3", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/doctrine/lexer.git", - "reference": "c268e882d4dbdd85e36e4ad69e02dc284f89d229" + "reference": "39ab8fcf5a51ce4b85ca97c7a7d033eb12831124" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/c268e882d4dbdd85e36e4ad69e02dc284f89d229", - "reference": "c268e882d4dbdd85e36e4ad69e02dc284f89d229", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/39ab8fcf5a51ce4b85ca97c7a7d033eb12831124", + "reference": "39ab8fcf5a51ce4b85ca97c7a7d033eb12831124", "shasum": "" }, "require": { + "doctrine/deprecations": "^1.0", "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^9.0", + "doctrine/coding-standard": "^9 || ^10", "phpstan/phpstan": "^1.3", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", - "vimeo/psalm": "^4.11" + "psalm/plugin-phpunit": "^0.18.3", + "vimeo/psalm": "^4.11 || ^5.0" }, "type": "library", "autoload": { "psr-4": { - "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" + "Doctrine\\Common\\Lexer\\": "src" } }, "notification-url": "https://packagist.org/downloads/", @@ -64,7 +109,7 @@ ], "support": { "issues": "https://github.com/doctrine/lexer/issues", - "source": "https://github.com/doctrine/lexer/tree/1.2.3" + "source": "https://github.com/doctrine/lexer/tree/2.1.0" }, "funding": [ { @@ -80,7 +125,7 @@ "type": "tidelift" } ], - "time": "2022-02-28T11:07:21+00:00" + "time": "2022-12-14T08:49:07+00:00" }, { "name": "symfony/polyfill-intl-idn", diff --git a/psalm.baseline.xml b/psalm.baseline.xml index 13a922e..b1c907f 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -1,19 +1,8 @@ - - - - self::$nullToken - - - - - parse - - - - - Spoofchecker - Spoofchecker - + + + + null !== $this->lexer->token['type'] + diff --git a/psalm.xml b/psalm.xml index 0977b9e..ebdcd35 100644 --- a/psalm.xml +++ b/psalm.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="https://getpsalm.org/schema/config" xsi:schemaLocation="https://getpsalm.org/schema/config ./vendor/vimeo/psalm/config.xsd" - errorBaseline="./psalm.baseline.xml" + errorBaseline="psalm.baseline.xml" > @@ -13,5 +13,11 @@ + + + + + + diff --git a/src/EmailLexer.php b/src/EmailLexer.php index 0bfe86f..6add6bd 100644 --- a/src/EmailLexer.php +++ b/src/EmailLexer.php @@ -3,7 +3,11 @@ namespace Egulias\EmailValidator; use Doctrine\Common\Lexer\AbstractLexer; +use Doctrine\Common\Lexer\Token; +/** + * @extends AbstractLexer + */ class EmailLexer extends AbstractLexer { //ASCII values @@ -140,18 +144,20 @@ class EmailLexer extends AbstractLexer /** * The last matched/seen token. * - * @var array + * @var array|Token * * @psalm-suppress NonInvariantDocblockPropertyType - * @psalm-var array{value:string, type:null|int, position:int} - * @psalm-suppress NonInvariantDocblockPropertyType + * @psalm-var array{value:string, type:null|int, position:int}|Token */ public $token; /** * The next token in the input. * - * @var array{position: int, type: int|null|string, value: int|string}|null + * @var array|Token|null + * + * @psalm-suppress NonInvariantDocblockPropertyType + * @psalm-var array{position: int, type: int|null|string, value: int|string}|Token|null */ public $lookahead; @@ -210,7 +216,9 @@ public function moveNext() : bool $this->accumulator .= $this->token['value']; } - $this->previous = $this->token; + $this->previous = $this->token instanceof Token + ? ['value' => $this->token->value, 'type' => $this->token->type, 'position' => $this->token->position] + : $this->token; if($this->lookahead === null) { $this->lookahead = self::$nullToken; diff --git a/src/Parser/DomainPart.php b/src/Parser/DomainPart.php index a57f4ba..e1f5b3b 100644 --- a/src/Parser/DomainPart.php +++ b/src/Parser/DomainPart.php @@ -2,6 +2,7 @@ namespace Egulias\EmailValidator\Parser; +use Doctrine\Common\Lexer\Token; use Egulias\EmailValidator\EmailLexer; use Egulias\EmailValidator\Warning\TLD; use Egulias\EmailValidator\Result\Result; @@ -212,7 +213,10 @@ protected function doParseDomainPart() : Result return new ValidEmail(); } - private function checkNotAllowedChars(array $token) : Result + /** + * @psalm-param array|Token $token + */ + private function checkNotAllowedChars($token) : Result { $notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true]; if (isset($notAllowed[$token['type']])) {