mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-09-01 21:19:25 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e5997fa97e | |||
| b531a23117 | |||
| 5f35e41eba |
@@ -1,3 +0,0 @@
|
||||
service_name: travis-ci
|
||||
src_dir: .
|
||||
coverage_clover: build/logs/clover*.xml
|
||||
@@ -0,0 +1,35 @@
|
||||
name: static analysis
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- '*.x'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
psalm:
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
strategy:
|
||||
fail-fast: true
|
||||
|
||||
name: Psalm
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 8.2
|
||||
ini-values: error_reporting=E_ALL
|
||||
tools: composer:v2
|
||||
coverage: none
|
||||
|
||||
- name: Install dependencies
|
||||
uses: ramsey/composer-install@v2
|
||||
|
||||
- name: Execute Psalm
|
||||
run: vendor/bin/psalm
|
||||
@@ -0,0 +1,48 @@
|
||||
name: tests
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- '*.x'
|
||||
pull_request:
|
||||
schedule:
|
||||
- cron: '0 0 * * *'
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-22.04
|
||||
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
php: [7.2, 7.3, 7.4, '8.0', 8.1, 8.2]
|
||||
|
||||
name: PHP ${{ matrix.php }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
ini-values: error_reporting=E_ALL
|
||||
tools: composer:v2
|
||||
coverage: xdebug
|
||||
|
||||
- name: Install dependencies
|
||||
uses: ramsey/composer-install@v2
|
||||
|
||||
- name: Setup logs directory
|
||||
run: mkdir -p build/logs
|
||||
|
||||
- name: Execute tests
|
||||
run: vendor/bin/phpunit --coverage-clover build/logs/clover.xml --exclude-group flaky
|
||||
|
||||
- name: Store artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: logs
|
||||
path: build/logs
|
||||
+4
-2
@@ -1,6 +1,8 @@
|
||||
phpunit.result.cache
|
||||
.idea
|
||||
build/
|
||||
report/
|
||||
vendor/
|
||||
composer.lock
|
||||
phpunit.result.cache
|
||||
.phpunit*
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
language: php
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- php: 7.4
|
||||
dist: bionic
|
||||
env:
|
||||
- psalm=yes
|
||||
- php: 8.0
|
||||
env:
|
||||
- psalm=yes
|
||||
dist: bionic
|
||||
#ppc64le support code
|
||||
- php: 7.4
|
||||
arch: ppc64le
|
||||
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 --exclude-group flaky
|
||||
- if [ "$psalm" = "yes" ]; then vendor/bin/psalm; fi
|
||||
|
||||
after_script:
|
||||
- php vendor/bin/coveralls
|
||||
@@ -1,6 +1,6 @@
|
||||
# EmailValidator
|
||||
|
||||
[](https://app.travis-ci.com/github/egulias/EmailValidator)
|
||||
[](https://github.com/egulias/EmailValidator/actions)
|
||||
[](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=3.x)
|
||||
[](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=3.x)
|
||||
|
||||
|
||||
+1
-2
@@ -14,11 +14,10 @@
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.2",
|
||||
"doctrine/lexer": "^1.2",
|
||||
"doctrine/lexer": "^1.2|^2",
|
||||
"symfony/polyfill-intl-idn": "^1.15"
|
||||
},
|
||||
"require-dev": {
|
||||
"php-coveralls/php-coveralls": "^2.2",
|
||||
"phpunit/phpunit": "^8.5.8|^9.3.3",
|
||||
"vimeo/psalm": "^4"
|
||||
},
|
||||
|
||||
Generated
-5028
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" executionOrder="defects" processIsolation="false" stopOnFailure="false">
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertDeprecationsToExceptions="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" executionOrder="defects" processIsolation="false" stopOnFailure="false">
|
||||
<coverage>
|
||||
<include>
|
||||
<directory>./src/</directory>
|
||||
|
||||
+5
-16
@@ -1,19 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<files psalm-version="3.8.3@389af1bfc739bfdff3f9e3dc7bd6499aee51a831">
|
||||
<file src="src/EmailLexer.php">
|
||||
<DocblockTypeContradiction occurrences="1">
|
||||
<code>self::$nullToken</code>
|
||||
</DocblockTypeContradiction>
|
||||
</file>
|
||||
<file src="src/Parser/Parser.php">
|
||||
<MissingReturnType occurrences="1">
|
||||
<code>parse</code>
|
||||
</MissingReturnType>
|
||||
</file>
|
||||
<file src="src/Validation/SpoofCheckValidation.php">
|
||||
<UndefinedClass occurrences="2">
|
||||
<code>Spoofchecker</code>
|
||||
<code>Spoofchecker</code>
|
||||
</UndefinedClass>
|
||||
<files psalm-version="5.4.0@62db5d4f6a7ae0a20f7cc5a4952d730272fc0863">
|
||||
<file src="src/Parser/DomainPart.php">
|
||||
<RedundantConditionGivenDocblockType occurrences="1">
|
||||
<code>null !== $this->lexer->token['type']</code>
|
||||
</RedundantConditionGivenDocblockType>
|
||||
</file>
|
||||
</files>
|
||||
|
||||
@@ -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"
|
||||
>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
@@ -13,5 +13,11 @@
|
||||
</projectFiles>
|
||||
|
||||
<issueHandlers>
|
||||
<DeprecatedMethod>
|
||||
<errorLevel type="suppress">
|
||||
<!-- This issue needs to be resolved before upgrading to Lexer 3 -->
|
||||
<referencedMethod name="Doctrine\Common\Lexer\Token::offsetGet"/>
|
||||
</errorLevel>
|
||||
</DeprecatedMethod>
|
||||
</issueHandlers>
|
||||
</psalm>
|
||||
|
||||
+14
-8
@@ -3,7 +3,11 @@
|
||||
namespace Egulias\EmailValidator;
|
||||
|
||||
use Doctrine\Common\Lexer\AbstractLexer;
|
||||
use Doctrine\Common\Lexer\Token;
|
||||
|
||||
/**
|
||||
* @extends AbstractLexer<int, string>
|
||||
*/
|
||||
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<int, string>
|
||||
*/
|
||||
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<int, string>|null
|
||||
*/
|
||||
public $lookahead;
|
||||
|
||||
@@ -207,11 +213,11 @@ class EmailLexer extends AbstractLexer
|
||||
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;
|
||||
|
||||
$this->previous = (array) $this->token;
|
||||
|
||||
if($this->lookahead === null) {
|
||||
$this->lookahead = self::$nullToken;
|
||||
}
|
||||
@@ -219,7 +225,7 @@ class EmailLexer extends AbstractLexer
|
||||
$hasNext = parent::moveNext();
|
||||
|
||||
if ($this->hasToRecord) {
|
||||
$this->accumulator .= $this->token['value'];
|
||||
$this->accumulator .= ((array) $this->token)['value'];
|
||||
}
|
||||
|
||||
return $hasNext;
|
||||
|
||||
+3
-3
@@ -29,7 +29,7 @@ abstract class Parser
|
||||
|
||||
public function __construct(EmailLexer $lexer)
|
||||
{
|
||||
$this->lexer = $lexer;
|
||||
$this->lexer = $lexer;
|
||||
}
|
||||
|
||||
public function parse(string $str) : Result
|
||||
@@ -51,7 +51,7 @@ abstract class Parser
|
||||
return $localPartResult;
|
||||
}
|
||||
|
||||
$domainPartResult = $this->parseRightFromAt();
|
||||
$domainPartResult = $this->parseRightFromAt();
|
||||
|
||||
if ($domainPartResult->isInvalid()) {
|
||||
return $domainPartResult;
|
||||
@@ -73,6 +73,6 @@ abstract class Parser
|
||||
$this->lexer->moveNext();
|
||||
$this->lexer->moveNext();
|
||||
|
||||
return $this->lexer->token['type'] !== EmailLexer::S_AT;
|
||||
return ((array) $this->lexer->token)['type'] !== EmailLexer::S_AT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,15 +31,15 @@ class Comment extends PartParser
|
||||
|
||||
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();
|
||||
@@ -58,10 +58,10 @@ class Comment extends PartParser
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -78,7 +78,7 @@ class Comment extends PartParser
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -87,12 +87,12 @@ class Comment extends PartParser
|
||||
}
|
||||
|
||||
$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);
|
||||
|
||||
@@ -23,7 +23,7 @@ class DomainComment implements CommentStrategy
|
||||
{
|
||||
//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
|
||||
|
||||
@@ -24,7 +24,7 @@ class LocalComment implements CommentStrategy
|
||||
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();
|
||||
|
||||
@@ -39,14 +39,14 @@ class DomainLiteral extends PartParser
|
||||
$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(
|
||||
@@ -57,21 +57,21 @@ class DomainLiteral extends PartParser
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
@@ -144,7 +144,7 @@ class DomainLiteral extends PartParser
|
||||
$this->warnings[IPV6Deprecated::CODE] = new IPV6Deprecated();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function convertIPv4ToIPv6(string $addressLiteralIPv4) : string
|
||||
{
|
||||
$matchesIP = [];
|
||||
@@ -189,7 +189,7 @@ class DomainLiteral extends PartParser
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
+39
-35
@@ -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;
|
||||
@@ -49,8 +50,8 @@ class DomainPart extends PartParser
|
||||
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();
|
||||
@@ -68,7 +69,7 @@ class DomainPart extends PartParser
|
||||
|
||||
$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();
|
||||
@@ -78,13 +79,13 @@ class DomainPart extends PartParser
|
||||
{
|
||||
$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();
|
||||
@@ -97,13 +98,13 @@ class DomainPart extends PartParser
|
||||
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();
|
||||
@@ -111,12 +112,12 @@ class DomainPart extends PartParser
|
||||
|
||||
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();
|
||||
@@ -124,11 +125,11 @@ class DomainPart extends PartParser
|
||||
|
||||
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();
|
||||
}
|
||||
@@ -155,8 +156,8 @@ class DomainPart extends PartParser
|
||||
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();
|
||||
|
||||
@@ -171,7 +172,7 @@ class DomainPart extends PartParser
|
||||
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);
|
||||
@@ -188,9 +189,9 @@ class DomainPart extends PartParser
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -200,7 +201,7 @@ class DomainPart extends PartParser
|
||||
}
|
||||
$this->lexer->moveNext();
|
||||
|
||||
} while (null !== $this->lexer->token['type']);
|
||||
} while (null !== ((array) $this->lexer->token)['type']);
|
||||
|
||||
$labelCheck = $this->checkLabelLength(true);
|
||||
if ($labelCheck->isInvalid()) {
|
||||
@@ -212,11 +213,14 @@ class DomainPart extends PartParser
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
private function checkNotAllowedChars(array $token) : Result
|
||||
/**
|
||||
* @psalm-param array|Token<int, string> $token
|
||||
*/
|
||||
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();
|
||||
}
|
||||
@@ -229,7 +233,7 @@ class DomainPart extends PartParser
|
||||
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);
|
||||
@@ -240,17 +244,17 @@ class DomainPart extends PartParser
|
||||
|
||||
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);
|
||||
@@ -269,8 +273,8 @@ class DomainPart extends PartParser
|
||||
$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();
|
||||
@@ -278,13 +282,13 @@ class DomainPart extends PartParser
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
+10
-10
@@ -30,24 +30,24 @@ class DoubleQuote extends PartParser
|
||||
EmailLexer::S_CR => true,
|
||||
EmailLexer::S_LF => true
|
||||
];
|
||||
|
||||
|
||||
$setSpecialsWarning = true;
|
||||
|
||||
$this->lexer->moveNext();
|
||||
|
||||
while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && null !== $this->lexer->token['type']) {
|
||||
if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) {
|
||||
while (((array) $this->lexer->token)['type'] !== EmailLexer::S_DQUOTE && null !== ((array) $this->lexer->token)['type']) {
|
||||
if (isset($special[((array) $this->lexer->token)['type']]) && $setSpecialsWarning) {
|
||||
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
|
||||
$setSpecialsWarning = false;
|
||||
}
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_BACKSLASH && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) {
|
||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_BACKSLASH && $this->lexer->isNextToken(EmailLexer::S_DQUOTE)) {
|
||||
$this->lexer->moveNext();
|
||||
}
|
||||
|
||||
$this->lexer->moveNext();
|
||||
|
||||
if (!$this->escaped() && isset($invalid[$this->lexer->token['type']])) {
|
||||
return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->token['value']);
|
||||
if (!$this->escaped() && isset($invalid[((array) $this->lexer->token)['type']])) {
|
||||
return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class DoubleQuote extends PartParser
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextToken(EmailLexer::S_AT) && $prev['type'] !== EmailLexer::S_BACKSLASH) {
|
||||
return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), $this->lexer->token['value']);
|
||||
return new InvalidEmail(new ExpectingATEXT("Expecting ATEXT between DQUOTE"), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
|
||||
return new ValidEmail();
|
||||
@@ -71,15 +71,15 @@ class DoubleQuote extends PartParser
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] === EmailLexer::GENERIC) {
|
||||
$description = 'https://tools.ietf.org/html/rfc5322#section-3.2.4 - quoted string should be a unit';
|
||||
return new InvalidEmail(new ExpectingATEXT($description), $this->lexer->token['value']);
|
||||
return new InvalidEmail(new ExpectingATEXT($description), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->lexer->find(EmailLexer::S_DQUOTE);
|
||||
} catch (\Exception $e) {
|
||||
return new InvalidEmail(new UnclosedQuotedString(), $this->lexer->token['value']);
|
||||
return new InvalidEmail(new UnclosedQuotedString(), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
$this->warnings[QuotedString::CODE] = new QuotedString($previous['value'], $this->lexer->token['value']);
|
||||
$this->warnings[QuotedString::CODE] = new QuotedString($previous['value'], ((array) $this->lexer->token)['value']);
|
||||
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
@@ -36,16 +36,16 @@ class FoldingWhiteSpace extends PartParser
|
||||
return $resultCRLF;
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_CR) {
|
||||
return new InvalidEmail(new CRNoLF(), $this->lexer->token['value']);
|
||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_CR) {
|
||||
return new InvalidEmail(new CRNoLF(), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC) && $previous['type'] !== EmailLexer::S_AT) {
|
||||
return new InvalidEmail(new AtextAfterCFWS(), $this->lexer->token['value']);
|
||||
return new InvalidEmail(new AtextAfterCFWS(), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_LF || $this->lexer->token['type'] === EmailLexer::C_NUL) {
|
||||
return new InvalidEmail(new ExpectingCTEXT(), $this->lexer->token['value']);
|
||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_LF || ((array) $this->lexer->token)['type'] === EmailLexer::C_NUL) {
|
||||
return new InvalidEmail(new ExpectingCTEXT(), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::S_AT) || $previous['type'] === EmailLexer::S_AT) {
|
||||
@@ -59,28 +59,28 @@ class FoldingWhiteSpace extends PartParser
|
||||
|
||||
protected function checkCRLFInFWS() : Result
|
||||
{
|
||||
if ($this->lexer->token['type'] !== EmailLexer::CRLF) {
|
||||
if (((array) $this->lexer->token)['type'] !== EmailLexer::CRLF) {
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
|
||||
return new InvalidEmail(new CRLFX2(), $this->lexer->token['value']);
|
||||
return new InvalidEmail(new CRLFX2(), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
|
||||
//this has no coverage. Condition is repeated from above one
|
||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB))) {
|
||||
return new InvalidEmail(new CRLFAtTheEnd(), $this->lexer->token['value']);
|
||||
return new InvalidEmail(new CRLFAtTheEnd(), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
|
||||
protected function isFWS() : bool
|
||||
{
|
||||
if ($this->escaped()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array($this->lexer->token['type'], self::FWS_TYPES);
|
||||
return in_array(((array) $this->lexer->token)['type'], self::FWS_TYPES);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,6 @@ class IDLeftPart extends LocalPart
|
||||
{
|
||||
protected function parseComments(): Result
|
||||
{
|
||||
return new InvalidEmail(new CommentsInIDRight(), $this->lexer->token['value']);
|
||||
return new InvalidEmail(new CommentsInIDRight(), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,9 +20,9 @@ class IDRightPart extends DomainPart
|
||||
EmailLexer::S_GREATERTHAN => true,
|
||||
EmailLexer::S_LOWERTHAN => true,
|
||||
];
|
||||
|
||||
if (isset($invalidDomainTokens[$this->lexer->token['type']])) {
|
||||
return new InvalidEmail(new ExpectingATEXT('Invalid token in domain: ' . $this->lexer->token['value']), $this->lexer->token['value']);
|
||||
|
||||
if (isset($invalidDomainTokens[((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();
|
||||
}
|
||||
|
||||
+15
-15
@@ -36,12 +36,12 @@ class LocalPart extends PartParser
|
||||
{
|
||||
$this->lexer->startRecording();
|
||||
|
||||
while ($this->lexer->token['type'] !== EmailLexer::S_AT && null !== $this->lexer->token['type']) {
|
||||
while (((array) $this->lexer->token)['type'] !== EmailLexer::S_AT && null !== ((array) $this->lexer->token)['type']) {
|
||||
if ($this->hasDotAtStart()) {
|
||||
return new InvalidEmail(new DotAtStart(), $this->lexer->token['value']);
|
||||
return new InvalidEmail(new DotAtStart(), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DQUOTE) {
|
||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DQUOTE) {
|
||||
$dquoteParsingResult = $this->parseDoubleQuote();
|
||||
|
||||
//Invalid double quote parsing
|
||||
@@ -50,8 +50,8 @@ class LocalPart extends PartParser
|
||||
}
|
||||
}
|
||||
|
||||
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 ) {
|
||||
$commentsResult = $this->parseComments();
|
||||
|
||||
//Invalid comment parsing
|
||||
@@ -60,14 +60,14 @@ class LocalPart extends PartParser
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token['value']);
|
||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new ConsecutiveDot(), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT &&
|
||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT &&
|
||||
$this->lexer->isNextToken(EmailLexer::S_AT)
|
||||
) {
|
||||
return new InvalidEmail(new DotAtEnd(), $this->lexer->token['value']);
|
||||
return new InvalidEmail(new DotAtEnd(), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
|
||||
$resultEscaping = $this->validateEscaping();
|
||||
@@ -99,8 +99,8 @@ class LocalPart extends PartParser
|
||||
|
||||
protected function validateTokens(bool $hasComments) : Result
|
||||
{
|
||||
if (isset(self::INVALID_TOKENS[$this->lexer->token['type']])) {
|
||||
return new InvalidEmail(new ExpectingATEXT('Invalid token found'), $this->lexer->token['value']);
|
||||
if (isset(self::INVALID_TOKENS[((array) $this->lexer->token)['type']])) {
|
||||
return new InvalidEmail(new ExpectingATEXT('Invalid token found'), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
return new ValidEmail();
|
||||
}
|
||||
@@ -110,7 +110,7 @@ class LocalPart extends PartParser
|
||||
return $this->localPart;
|
||||
}
|
||||
|
||||
private function parseLocalFWS() : Result
|
||||
private function parseLocalFWS() : Result
|
||||
{
|
||||
$foldingWS = new FoldingWhiteSpace($this->lexer);
|
||||
$resultFWS = $foldingWS->parse();
|
||||
@@ -122,7 +122,7 @@ class LocalPart extends PartParser
|
||||
|
||||
private function hasDotAtStart() : bool
|
||||
{
|
||||
return $this->lexer->token['type'] === EmailLexer::S_DOT && null === $this->lexer->getPrevious()['type'];
|
||||
return ((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && null === $this->lexer->getPrevious()['type'];
|
||||
}
|
||||
|
||||
private function parseDoubleQuote() : Result
|
||||
@@ -148,12 +148,12 @@ class LocalPart extends PartParser
|
||||
private function validateEscaping() : Result
|
||||
{
|
||||
//Backslash found
|
||||
if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) {
|
||||
if (((array) $this->lexer->token)['type'] !== EmailLexer::S_BACKSLASH) {
|
||||
return new ValidEmail();
|
||||
}
|
||||
|
||||
if ($this->lexer->isNextToken(EmailLexer::GENERIC)) {
|
||||
return new InvalidEmail(new ExpectingATEXT('Found ATOM after escaping'), $this->lexer->token['value']);
|
||||
return new InvalidEmail(new ExpectingATEXT('Found ATOM after escaping'), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
|
||||
if (!$this->lexer->isNextTokenAny(array(EmailLexer::S_SP, EmailLexer::S_HTAB, EmailLexer::C_DEL))) {
|
||||
|
||||
@@ -45,8 +45,8 @@ abstract class PartParser
|
||||
|
||||
protected function checkConsecutiveDots() : Result
|
||||
{
|
||||
if ($this->lexer->token['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new ConsecutiveDot(), $this->lexer->token['value']);
|
||||
if (((array) $this->lexer->token)['type'] === EmailLexer::S_DOT && $this->lexer->isNextToken(EmailLexer::S_DOT)) {
|
||||
return new InvalidEmail(new ConsecutiveDot(), ((array) $this->lexer->token)['value']);
|
||||
}
|
||||
|
||||
return new ValidEmail();
|
||||
@@ -58,6 +58,6 @@ abstract class PartParser
|
||||
|
||||
return $previous && $previous['type'] === EmailLexer::S_BACKSLASH
|
||||
&&
|
||||
$this->lexer->token['type'] !== EmailLexer::GENERIC;
|
||||
((array) $this->lexer->token)['type'] !== EmailLexer::GENERIC;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user