From 578bc958a6ab9123f4bb77b76ea9ee1fed032582 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sat, 19 Jan 2019 20:53:51 +0000 Subject: [PATCH 01/14] experimenting with psalm --- .travis.yml | 12 +++++++ EmailValidator/EmailLexer.php | 20 +++++++++-- EmailValidator/EmailParser.php | 34 ++++++++++++++++++ EmailValidator/EmailValidator.php | 8 ++--- EmailValidator/Parser/DomainPart.php | 36 ++++++++++++++++--- EmailValidator/Parser/LocalPart.php | 8 ++++- EmailValidator/Parser/Parser.php | 34 ++++++++++++++++++ .../Validation/DNSCheckValidation.php | 9 +++-- .../Exception/EmptyValidationList.php | 3 ++ EmailValidator/Validation/MultipleErrors.php | 8 ++++- .../Validation/MultipleValidationWithAnd.php | 15 ++++++-- .../Validation/NoRFCWarningsValidation.php | 2 +- EmailValidator/Validation/RFCValidation.php | 4 +-- .../Validation/SpoofCheckValidation.php | 8 ++++- EmailValidator/Warning/QuotedPart.php | 4 +++ EmailValidator/Warning/QuotedString.php | 4 +++ EmailValidator/Warning/Warning.php | 21 +++++++++-- psalm.xml | 18 ++++++++++ 18 files changed, 226 insertions(+), 22 deletions(-) create mode 100644 psalm.xml diff --git a/.travis.yml b/.travis.yml index 3dc8c7b..1d3b48b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,26 +8,38 @@ matrix: - php: 5.5 dist: trusty - php: 5.6 + env: + - psalm=yes dist: xenial - php: 7.0 + env: + - psalm=yes dist: xenial - php: 7.1 + env: + - psalm=yes dist: bionic - php: 7.2 + env: + - psalm=yes dist: bionic - php: 7.3 dist: bionic - php: 7.4 + env: + - psalm=yes dist: bionic install: - if [ "$deps" = "low" ]; then composer update --prefer-lowest; else composer install; fi + - if [ "$psalm" = "yes" ]; then composer require --dev vimeo/psalm; fi before_script: - mkdir -p build/logs script: - vendor/bin/phpunit --coverage-clover build/logs/clover.xml + - if [ "$psalm" = "yes" ]; then vendor/bin/psalm; fi after_script: - php vendor/bin/coveralls diff --git a/EmailValidator/EmailLexer.php b/EmailValidator/EmailLexer.php index 4485728..68c4cb9 100644 --- a/EmailValidator/EmailLexer.php +++ b/EmailValidator/EmailLexer.php @@ -73,9 +73,15 @@ class EmailLexer extends AbstractLexer '\0' => self::C_NUL, ); + /** + * @var bool + */ protected $hasInvalidTokens = false; - protected $previous; + /** + * @var array + */ + protected $previous = []; private static $nullToken = [ 'value' => '', @@ -98,6 +104,9 @@ public function reset() $this->previous = $this->token = self::$nullToken; } + /** + * @return bool + */ public function hasInvalidTokens() { return $this->hasInvalidTokens; @@ -107,6 +116,8 @@ public function hasInvalidTokens() * @param string $type * @throws \UnexpectedValueException * @return boolean + * + * @psalm-suppress InvalidScalarArgument */ public function find($type) { @@ -122,7 +133,7 @@ public function find($type) /** * getPrevious * - * @return array token + * @return array */ public function getPrevious() { @@ -196,6 +207,11 @@ protected function getType(&$value) return self::GENERIC; } + /** + * @param string $value + * + * @return bool + */ protected function isValid($value) { if (isset($this->charValue[$value])) { diff --git a/EmailValidator/EmailParser.php b/EmailValidator/EmailParser.php index 5bf605a..09a63cc 100644 --- a/EmailValidator/EmailParser.php +++ b/EmailValidator/EmailParser.php @@ -17,11 +17,33 @@ class EmailParser { const EMAIL_MAX_LENGTH = 254; + /** + * @var \SplObjectStorage|array + */ protected $warnings; + + /** + * @var string + */ protected $domainPart = ''; + + /** + * @var string + */ protected $localPart = ''; + /** + * @var EmailLexer + */ protected $lexer; + + /** + * @var LocalPart + */ protected $localPartParser; + + /** + * @var DomainPart + */ protected $domainPartParser; public function __construct(EmailLexer $lexer) @@ -57,6 +79,9 @@ public function parse($str) return array('local' => $this->localPart, 'domain' => $this->domainPart); } + /** + * @return Warning\Warning[] + */ public function getWarnings() { $localPartWarnings = $this->localPartParser->getWarnings(); @@ -68,11 +93,17 @@ public function getWarnings() return $this->warnings; } + /** + * @return string + */ public function getParsedDomainPart() { return $this->domainPart; } + /** + * @param string $email + */ protected function setParts($email) { $parts = explode('@', $email); @@ -80,6 +111,9 @@ protected function setParts($email) $this->localPart = $parts[0]; } + /** + * @return bool + */ protected function hasAtToken() { $this->lexer->moveNext(); diff --git a/EmailValidator/EmailValidator.php b/EmailValidator/EmailValidator.php index 1c27707..a30f21d 100644 --- a/EmailValidator/EmailValidator.php +++ b/EmailValidator/EmailValidator.php @@ -13,12 +13,12 @@ class EmailValidator private $lexer; /** - * @var array + * @var Warning\Warning[] */ - protected $warnings; + protected $warnings = []; /** - * @var InvalidEmail + * @var InvalidEmail|null */ protected $error; @@ -58,7 +58,7 @@ public function getWarnings() } /** - * @return InvalidEmail + * @return InvalidEmail|null */ public function getError() { diff --git a/EmailValidator/Parser/DomainPart.php b/EmailValidator/Parser/DomainPart.php index 8ed240b..0613e31 100644 --- a/EmailValidator/Parser/DomainPart.php +++ b/EmailValidator/Parser/DomainPart.php @@ -35,6 +35,10 @@ class DomainPart extends Parser { const DOMAIN_MAX_LENGTH = 254; + + /** + * @var string + */ protected $domainPart = ''; public function parse($domainPart) @@ -95,11 +99,18 @@ private function checkInvalidTokensAfterAT() } } + /** + * @return string + */ public function getDomainPart() { return $this->domainPart; } + /** + * @param string $addressLiteral + * @param int $maxGroups + */ public function checkIPV6Tag($addressLiteral, $maxGroups = 8) { $prev = $this->lexer->getPrevious(); @@ -143,6 +154,9 @@ public function checkIPV6Tag($addressLiteral, $maxGroups = 8) } } + /** + * @return string + */ protected function doParseDomainPart() { $domain = ''; @@ -189,7 +203,7 @@ protected function doParseDomainPart() return $domain; } - private function checkNotAllowedChars($token) + private function checkNotAllowedChars(array $token) { $notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true]; if (isset($notAllowed[$token['type']])) { @@ -197,6 +211,9 @@ private function checkNotAllowedChars($token) } } + /** + * @return string|false + */ protected function parseDomainLiteral() { if ($this->lexer->isNextToken(EmailLexer::S_COLON)) { @@ -213,6 +230,9 @@ protected function parseDomainLiteral() return $this->doParseDomainLiteral(); } + /** + * @return string|false + */ protected function doParseDomainLiteral() { $IPv6TAG = false; @@ -280,6 +300,11 @@ protected function doParseDomainLiteral() return $addressLiteral; } + /** + * @param string $addressLiteral + * + * @return string|false + */ protected function checkIPV4Tag($addressLiteral) { $matchesIP = array(); @@ -297,13 +322,13 @@ protected function checkIPV4Tag($addressLiteral) return false; } // Convert IPv4 part to IPv6 format for further testing - $addressLiteral = substr($addressLiteral, 0, $index) . '0:0'; + $addressLiteral = substr($addressLiteral, 0, (int) $index) . '0:0'; } return $addressLiteral; } - protected function checkDomainPartExceptions($prev) + protected function checkDomainPartExceptions(array $prev) { $invalidDomainTokens = array( EmailLexer::S_DQUOTE => true, @@ -338,6 +363,9 @@ protected function checkDomainPartExceptions($prev) } } + /** + * @return bool + */ protected function hasBrackets() { if ($this->lexer->token['type'] !== EmailLexer::S_OPENBRACKET) { @@ -353,7 +381,7 @@ protected function hasBrackets() return true; } - protected function checkLabelLength($prev) + protected function checkLabelLength(array $prev) { if ($this->lexer->token['type'] === EmailLexer::S_DOT && $prev['type'] === EmailLexer::GENERIC && diff --git a/EmailValidator/Parser/LocalPart.php b/EmailValidator/Parser/LocalPart.php index fa1d17b..19da67a 100644 --- a/EmailValidator/Parser/LocalPart.php +++ b/EmailValidator/Parser/LocalPart.php @@ -67,6 +67,9 @@ public function parse($localPart) } } + /** + * @return bool + */ protected function parseDoubleQuote() { $parseAgain = true; @@ -118,7 +121,10 @@ protected function parseDoubleQuote() return $parseAgain; } - protected function isInvalidToken($token, $closingQuote) + /** + * @param bool $closingQuote + */ + protected function isInvalidToken(array $token, $closingQuote) { $forbidden = array( EmailLexer::S_COMMA, diff --git a/EmailValidator/Parser/Parser.php b/EmailValidator/Parser/Parser.php index fa7bd44..cc9e26b 100644 --- a/EmailValidator/Parser/Parser.php +++ b/EmailValidator/Parser/Parser.php @@ -21,8 +21,19 @@ abstract class Parser { + /** + * @var \Egulias\EmailValidator\Warning\Warning[] + */ protected $warnings = []; + + /** + * @var EmailLexer + */ protected $lexer; + + /** + * @var int + */ protected $openedParenthesis = 0; public function __construct(EmailLexer $lexer) @@ -30,11 +41,17 @@ public function __construct(EmailLexer $lexer) $this->lexer = $lexer; } + /** + * @return \Egulias\EmailValidator\Warning\Warning[] + */ public function getWarnings() { return $this->warnings; } + /** + * @param string $str + */ abstract public function parse($str); /** @return int */ @@ -80,6 +97,9 @@ protected function parseComments() } } + /** + * @return bool + */ protected function isUnclosedComment() { try { @@ -122,6 +142,9 @@ protected function checkConsecutiveDots() } } + /** + * @return bool + */ protected function isFWS() { if ($this->escaped()) { @@ -140,6 +163,9 @@ protected function isFWS() return false; } + /** + * @return bool + */ protected function escaped() { $previous = $this->lexer->getPrevious(); @@ -154,6 +180,9 @@ protected function escaped() return false; } + /** + * @return bool + */ protected function warnEscaping() { if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) { @@ -174,6 +203,11 @@ protected function warnEscaping() } + /** + * @param bool $hasClosingQuote + * + * @return bool + */ protected function checkDQUOTE($hasClosingQuote) { if ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE) { diff --git a/EmailValidator/Validation/DNSCheckValidation.php b/EmailValidator/Validation/DNSCheckValidation.php index e5c3e5d..207fc73 100644 --- a/EmailValidator/Validation/DNSCheckValidation.php +++ b/EmailValidator/Validation/DNSCheckValidation.php @@ -15,10 +15,10 @@ class DNSCheckValidation implements EmailValidation private $warnings = []; /** - * @var InvalidEmail + * @var InvalidEmail|null */ private $error; - + public function __construct() { if (!extension_loaded('intl')) { @@ -49,6 +49,11 @@ public function getWarnings() return $this->warnings; } + /** + * @param string $host + * + * @return bool + */ protected function checkDNS($host) { $variant = INTL_IDNA_VARIANT_2003; diff --git a/EmailValidator/Validation/Exception/EmptyValidationList.php b/EmailValidator/Validation/Exception/EmptyValidationList.php index 775ad16..ee7c41a 100644 --- a/EmailValidator/Validation/Exception/EmptyValidationList.php +++ b/EmailValidator/Validation/Exception/EmptyValidationList.php @@ -6,6 +6,9 @@ class EmptyValidationList extends \InvalidArgumentException { + /** + * @param int $code + */ public function __construct($code = 0, Exception $previous = null) { parent::__construct("Empty validation list is not allowed", $code, $previous); diff --git a/EmailValidator/Validation/MultipleErrors.php b/EmailValidator/Validation/MultipleErrors.php index d5e87d8..3be5973 100644 --- a/EmailValidator/Validation/MultipleErrors.php +++ b/EmailValidator/Validation/MultipleErrors.php @@ -9,16 +9,22 @@ class MultipleErrors extends InvalidEmail const CODE = 999; const REASON = "Accumulated errors for multiple validations"; /** - * @var array + * @var InvalidEmail[] */ private $errors = []; + /** + * @param InvalidEmail[] $errors + */ public function __construct(array $errors) { $this->errors = $errors; parent::__construct(); } + /** + * @return InvalidEmail[] + */ public function getErrors() { return $this->errors; diff --git a/EmailValidator/Validation/MultipleValidationWithAnd.php b/EmailValidator/Validation/MultipleValidationWithAnd.php index b823f7e..feb2240 100644 --- a/EmailValidator/Validation/MultipleValidationWithAnd.php +++ b/EmailValidator/Validation/MultipleValidationWithAnd.php @@ -30,12 +30,12 @@ class MultipleValidationWithAnd implements EmailValidation private $warnings = []; /** - * @var MultipleErrors + * @var MultipleErrors|null */ private $error; /** - * @var bool + * @var int */ private $mode; @@ -79,6 +79,12 @@ public function isValid($email, EmailLexer $emailLexer) return $result; } + /** + * @param \Egulias\EmailValidator\Exception\InvalidEmail|null $possibleError + * @param \Egulias\EmailValidator\Exception\InvalidEmail[] $errors + * + * @return \Egulias\EmailValidator\Exception\InvalidEmail[] + */ private function addNewError($possibleError, array $errors) { if (null !== $possibleError) { @@ -88,6 +94,11 @@ private function addNewError($possibleError, array $errors) return $errors; } + /** + * @param bool $result + * + * @return bool + */ private function shouldStop($result) { return !$result && $this->mode === self::STOP_ON_ERROR; diff --git a/EmailValidator/Validation/NoRFCWarningsValidation.php b/EmailValidator/Validation/NoRFCWarningsValidation.php index e4bf0cc..6b31e54 100644 --- a/EmailValidator/Validation/NoRFCWarningsValidation.php +++ b/EmailValidator/Validation/NoRFCWarningsValidation.php @@ -9,7 +9,7 @@ class NoRFCWarningsValidation extends RFCValidation { /** - * @var InvalidEmail + * @var InvalidEmail|null */ private $error; diff --git a/EmailValidator/Validation/RFCValidation.php b/EmailValidator/Validation/RFCValidation.php index c4ffe35..8781e0b 100644 --- a/EmailValidator/Validation/RFCValidation.php +++ b/EmailValidator/Validation/RFCValidation.php @@ -9,7 +9,7 @@ class RFCValidation implements EmailValidation { /** - * @var EmailParser + * @var EmailParser|null */ private $parser; @@ -19,7 +19,7 @@ class RFCValidation implements EmailValidation private $warnings = []; /** - * @var InvalidEmail + * @var InvalidEmail|null */ private $error; diff --git a/EmailValidator/Validation/SpoofCheckValidation.php b/EmailValidator/Validation/SpoofCheckValidation.php index 4721f0d..e10bfab 100644 --- a/EmailValidator/Validation/SpoofCheckValidation.php +++ b/EmailValidator/Validation/SpoofCheckValidation.php @@ -10,7 +10,7 @@ class SpoofCheckValidation implements EmailValidation { /** - * @var InvalidEmail + * @var InvalidEmail|null */ private $error; @@ -21,6 +21,9 @@ public function __construct() } } + /** + * @psalm-suppress InvalidArgument + */ public function isValid($email, EmailLexer $emailLexer) { $checker = new Spoofchecker(); @@ -33,6 +36,9 @@ public function isValid($email, EmailLexer $emailLexer) return $this->error === null; } + /** + * @return InvalidEmail|null + */ public function getError() { return $this->error; diff --git a/EmailValidator/Warning/QuotedPart.php b/EmailValidator/Warning/QuotedPart.php index 7be9e6a..36a4265 100644 --- a/EmailValidator/Warning/QuotedPart.php +++ b/EmailValidator/Warning/QuotedPart.php @@ -6,6 +6,10 @@ class QuotedPart extends Warning { const CODE = 36; + /** + * @param scalar $prevToken + * @param scalar $postToken + */ public function __construct($prevToken, $postToken) { $this->message = "Deprecated Quoted String found between $prevToken and $postToken"; diff --git a/EmailValidator/Warning/QuotedString.php b/EmailValidator/Warning/QuotedString.php index e9d56e1..817e4e8 100644 --- a/EmailValidator/Warning/QuotedString.php +++ b/EmailValidator/Warning/QuotedString.php @@ -6,6 +6,10 @@ class QuotedString extends Warning { const CODE = 11; + /** + * @param scalar $prevToken + * @param scalar $postToken + */ public function __construct($prevToken, $postToken) { $this->message = "Quoted String found between $prevToken and $postToken"; diff --git a/EmailValidator/Warning/Warning.php b/EmailValidator/Warning/Warning.php index ec6a365..bce7e7a 100644 --- a/EmailValidator/Warning/Warning.php +++ b/EmailValidator/Warning/Warning.php @@ -5,19 +5,36 @@ abstract class Warning { const CODE = 0; - protected $message; - protected $rfcNumber; + /** + * @var string + */ + protected $message = ''; + + /** + * @var int + */ + protected $rfcNumber = 0; + + /** + * @return string + */ public function message() { return $this->message; } + /** + * @return int + */ public function code() { return self::CODE; } + /** + * @return int + */ public function RFCNumber() { return $this->rfcNumber; diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..8a83de7 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + From 6258b0f6aea4b10832ff48b0d428bbc8b774ff96 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sat, 19 Jan 2019 22:02:23 +0000 Subject: [PATCH 02/14] loading in symfony polyfill, partially resolves egulias/EmailValidator#177, but SpoofChecker does not seem to be polyfilled in symfony/polyfill-intl-* --- EmailValidator/Validation/DNSCheckValidation.php | 2 +- composer.json | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/EmailValidator/Validation/DNSCheckValidation.php b/EmailValidator/Validation/DNSCheckValidation.php index 207fc73..da13253 100644 --- a/EmailValidator/Validation/DNSCheckValidation.php +++ b/EmailValidator/Validation/DNSCheckValidation.php @@ -21,7 +21,7 @@ class DNSCheckValidation implements EmailValidation public function __construct() { - if (!extension_loaded('intl')) { + if (!function_exists('idn_to_ascii')) { throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__)); } } diff --git a/composer.json b/composer.json index 37e87d5..595caff 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ }, "require": { "php": ">=5.5", - "doctrine/lexer": "^1.0.1" + "doctrine/lexer": "^1.0.1", + "symfony/polyfill-intl-idn": "^1.10" }, "require-dev": { "satooshi/php-coveralls": "^1.0.1", From 2341bc7e03268c0d05d502b3a4f9e22fc59d16d3 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sat, 19 Jan 2019 22:12:26 +0000 Subject: [PATCH 03/14] removing unused imports, fixes egulias/EmailValidator#168 and egulias/EmailValidator#169 --- EmailValidator/Parser/LocalPart.php | 1 - Tests/EmailValidator/Validation/IsEmailFunctionTests.php | 1 - .../EmailValidator/Validation/MultipleValidationWithAndTest.php | 2 -- 3 files changed, 4 deletions(-) diff --git a/EmailValidator/Parser/LocalPart.php b/EmailValidator/Parser/LocalPart.php index 19da67a..5f6b8c2 100644 --- a/EmailValidator/Parser/LocalPart.php +++ b/EmailValidator/Parser/LocalPart.php @@ -5,7 +5,6 @@ use Egulias\EmailValidator\Exception\DotAtEnd; use Egulias\EmailValidator\Exception\DotAtStart; use Egulias\EmailValidator\EmailLexer; -use Egulias\EmailValidator\EmailValidator; use Egulias\EmailValidator\Exception\ExpectingAT; use Egulias\EmailValidator\Exception\ExpectingATEXT; use Egulias\EmailValidator\Exception\UnclosedQuotedString; diff --git a/Tests/EmailValidator/Validation/IsEmailFunctionTests.php b/Tests/EmailValidator/Validation/IsEmailFunctionTests.php index 4674fd4..565741a 100644 --- a/Tests/EmailValidator/Validation/IsEmailFunctionTests.php +++ b/Tests/EmailValidator/Validation/IsEmailFunctionTests.php @@ -6,7 +6,6 @@ use Egulias\EmailValidator\Validation\DNSCheckValidation; use Egulias\EmailValidator\Validation\MultipleValidationWithAnd; use Egulias\EmailValidator\Validation\NoRFCWarningsValidation; -use Egulias\EmailValidator\Validation\RFCValidation; use PHPUnit\Framework\TestCase; class IsEmailFunctionTests extends TestCase diff --git a/Tests/EmailValidator/Validation/MultipleValidationWithAndTest.php b/Tests/EmailValidator/Validation/MultipleValidationWithAndTest.php index e6bba8e..9e3610d 100644 --- a/Tests/EmailValidator/Validation/MultipleValidationWithAndTest.php +++ b/Tests/EmailValidator/Validation/MultipleValidationWithAndTest.php @@ -3,13 +3,11 @@ namespace Egulias\Tests\EmailValidator\Validation; use Egulias\EmailValidator\EmailLexer; -use Egulias\EmailValidator\EmailValidator; use Egulias\EmailValidator\Exception\CommaInDomain; use Egulias\EmailValidator\Exception\NoDomainPart; use Egulias\EmailValidator\Validation\EmailValidation; use Egulias\EmailValidator\Validation\MultipleErrors; use Egulias\EmailValidator\Validation\MultipleValidationWithAnd; -use Egulias\EmailValidator\Validation\NoRFCWarningsValidation; use Egulias\EmailValidator\Validation\RFCValidation; use Egulias\EmailValidator\Warning\AddressLiteral; use Egulias\EmailValidator\Warning\DomainLiteral; From 5f47ec09d841776ec319499c8f7c880f4e1c7b2f Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Tue, 26 Feb 2019 18:04:48 +0000 Subject: [PATCH 04/14] not actually used for object storage --- EmailValidator/EmailParser.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/EmailValidator/EmailParser.php b/EmailValidator/EmailParser.php index 09a63cc..6b7bad6 100644 --- a/EmailValidator/EmailParser.php +++ b/EmailValidator/EmailParser.php @@ -18,9 +18,9 @@ class EmailParser const EMAIL_MAX_LENGTH = 254; /** - * @var \SplObjectStorage|array + * @var array */ - protected $warnings; + protected $warnings = []; /** * @var string @@ -51,7 +51,6 @@ public function __construct(EmailLexer $lexer) $this->lexer = $lexer; $this->localPartParser = new LocalPart($this->lexer); $this->domainPartParser = new DomainPart($this->lexer); - $this->warnings = new \SplObjectStorage(); } /** From 91830b19a258972f71a741ccfc36c78d301aa835 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sun, 1 Sep 2019 11:04:53 +0100 Subject: [PATCH 05/14] Egulias\Tests\EmailValidator\Validation\SpoofCheckValidationTest::testEmailWithSpoofsIsInvalid fails if extension is not installed --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index 595caff..7cbd8d5 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "symfony/polyfill-intl-idn": "^1.10" }, "require-dev": { + "ext-intl": "*", "satooshi/php-coveralls": "^1.0.1", "phpunit/phpunit": "^4.8.36|^7.5.15", "dominicsayers/isemail": "^3.0.7" From dd68247775bd15198dd76a44947d65d87e731d49 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sun, 1 Sep 2019 11:29:52 +0100 Subject: [PATCH 06/14] satisfying psalm --- EmailValidator/EmailLexer.php | 16 +++++++++++++++- psalm.baseline.xml | 24 ++++++++++++++++++++++++ psalm.xml | 1 + 3 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 psalm.baseline.xml diff --git a/EmailValidator/EmailLexer.php b/EmailValidator/EmailLexer.php index 68c4cb9..4c01045 100644 --- a/EmailValidator/EmailLexer.php +++ b/EmailValidator/EmailLexer.php @@ -80,9 +80,23 @@ class EmailLexer extends AbstractLexer /** * @var array + * + * @psalm-var array{value:string, type:null|int, position:int}|array */ protected $previous = []; + /** + * The last matched/seen token. + * + * @var array + * + * @psalm-var array{value:string, type:null|int, position:int} + */ + public $token; + + /** + * @psalm-var array{value:'', type:null, position:0} + */ private static $nullToken = [ 'value' => '', 'type' => null, @@ -113,7 +127,7 @@ public function hasInvalidTokens() } /** - * @param string $type + * @param int $type * @throws \UnexpectedValueException * @return boolean * diff --git a/psalm.baseline.xml b/psalm.baseline.xml new file mode 100644 index 0000000..2759708 --- /dev/null +++ b/psalm.baseline.xml @@ -0,0 +1,24 @@ + + + + + self::$nullToken + + + + + null !== $this->lexer->token['type'] + + + + + $this->lexer->token['type'] !== EmailLexer::S_AT && null !== $this->lexer->token['type'] + $this->lexer->token['type'] !== EmailLexer::S_DQUOTE && null !== $this->lexer->token['type'] + + + + + parse + + + diff --git a/psalm.xml b/psalm.xml index 8a83de7..fb17dc8 100644 --- a/psalm.xml +++ b/psalm.xml @@ -5,6 +5,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" > From cbf7a806ef5ef094e24fb4a0ec90f7d841f54d3e Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sun, 1 Sep 2019 11:38:01 +0100 Subject: [PATCH 07/14] amending indentation --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1d3b48b..17b9d57 100644 --- a/.travis.yml +++ b/.travis.yml @@ -39,7 +39,7 @@ before_script: script: - vendor/bin/phpunit --coverage-clover build/logs/clover.xml - - if [ "$psalm" = "yes" ]; then vendor/bin/psalm; fi + - if [ "$psalm" = "yes" ]; then vendor/bin/psalm; fi after_script: - php vendor/bin/coveralls From da49ad1c863726a7939bcd41206af1a7ecee3e4a Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sun, 1 Sep 2019 11:51:17 +0100 Subject: [PATCH 08/14] disabling psalm on 5.6 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 17b9d57..184943f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,7 +9,6 @@ matrix: dist: trusty - php: 5.6 env: - - psalm=yes dist: xenial - php: 7.0 env: From 520defdb4639449b884ea8c47d9fc62f91f2ff0c Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sun, 1 Sep 2019 11:51:52 +0100 Subject: [PATCH 09/14] attempting to resolve psalm issue on 7.0 & 7.1 --- EmailValidator/EmailLexer.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/EmailValidator/EmailLexer.php b/EmailValidator/EmailLexer.php index 4c01045..cb47c01 100644 --- a/EmailValidator/EmailLexer.php +++ b/EmailValidator/EmailLexer.php @@ -94,6 +94,13 @@ class EmailLexer extends AbstractLexer */ public $token; + /** + * The next token in the input. + * + * @var array|null + */ + public $lookahead; + /** * @psalm-var array{value:'', type:null, position:0} */ @@ -106,6 +113,7 @@ class EmailLexer extends AbstractLexer public function __construct() { $this->previous = $this->token = self::$nullToken; + $this->lookahead = null; } /** From 079ac0e64943495ae05bbc4b3a601442ffcfc3bb Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Mon, 6 Jan 2020 21:01:14 +0000 Subject: [PATCH 10/14] dropping psalm from 7.0 matrix --- .travis.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 184943f..c282043 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,8 +11,6 @@ matrix: env: dist: xenial - php: 7.0 - env: - - psalm=yes dist: xenial - php: 7.1 env: From affd3ddbf5c13d287de2af85b36251c3d493f252 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sat, 18 Jan 2020 23:24:36 +0000 Subject: [PATCH 11/14] ext-intl removed as per egulias/EmailValidator#231 --- composer.json | 1 - 1 file changed, 1 deletion(-) diff --git a/composer.json b/composer.json index 7cbd8d5..595caff 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,6 @@ "symfony/polyfill-intl-idn": "^1.10" }, "require-dev": { - "ext-intl": "*", "satooshi/php-coveralls": "^1.0.1", "phpunit/phpunit": "^4.8.36|^7.5.15", "dominicsayers/isemail": "^3.0.7" From 2722fd22c9c853e9373b59c206e88699a1b793af Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sat, 18 Jan 2020 23:26:56 +0000 Subject: [PATCH 12/14] updating baseline with psalm 3.8.3 --- psalm.baseline.xml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/psalm.baseline.xml b/psalm.baseline.xml index 2759708..f2a86a4 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -1,21 +1,10 @@ - + self::$nullToken - - - null !== $this->lexer->token['type'] - - - - - $this->lexer->token['type'] !== EmailLexer::S_AT && null !== $this->lexer->token['type'] - $this->lexer->token['type'] !== EmailLexer::S_DQUOTE && null !== $this->lexer->token['type'] - - parse From 29f8f0106b2c5b3834842d8f81b8f68022dd6d7e Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sat, 18 Jan 2020 23:28:01 +0000 Subject: [PATCH 13/14] suppressing issue with Spoofchecker not being present, pending resolution of egulias/EmailValidator#231 --- psalm.baseline.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/psalm.baseline.xml b/psalm.baseline.xml index f2a86a4..f81df72 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -10,4 +10,10 @@ parse + + + Spoofchecker + Spoofchecker + + From 313ee8c71ddb26a968e1ae126e03e28499edd3d2 Mon Sep 17 00:00:00 2001 From: SignpostMarv Date: Sat, 18 Jan 2020 23:36:00 +0000 Subject: [PATCH 14/14] enable psalm on travis config for php 7.3 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index c282043..95a4687 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,6 +22,8 @@ matrix: dist: bionic - php: 7.3 dist: bionic + env: + - psalm=yes - php: 7.4 env: - psalm=yes