Compare commits

..

20 Commits

Author SHA1 Message Date
Marcin Michalski ade6887fd9 Fix local part length check (#233) 2020-02-13 23:36:52 +01:00
Denis Ryabov 5065fafc8c Fix "Trying to access array offset on value of type null" (#228)
Added a check that `$previous` is not null (i.e. previous token exists)
2020-02-12 23:28:28 +01:00
SignpostMarv e834eea530 Enabling psalm on php >= 7.1, fixing #125, #168, #169, partially fixing #177 (#190)
* experimenting with psalm

* loading in symfony polyfill, partially resolves egulias/EmailValidator#177, but SpoofChecker does not seem to be polyfilled in symfony/polyfill-intl-*

* removing unused imports, fixes egulias/EmailValidator#168 and egulias/EmailValidator#169

* not actually used for object storage

* Egulias\Tests\EmailValidator\Validation\SpoofCheckValidationTest::testEmailWithSpoofsIsInvalid fails if extension is not installed

* satisfying psalm

* amending indentation

* disabling psalm on 5.6

* attempting to resolve psalm issue on 7.0 & 7.1

* dropping psalm from 7.0 matrix

* ext-intl removed as per egulias/EmailValidator#231

* updating baseline with psalm 3.8.3

* suppressing issue with Spoofchecker not being present, pending resolution of egulias/EmailValidator#231

* enable psalm on travis config for php 7.3
2020-01-20 22:40:59 +01:00
SignpostMarv c4b8d12921 Composer tweaks (#227)
* lockfile is not present in git repo

* correcting autoloader

* package is listed on packagist, repo listing in composer.json causes install issues on windows

Co-authored-by: Eduardo Gulias Davis <eduardomgulias@gmail.com>
2020-01-05 15:11:20 +01:00
Graham Campbell 3d09cd0b58 Update .gitignore (#225) 2020-01-05 14:48:40 +01:00
Graham Campbell 3e3b1e562b Removed unneeded repositories section from composer.json (#226) 2020-01-02 13:23:54 +01:00
SignpostMarv ed32faa118 using ::class instead of FQCN literal, fixes egulias/EmailValidator#125 (#230) 2020-01-02 13:02:44 +01:00
Graham Campbell 834593d590 Fixed tests (#223) 2019-12-30 09:14:25 +01:00
Graham Campbell a6255605af Important compser.json fix (#220) 2019-12-20 13:49:39 +01:00
felipeAraujo 950d0663dc making the docs more precise in order to some lint tools don't give error (#216) 2019-09-15 22:23:48 +02:00
Nicolas Grekas 92dd169c32 Advertise return annotations from doctrine/lexer (#209) 2019-08-13 19:33:27 +02:00
Nicolas Grekas a6c8d7101b Fix PHP 7.4 support (#203)
Adding support for deprecated PHP behaviours.
2019-07-19 22:52:08 +02:00
Eduardo Gulias Davis 128cc721d7 fix(201) - empty domain 2019-06-23 12:14:27 +02:00
Viktor Szépe c26463ff92 Fix class name and parameter types (#200)
* Fix class name and paramtere types

* HHVM is not a thing anymore
2019-05-17 00:02:54 +02:00
Victor Bocharsky a09af2de87 Minor: Use SVG format for some bad looking badges in README (#197) 2019-05-07 22:08:52 +02:00
Victor Bocharsky c802f106b3 Simplify installation command in README (#198)
Composer will automatically use BC constraint, like `^2.1.7`
2019-05-07 22:08:00 +02:00
Joël Harkes 709f21f927 Update MultipleValidationWithAnd.php (#179)
* Update MultipleValidationWithAnd.php

Fix all validations actually get executed when mode is ALLOW_ALL_ERRORS (1)

* this should validate not breake out.

* Actually fix the unit tests

* add real invalid email test
2018-12-04 23:38:24 +01:00
Eduardo Gulias Davis e68c26e065 Update supported RFCs (#186)
solves #186
2018-12-03 11:33:36 +01:00
Andrey Bolonin 8036f2bd05 Update .travis.yml (#182) 2018-11-03 22:52:10 +01:00
nikitos569 0043eab0c5 Update README.md (#180) 2018-10-19 00:14:56 +02:00
29 changed files with 451 additions and 128 deletions
+2 -1
View File
@@ -1,3 +1,4 @@
.idea
composer.lock
report/ report/
vendor/ vendor/
.idea
+32 -23
View File
@@ -1,35 +1,44 @@
sudo: false
language: php language: php
php:
- 5.5
- 5.6
- 7.0
- 7.1
- 7.2
- hhvm
env:
global:
- deps=no
matrix: matrix:
fast_finish: true
include: include:
- php: 5.5 - php: 5.5.9
dist: trusty
env: deps=low env: deps=low
- php: 5.5
dist: trusty
- php: 5.6 - php: 5.6
env: deps=high env:
dist: xenial
- php: 7.0
dist: xenial
- php: 7.1
env:
- psalm=yes
dist: bionic
- php: 7.2
env:
- psalm=yes
dist: bionic
- php: 7.3
dist: bionic
env:
- psalm=yes
- php: 7.4
env:
- psalm=yes
dist: bionic
install: install:
- if [ "$deps" = "no" ]; then composer install; fi - if [ "$deps" = "low" ]; then composer update --prefer-lowest; else composer install; fi
- if [ "$deps" = "low" ]; then composer update --prefer-lowest; fi - if [ "$psalm" = "yes" ]; then composer require --dev vimeo/psalm; fi
- if [ "$deps" = "high" ]; then composer update; fi
before_script:
- mkdir -p build/logs
script: script:
- mkdir -p build/logs - vendor/bin/phpunit --coverage-clover build/logs/clover.xml
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml - if [ "$psalm" = "yes" ]; then vendor/bin/psalm; fi
after_script: after_script:
- php vendor/bin/coveralls - php vendor/bin/coveralls
+64 -6
View File
@@ -73,25 +73,73 @@ class EmailLexer extends AbstractLexer
'\0' => self::C_NUL, '\0' => self::C_NUL,
); );
/**
* @var bool
*/
protected $hasInvalidTokens = false; protected $hasInvalidTokens = false;
protected $previous; /**
* @var array
*
* @psalm-var array{value:string, type:null|int, position:int}|array<empty, empty>
*/
protected $previous = [];
/**
* The last matched/seen token.
*
* @var array
*
* @psalm-var array{value:string, type:null|int, position:int}
*/
public $token;
/**
* The next token in the input.
*
* @var array|null
*/
public $lookahead;
/**
* @psalm-var array{value:'', type:null, position:0}
*/
private static $nullToken = [
'value' => '',
'type' => null,
'position' => 0,
];
public function __construct()
{
$this->previous = $this->token = self::$nullToken;
$this->lookahead = null;
}
/**
* @return void
*/
public function reset() public function reset()
{ {
$this->hasInvalidTokens = false; $this->hasInvalidTokens = false;
parent::reset(); parent::reset();
$this->previous = $this->token = self::$nullToken;
} }
/**
* @return bool
*/
public function hasInvalidTokens() public function hasInvalidTokens()
{ {
return $this->hasInvalidTokens; return $this->hasInvalidTokens;
} }
/** /**
* @param $type * @param int $type
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
* @return boolean * @return boolean
*
* @psalm-suppress InvalidScalarArgument
*/ */
public function find($type) public function find($type)
{ {
@@ -107,7 +155,7 @@ class EmailLexer extends AbstractLexer
/** /**
* getPrevious * getPrevious
* *
* @return array token * @return array
*/ */
public function getPrevious() public function getPrevious()
{ {
@@ -122,8 +170,10 @@ class EmailLexer extends AbstractLexer
public function moveNext() public function moveNext()
{ {
$this->previous = $this->token; $this->previous = $this->token;
$hasNext = parent::moveNext();
$this->token = $this->token ?: self::$nullToken;
return parent::moveNext(); return $hasNext;
} }
/** /**
@@ -179,6 +229,11 @@ class EmailLexer extends AbstractLexer
return self::GENERIC; return self::GENERIC;
} }
/**
* @param string $value
*
* @return bool
*/
protected function isValid($value) protected function isValid($value)
{ {
if (isset($this->charValue[$value])) { if (isset($this->charValue[$value])) {
@@ -189,7 +244,7 @@ class EmailLexer extends AbstractLexer
} }
/** /**
* @param $value * @param string $value
* @return bool * @return bool
*/ */
protected function isNullType($value) protected function isNullType($value)
@@ -202,7 +257,7 @@ class EmailLexer extends AbstractLexer
} }
/** /**
* @param $value * @param string $value
* @return bool * @return bool
*/ */
protected function isUTF8Invalid($value) protected function isUTF8Invalid($value)
@@ -214,6 +269,9 @@ class EmailLexer extends AbstractLexer
return false; return false;
} }
/**
* @return string
*/
protected function getModifiers() protected function getModifiers()
{ {
return 'iu'; return 'iu';
+36 -3
View File
@@ -17,11 +17,33 @@ class EmailParser
{ {
const EMAIL_MAX_LENGTH = 254; const EMAIL_MAX_LENGTH = 254;
protected $warnings; /**
* @var array
*/
protected $warnings = [];
/**
* @var string
*/
protected $domainPart = ''; protected $domainPart = '';
/**
* @var string
*/
protected $localPart = ''; protected $localPart = '';
/**
* @var EmailLexer
*/
protected $lexer; protected $lexer;
/**
* @var LocalPart
*/
protected $localPartParser; protected $localPartParser;
/**
* @var DomainPart
*/
protected $domainPartParser; protected $domainPartParser;
public function __construct(EmailLexer $lexer) public function __construct(EmailLexer $lexer)
@@ -29,11 +51,10 @@ class EmailParser
$this->lexer = $lexer; $this->lexer = $lexer;
$this->localPartParser = new LocalPart($this->lexer); $this->localPartParser = new LocalPart($this->lexer);
$this->domainPartParser = new DomainPart($this->lexer); $this->domainPartParser = new DomainPart($this->lexer);
$this->warnings = new \SplObjectStorage();
} }
/** /**
* @param $str * @param string $str
* @return array * @return array
*/ */
public function parse($str) public function parse($str)
@@ -57,6 +78,9 @@ class EmailParser
return array('local' => $this->localPart, 'domain' => $this->domainPart); return array('local' => $this->localPart, 'domain' => $this->domainPart);
} }
/**
* @return Warning\Warning[]
*/
public function getWarnings() public function getWarnings()
{ {
$localPartWarnings = $this->localPartParser->getWarnings(); $localPartWarnings = $this->localPartParser->getWarnings();
@@ -68,11 +92,17 @@ class EmailParser
return $this->warnings; return $this->warnings;
} }
/**
* @return string
*/
public function getParsedDomainPart() public function getParsedDomainPart()
{ {
return $this->domainPart; return $this->domainPart;
} }
/**
* @param string $email
*/
protected function setParts($email) protected function setParts($email)
{ {
$parts = explode('@', $email); $parts = explode('@', $email);
@@ -80,6 +110,9 @@ class EmailParser
$this->localPart = $parts[0]; $this->localPart = $parts[0];
} }
/**
* @return bool
*/
protected function hasAtToken() protected function hasAtToken()
{ {
$this->lexer->moveNext(); $this->lexer->moveNext();
+5 -5
View File
@@ -13,12 +13,12 @@ class EmailValidator
private $lexer; private $lexer;
/** /**
* @var array * @var Warning\Warning[]
*/ */
protected $warnings; protected $warnings = [];
/** /**
* @var InvalidEmail * @var InvalidEmail|null
*/ */
protected $error; protected $error;
@@ -28,7 +28,7 @@ class EmailValidator
} }
/** /**
* @param $email * @param string $email
* @param EmailValidation $emailValidation * @param EmailValidation $emailValidation
* @return bool * @return bool
*/ */
@@ -58,7 +58,7 @@ class EmailValidator
} }
/** /**
* @return InvalidEmail * @return InvalidEmail|null
*/ */
public function getError() public function getError()
{ {
+1 -1
View File
@@ -2,7 +2,7 @@
namespace Egulias\EmailValidator\Exception; namespace Egulias\EmailValidator\Exception;
class ExpectedQPair extends InvalidEmail class ExpectingQPair extends InvalidEmail
{ {
const CODE = 136; const CODE = 136;
const REASON = "Expecting QPAIR"; const REASON = "Expecting QPAIR";
-2
View File
@@ -2,8 +2,6 @@
namespace Egulias\EmailValidator\Exception; namespace Egulias\EmailValidator\Exception;
use Egulias\EmailValidator\Exception\InvalidEmail;
class NoDNSRecord extends InvalidEmail class NoDNSRecord extends InvalidEmail
{ {
const CODE = 5; const CODE = 5;
+66 -20
View File
@@ -35,27 +35,17 @@ use Egulias\EmailValidator\Warning\TLD;
class DomainPart extends Parser class DomainPart extends Parser
{ {
const DOMAIN_MAX_LENGTH = 254; const DOMAIN_MAX_LENGTH = 254;
/**
* @var string
*/
protected $domainPart = ''; protected $domainPart = '';
public function parse($domainPart) public function parse($domainPart)
{ {
$this->lexer->moveNext(); $this->lexer->moveNext();
if ($this->lexer->token['type'] === EmailLexer::S_DOT) { $this->performDomainStartChecks();
throw new DotAtStart();
}
if ($this->lexer->token['type'] === EmailLexer::S_EMPTY) {
throw new NoDomainPart();
}
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN) {
throw new DomainHyphened();
}
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->warnings[DeprecatedComment::CODE] = new DeprecatedComment();
$this->parseDomainComments();
}
$domain = $this->doParseDomainPart(); $domain = $this->doParseDomainPart();
@@ -77,11 +67,50 @@ class DomainPart extends Parser
$this->domainPart = $domain; $this->domainPart = $domain;
} }
private function performDomainStartChecks()
{
$this->checkInvalidTokensAfterAT();
$this->checkEmptyDomain();
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->warnings[DeprecatedComment::CODE] = new DeprecatedComment();
$this->parseDomainComments();
}
}
private function checkEmptyDomain()
{
$thereIsNoDomain = $this->lexer->token['type'] === EmailLexer::S_EMPTY ||
($this->lexer->token['type'] === EmailLexer::S_SP &&
!$this->lexer->isNextToken(EmailLexer::GENERIC));
if ($thereIsNoDomain) {
throw new NoDomainPart();
}
}
private function checkInvalidTokensAfterAT()
{
if ($this->lexer->token['type'] === EmailLexer::S_DOT) {
throw new DotAtStart();
}
if ($this->lexer->token['type'] === EmailLexer::S_HYPHEN) {
throw new DomainHyphened();
}
}
/**
* @return string
*/
public function getDomainPart() public function getDomainPart()
{ {
return $this->domainPart; return $this->domainPart;
} }
/**
* @param string $addressLiteral
* @param int $maxGroups
*/
public function checkIPV6Tag($addressLiteral, $maxGroups = 8) public function checkIPV6Tag($addressLiteral, $maxGroups = 8)
{ {
$prev = $this->lexer->getPrevious(); $prev = $this->lexer->getPrevious();
@@ -125,6 +154,9 @@ class DomainPart extends Parser
} }
} }
/**
* @return string
*/
protected function doParseDomainPart() protected function doParseDomainPart()
{ {
$domain = ''; $domain = '';
@@ -166,12 +198,12 @@ class DomainPart extends Parser
$domain .= $this->lexer->token['value']; $domain .= $this->lexer->token['value'];
$this->lexer->moveNext(); $this->lexer->moveNext();
} while ($this->lexer->token); } while (null !== $this->lexer->token['type']);
return $domain; return $domain;
} }
private function checkNotAllowedChars($token) private function checkNotAllowedChars(array $token)
{ {
$notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true]; $notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true];
if (isset($notAllowed[$token['type']])) { if (isset($notAllowed[$token['type']])) {
@@ -179,6 +211,9 @@ class DomainPart extends Parser
} }
} }
/**
* @return string|false
*/
protected function parseDomainLiteral() protected function parseDomainLiteral()
{ {
if ($this->lexer->isNextToken(EmailLexer::S_COLON)) { if ($this->lexer->isNextToken(EmailLexer::S_COLON)) {
@@ -195,6 +230,9 @@ class DomainPart extends Parser
return $this->doParseDomainLiteral(); return $this->doParseDomainLiteral();
} }
/**
* @return string|false
*/
protected function doParseDomainLiteral() protected function doParseDomainLiteral()
{ {
$IPv6TAG = false; $IPv6TAG = false;
@@ -262,6 +300,11 @@ class DomainPart extends Parser
return $addressLiteral; return $addressLiteral;
} }
/**
* @param string $addressLiteral
*
* @return string|false
*/
protected function checkIPV4Tag($addressLiteral) protected function checkIPV4Tag($addressLiteral)
{ {
$matchesIP = array(); $matchesIP = array();
@@ -279,13 +322,13 @@ class DomainPart extends Parser
return false; return false;
} }
// Convert IPv4 part to IPv6 format for further testing // 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; return $addressLiteral;
} }
protected function checkDomainPartExceptions($prev) protected function checkDomainPartExceptions(array $prev)
{ {
$invalidDomainTokens = array( $invalidDomainTokens = array(
EmailLexer::S_DQUOTE => true, EmailLexer::S_DQUOTE => true,
@@ -320,6 +363,9 @@ class DomainPart extends Parser
} }
} }
/**
* @return bool
*/
protected function hasBrackets() protected function hasBrackets()
{ {
if ($this->lexer->token['type'] !== EmailLexer::S_OPENBRACKET) { if ($this->lexer->token['type'] !== EmailLexer::S_OPENBRACKET) {
@@ -335,7 +381,7 @@ class DomainPart extends Parser
return true; return true;
} }
protected function checkLabelLength($prev) protected function checkLabelLength(array $prev)
{ {
if ($this->lexer->token['type'] === EmailLexer::S_DOT && if ($this->lexer->token['type'] === EmailLexer::S_DOT &&
$prev['type'] === EmailLexer::GENERIC && $prev['type'] === EmailLexer::GENERIC &&
+16 -9
View File
@@ -5,7 +5,6 @@ namespace Egulias\EmailValidator\Parser;
use Egulias\EmailValidator\Exception\DotAtEnd; use Egulias\EmailValidator\Exception\DotAtEnd;
use Egulias\EmailValidator\Exception\DotAtStart; use Egulias\EmailValidator\Exception\DotAtStart;
use Egulias\EmailValidator\EmailLexer; use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Exception\ExpectingAT; use Egulias\EmailValidator\Exception\ExpectingAT;
use Egulias\EmailValidator\Exception\ExpectingATEXT; use Egulias\EmailValidator\Exception\ExpectingATEXT;
use Egulias\EmailValidator\Exception\UnclosedQuotedString; use Egulias\EmailValidator\Exception\UnclosedQuotedString;
@@ -20,9 +19,10 @@ class LocalPart extends Parser
$parseDQuote = true; $parseDQuote = true;
$closingQuote = false; $closingQuote = false;
$openedParenthesis = 0; $openedParenthesis = 0;
$totalLength = 0;
while ($this->lexer->token['type'] !== EmailLexer::S_AT && $this->lexer->token) { while ($this->lexer->token['type'] !== EmailLexer::S_AT && null !== $this->lexer->token['type']) {
if ($this->lexer->token['type'] === EmailLexer::S_DOT && !$this->lexer->getPrevious()) { if ($this->lexer->token['type'] === EmailLexer::S_DOT && null === $this->lexer->getPrevious()['type']) {
throw new DotAtStart(); throw new DotAtStart();
} }
@@ -35,12 +35,13 @@ class LocalPart extends Parser
$this->parseComments(); $this->parseComments();
$openedParenthesis += $this->getOpenedParenthesis(); $openedParenthesis += $this->getOpenedParenthesis();
} }
if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) { if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) {
if ($openedParenthesis === 0) { if ($openedParenthesis === 0) {
throw new UnopenedComment(); throw new UnopenedComment();
} else {
$openedParenthesis--;
} }
$openedParenthesis--;
} }
$this->checkConsecutiveDots(); $this->checkConsecutiveDots();
@@ -58,15 +59,18 @@ class LocalPart extends Parser
$this->parseFWS(); $this->parseFWS();
} }
$totalLength += strlen($this->lexer->token['value']);
$this->lexer->moveNext(); $this->lexer->moveNext();
} }
$prev = $this->lexer->getPrevious(); if ($totalLength > LocalTooLong::LOCAL_PART_LENGTH) {
if (strlen($prev['value']) > LocalTooLong::LOCAL_PART_LENGTH) {
$this->warnings[LocalTooLong::CODE] = new LocalTooLong(); $this->warnings[LocalTooLong::CODE] = new LocalTooLong();
} }
} }
/**
* @return bool
*/
protected function parseDoubleQuote() protected function parseDoubleQuote()
{ {
$parseAgain = true; $parseAgain = true;
@@ -86,7 +90,7 @@ class LocalPart extends Parser
$this->lexer->moveNext(); $this->lexer->moveNext();
while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && $this->lexer->token) { while ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE && null !== $this->lexer->token['type']) {
$parseAgain = false; $parseAgain = false;
if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) { if (isset($special[$this->lexer->token['type']]) && $setSpecialsWarning) {
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS(); $this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
@@ -118,7 +122,10 @@ class LocalPart extends Parser
return $parseAgain; return $parseAgain;
} }
protected function isInvalidToken($token, $closingQuote) /**
* @param bool $closingQuote
*/
protected function isInvalidToken(array $token, $closingQuote)
{ {
$forbidden = array( $forbidden = array(
EmailLexer::S_COMMA, EmailLexer::S_COMMA,
+37 -3
View File
@@ -8,7 +8,7 @@ use Egulias\EmailValidator\Exception\ConsecutiveDot;
use Egulias\EmailValidator\Exception\CRLFAtTheEnd; use Egulias\EmailValidator\Exception\CRLFAtTheEnd;
use Egulias\EmailValidator\Exception\CRLFX2; use Egulias\EmailValidator\Exception\CRLFX2;
use Egulias\EmailValidator\Exception\CRNoLF; use Egulias\EmailValidator\Exception\CRNoLF;
use Egulias\EmailValidator\Exception\ExpectedQPair; use Egulias\EmailValidator\Exception\ExpectingQPair;
use Egulias\EmailValidator\Exception\ExpectingATEXT; use Egulias\EmailValidator\Exception\ExpectingATEXT;
use Egulias\EmailValidator\Exception\ExpectingCTEXT; use Egulias\EmailValidator\Exception\ExpectingCTEXT;
use Egulias\EmailValidator\Exception\UnclosedComment; use Egulias\EmailValidator\Exception\UnclosedComment;
@@ -21,8 +21,19 @@ use Egulias\EmailValidator\Warning\QuotedString;
abstract class Parser abstract class Parser
{ {
/**
* @var \Egulias\EmailValidator\Warning\Warning[]
*/
protected $warnings = []; protected $warnings = [];
/**
* @var EmailLexer
*/
protected $lexer; protected $lexer;
/**
* @var int
*/
protected $openedParenthesis = 0; protected $openedParenthesis = 0;
public function __construct(EmailLexer $lexer) public function __construct(EmailLexer $lexer)
@@ -30,11 +41,17 @@ abstract class Parser
$this->lexer = $lexer; $this->lexer = $lexer;
} }
/**
* @return \Egulias\EmailValidator\Warning\Warning[]
*/
public function getWarnings() public function getWarnings()
{ {
return $this->warnings; return $this->warnings;
} }
/**
* @param string $str
*/
abstract public function parse($str); abstract public function parse($str);
/** @return int */ /** @return int */
@@ -50,7 +67,7 @@ abstract class Parser
{ {
if (!($this->lexer->token['type'] === EmailLexer::INVALID if (!($this->lexer->token['type'] === EmailLexer::INVALID
|| $this->lexer->token['type'] === EmailLexer::C_DEL)) { || $this->lexer->token['type'] === EmailLexer::C_DEL)) {
throw new ExpectedQPair(); throw new ExpectingQPair();
} }
$this->warnings[QuotedPart::CODE] = $this->warnings[QuotedPart::CODE] =
@@ -80,6 +97,9 @@ abstract class Parser
} }
} }
/**
* @return bool
*/
protected function isUnclosedComment() protected function isUnclosedComment()
{ {
try { try {
@@ -122,6 +142,9 @@ abstract class Parser
} }
} }
/**
* @return bool
*/
protected function isFWS() protected function isFWS()
{ {
if ($this->escaped()) { if ($this->escaped()) {
@@ -140,11 +163,14 @@ abstract class Parser
return false; return false;
} }
/**
* @return bool
*/
protected function escaped() protected function escaped()
{ {
$previous = $this->lexer->getPrevious(); $previous = $this->lexer->getPrevious();
if ($previous['type'] === EmailLexer::S_BACKSLASH if ($previous && $previous['type'] === EmailLexer::S_BACKSLASH
&& &&
$this->lexer->token['type'] !== EmailLexer::GENERIC $this->lexer->token['type'] !== EmailLexer::GENERIC
) { ) {
@@ -154,6 +180,9 @@ abstract class Parser
return false; return false;
} }
/**
* @return bool
*/
protected function warnEscaping() protected function warnEscaping()
{ {
if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) { if ($this->lexer->token['type'] !== EmailLexer::S_BACKSLASH) {
@@ -174,6 +203,11 @@ abstract class Parser
} }
/**
* @param bool $hasClosingQuote
*
* @return bool
*/
protected function checkDQUOTE($hasClosingQuote) protected function checkDQUOTE($hasClosingQuote)
{ {
if ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE) { if ($this->lexer->token['type'] !== EmailLexer::S_DQUOTE) {
@@ -15,13 +15,13 @@ class DNSCheckValidation implements EmailValidation
private $warnings = []; private $warnings = [];
/** /**
* @var InvalidEmail * @var InvalidEmail|null
*/ */
private $error; private $error;
public function __construct() 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__)); throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
} }
} }
@@ -49,6 +49,11 @@ class DNSCheckValidation implements EmailValidation
return $this->warnings; return $this->warnings;
} }
/**
* @param string $host
*
* @return bool
*/
protected function checkDNS($host) protected function checkDNS($host)
{ {
$variant = INTL_IDNA_VARIANT_2003; $variant = INTL_IDNA_VARIANT_2003;
@@ -6,6 +6,9 @@ use Exception;
class EmptyValidationList extends \InvalidArgumentException class EmptyValidationList extends \InvalidArgumentException
{ {
/**
* @param int $code
*/
public function __construct($code = 0, Exception $previous = null) public function __construct($code = 0, Exception $previous = null)
{ {
parent::__construct("Empty validation list is not allowed", $code, $previous); parent::__construct("Empty validation list is not allowed", $code, $previous);
+7 -1
View File
@@ -9,16 +9,22 @@ class MultipleErrors extends InvalidEmail
const CODE = 999; const CODE = 999;
const REASON = "Accumulated errors for multiple validations"; const REASON = "Accumulated errors for multiple validations";
/** /**
* @var array * @var InvalidEmail[]
*/ */
private $errors = []; private $errors = [];
/**
* @param InvalidEmail[] $errors
*/
public function __construct(array $errors) public function __construct(array $errors)
{ {
$this->errors = $errors; $this->errors = $errors;
parent::__construct(); parent::__construct();
} }
/**
* @return InvalidEmail[]
*/
public function getErrors() public function getErrors()
{ {
return $this->errors; return $this->errors;
@@ -30,12 +30,12 @@ class MultipleValidationWithAnd implements EmailValidation
private $warnings = []; private $warnings = [];
/** /**
* @var MultipleErrors * @var MultipleErrors|null
*/ */
private $error; private $error;
/** /**
* @var bool * @var int
*/ */
private $mode; private $mode;
@@ -62,7 +62,8 @@ class MultipleValidationWithAnd implements EmailValidation
$errors = []; $errors = [];
foreach ($this->validations as $validation) { foreach ($this->validations as $validation) {
$emailLexer->reset(); $emailLexer->reset();
$result = $result && $validation->isValid($email, $emailLexer); $validationResult = $validation->isValid($email, $emailLexer);
$result = $result && $validationResult;
$this->warnings = array_merge($this->warnings, $validation->getWarnings()); $this->warnings = array_merge($this->warnings, $validation->getWarnings());
$errors = $this->addNewError($validation->getError(), $errors); $errors = $this->addNewError($validation->getError(), $errors);
@@ -78,6 +79,12 @@ class MultipleValidationWithAnd implements EmailValidation
return $result; 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) private function addNewError($possibleError, array $errors)
{ {
if (null !== $possibleError) { if (null !== $possibleError) {
@@ -87,13 +94,20 @@ class MultipleValidationWithAnd implements EmailValidation
return $errors; return $errors;
} }
/**
* @param bool $result
*
* @return bool
*/
private function shouldStop($result) private function shouldStop($result)
{ {
return !$result && $this->mode === self::STOP_ON_ERROR; return !$result && $this->mode === self::STOP_ON_ERROR;
} }
/** /**
* {@inheritdoc} * Returns the validation errors.
*
* @return MultipleErrors|null
*/ */
public function getError() public function getError()
{ {
@@ -9,7 +9,7 @@ use Egulias\EmailValidator\Validation\Error\RFCWarnings;
class NoRFCWarningsValidation extends RFCValidation class NoRFCWarningsValidation extends RFCValidation
{ {
/** /**
* @var InvalidEmail * @var InvalidEmail|null
*/ */
private $error; private $error;
+2 -2
View File
@@ -9,7 +9,7 @@ use Egulias\EmailValidator\Exception\InvalidEmail;
class RFCValidation implements EmailValidation class RFCValidation implements EmailValidation
{ {
/** /**
* @var EmailParser * @var EmailParser|null
*/ */
private $parser; private $parser;
@@ -19,7 +19,7 @@ class RFCValidation implements EmailValidation
private $warnings = []; private $warnings = [];
/** /**
* @var InvalidEmail * @var InvalidEmail|null
*/ */
private $error; private $error;
@@ -10,7 +10,7 @@ use \Spoofchecker;
class SpoofCheckValidation implements EmailValidation class SpoofCheckValidation implements EmailValidation
{ {
/** /**
* @var InvalidEmail * @var InvalidEmail|null
*/ */
private $error; private $error;
@@ -21,6 +21,9 @@ class SpoofCheckValidation implements EmailValidation
} }
} }
/**
* @psalm-suppress InvalidArgument
*/
public function isValid($email, EmailLexer $emailLexer) public function isValid($email, EmailLexer $emailLexer)
{ {
$checker = new Spoofchecker(); $checker = new Spoofchecker();
@@ -33,6 +36,9 @@ class SpoofCheckValidation implements EmailValidation
return $this->error === null; return $this->error === null;
} }
/**
* @return InvalidEmail|null
*/
public function getError() public function getError()
{ {
return $this->error; return $this->error;
+4
View File
@@ -6,6 +6,10 @@ class QuotedPart extends Warning
{ {
const CODE = 36; const CODE = 36;
/**
* @param scalar $prevToken
* @param scalar $postToken
*/
public function __construct($prevToken, $postToken) public function __construct($prevToken, $postToken)
{ {
$this->message = "Deprecated Quoted String found between $prevToken and $postToken"; $this->message = "Deprecated Quoted String found between $prevToken and $postToken";
+4
View File
@@ -6,6 +6,10 @@ class QuotedString extends Warning
{ {
const CODE = 11; const CODE = 11;
/**
* @param scalar $prevToken
* @param scalar $postToken
*/
public function __construct($prevToken, $postToken) public function __construct($prevToken, $postToken)
{ {
$this->message = "Quoted String found between $prevToken and $postToken"; $this->message = "Quoted String found between $prevToken and $postToken";
+19 -2
View File
@@ -5,19 +5,36 @@ namespace Egulias\EmailValidator\Warning;
abstract class Warning abstract class Warning
{ {
const CODE = 0; const CODE = 0;
protected $message;
protected $rfcNumber;
/**
* @var string
*/
protected $message = '';
/**
* @var int
*/
protected $rfcNumber = 0;
/**
* @return string
*/
public function message() public function message()
{ {
return $this->message; return $this->message;
} }
/**
* @return int
*/
public function code() public function code()
{ {
return self::CODE; return self::CODE;
} }
/**
* @return int
*/
public function RFCNumber() public function RFCNumber()
{ {
return $this->rfcNumber; return $this->rfcNumber;
+7 -4
View File
@@ -1,19 +1,22 @@
# EmailValidator # EmailValidator
[![Build Status](https://travis-ci.org/egulias/EmailValidator.png?branch=master)](https://travis-ci.org/egulias/EmailValidator) [![Coverage Status](https://coveralls.io/repos/egulias/EmailValidator/badge.png?branch=master)](https://coveralls.io/r/egulias/EmailValidator?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/egulias/EmailValidator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6/small.png)](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6) [![Build Status](https://travis-ci.org/egulias/EmailValidator.svg?branch=master)](https://travis-ci.org/egulias/EmailValidator) [![Coverage Status](https://coveralls.io/repos/egulias/EmailValidator/badge.svg?branch=master)](https://coveralls.io/r/egulias/EmailValidator?branch=master) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/egulias/EmailValidator/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/egulias/EmailValidator/?branch=master) [![SensioLabsInsight](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6/small.png)](https://insight.sensiolabs.com/projects/22ba6692-9c02-42e5-a65d-1c5696bfffc6)
============================= =============================
With the help of [PHPStorm](https://www.jetbrains.com/phpstorm/) ## Suported RFCs ##
This library aims to support:
RFC 5321, 5322, 6530, 6531, 6532.
## Requirements ## ## Requirements ##
* [Composer](https://getcomposer.org) is required for installation * [Composer](https://getcomposer.org) is required for installation
* [Spoofchecking](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/SpoofCheckValidation.php) and [DNSCheckValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/DNSCheckValidation.php) validation requires that your PHP system have the [PHP Internationalization Libraries](https://php.net/manual/en/book.intl.php) (also known as PHP Intl) * [Spoofchecking](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/SpoofCheckValidation.php) and [DNSCheckValidation](https://github.com/egulias/EmailValidator/blob/master/EmailValidator/Validation/DNSCheckValidation.php) validation requires that your PHP system has the [PHP Internationalization Libraries](https://php.net/manual/en/book.intl.php) (also known as PHP Intl)
## Installation ## ## Installation ##
Run the command below to install via Composer Run the command below to install via Composer
```shell ```shell
composer require egulias/email-validator "~2.1" composer require egulias/email-validator
``` ```
## Getting Started ## ## Getting Started ##
+3 -2
View File
@@ -3,6 +3,7 @@
namespace Egulias\Tests\EmailValidator; namespace Egulias\Tests\EmailValidator;
use Egulias\EmailValidator\EmailValidator; use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\EmailValidation;
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd; use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
@@ -11,7 +12,7 @@ class EmailValidatorTest extends TestCase
public function testValidationIsUsed() public function testValidationIsUsed()
{ {
$validator = new EmailValidator(); $validator = new EmailValidator();
$validation = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock(); $validation = $this->getMockBuilder(EmailValidation::class)->getMock();
$validation->expects($this->once())->method("isValid")->willReturn(true); $validation->expects($this->once())->method("isValid")->willReturn(true);
$validation->expects($this->once())->method("getWarnings")->willReturn([]); $validation->expects($this->once())->method("getWarnings")->willReturn([]);
$validation->expects($this->once())->method("getError")->willReturn(null); $validation->expects($this->once())->method("getError")->willReturn(null);
@@ -22,7 +23,7 @@ class EmailValidatorTest extends TestCase
public function testMultipleValidation() public function testMultipleValidation()
{ {
$validator = new EmailValidator(); $validator = new EmailValidator();
$validation = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock(); $validation = $this->getMockBuilder(EmailValidation::class)->getMock();
$validation->expects($this->once())->method("isValid")->willReturn(true); $validation->expects($this->once())->method("isValid")->willReturn(true);
$validation->expects($this->once())->method("getWarnings")->willReturn([]); $validation->expects($this->once())->method("getWarnings")->willReturn([]);
$validation->expects($this->once())->method("getError")->willReturn(null); $validation->expects($this->once())->method("getError")->willReturn(null);
@@ -6,7 +6,6 @@ use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Validation\DNSCheckValidation; use Egulias\EmailValidator\Validation\DNSCheckValidation;
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd; use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
use Egulias\EmailValidator\Validation\NoRFCWarningsValidation; use Egulias\EmailValidator\Validation\NoRFCWarningsValidation;
use Egulias\EmailValidator\Validation\RFCValidation;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class IsEmailFunctionTests extends TestCase class IsEmailFunctionTests extends TestCase
@@ -2,23 +2,26 @@
namespace Egulias\Tests\EmailValidator\Validation; namespace Egulias\Tests\EmailValidator\Validation;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Exception\CommaInDomain; use Egulias\EmailValidator\Exception\CommaInDomain;
use Egulias\EmailValidator\Exception\NoDomainPart; use Egulias\EmailValidator\Exception\NoDomainPart;
use Egulias\EmailValidator\Validation\EmailValidation;
use Egulias\EmailValidator\Validation\MultipleErrors; use Egulias\EmailValidator\Validation\MultipleErrors;
use Egulias\EmailValidator\Validation\MultipleValidationWithAnd; use Egulias\EmailValidator\Validation\MultipleValidationWithAnd;
use Egulias\EmailValidator\Validation\RFCValidation;
use Egulias\EmailValidator\Warning\AddressLiteral; use Egulias\EmailValidator\Warning\AddressLiteral;
use Egulias\EmailValidator\Warning\DomainLiteral; use Egulias\EmailValidator\Warning\DomainLiteral;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class MultipleValidationWitAndTest extends TestCase class MultipleValidationWithAndTest extends TestCase
{ {
public function testUsesAndLogicalOperation() public function testUsesAndLogicalOperation()
{ {
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock(); $lexer = new EmailLexer();
$validationTrue = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock(); $validationTrue = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validationTrue->expects($this->any())->method("isValid")->willReturn(true); $validationTrue->expects($this->any())->method("isValid")->willReturn(true);
$validationTrue->expects($this->any())->method("getWarnings")->willReturn([]); $validationTrue->expects($this->any())->method("getWarnings")->willReturn([]);
$validationFalse = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock(); $validationFalse = $this->getMockBuilder(EmailValidation::class)->getMock();
$validationFalse->expects($this->any())->method("isValid")->willReturn(false); $validationFalse->expects($this->any())->method("isValid")->willReturn(false);
$validationFalse->expects($this->any())->method("getWarnings")->willReturn([]); $validationFalse->expects($this->any())->method("getWarnings")->willReturn([]);
$multipleValidation = new MultipleValidationWithAnd([$validationTrue, $validationFalse]); $multipleValidation = new MultipleValidationWithAnd([$validationTrue, $validationFalse]);
@@ -35,9 +38,9 @@ class MultipleValidationWitAndTest extends TestCase
public function testValidationIsValid() public function testValidationIsValid()
{ {
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock(); $lexer = new EmailLexer();
$validation = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock(); $validation = $this->getMockBuilder(EmailValidation::class)->getMock();
$validation->expects($this->any())->method("isValid")->willReturn(true); $validation->expects($this->any())->method("isValid")->willReturn(true);
$validation->expects($this->once())->method("getWarnings")->willReturn([]); $validation->expects($this->once())->method("getWarnings")->willReturn([]);
@@ -56,12 +59,12 @@ class MultipleValidationWitAndTest extends TestCase
]; ];
$expectedResult = array_merge($warnings1, $warnings2); $expectedResult = array_merge($warnings1, $warnings2);
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock(); $lexer = new EmailLexer();
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock(); $validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation1->expects($this->any())->method("isValid")->willReturn(true); $validation1->expects($this->any())->method("isValid")->willReturn(true);
$validation1->expects($this->once())->method("getWarnings")->willReturn($warnings1); $validation1->expects($this->once())->method("getWarnings")->willReturn($warnings1);
$validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock(); $validation2 = $this->getMockBuilder(EmailValidation::class)->getMock();
$validation2->expects($this->any())->method("isValid")->willReturn(false); $validation2->expects($this->any())->method("isValid")->willReturn(false);
$validation2->expects($this->once())->method("getWarnings")->willReturn($warnings2); $validation2->expects($this->once())->method("getWarnings")->willReturn($warnings2);
@@ -78,15 +81,15 @@ class MultipleValidationWitAndTest extends TestCase
$expectedResult = new MultipleErrors([$error1, $error2]); $expectedResult = new MultipleErrors([$error1, $error2]);
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock(); $lexer = new EmailLexer();
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock(); $validation1 = $this->getMockBuilder(EmailValidation::class)->getMock();
$validation1->expects($this->any())->method("isValid")->willReturn(true); $validation1->expects($this->once())->method("isValid")->willReturn(false);
$validation1->expects($this->once())->method("getWarnings")->willReturn([]); $validation1->expects($this->once())->method("getWarnings")->willReturn([]);
$validation1->expects($this->once())->method("getError")->willReturn($error1); $validation1->expects($this->once())->method("getError")->willReturn($error1);
$validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock(); $validation2 = $this->getMockBuilder(EmailValidation::class)->getMock();
$validation2->expects($this->any())->method("isValid")->willReturn(false); $validation2->expects($this->once())->method("isValid")->willReturn(false);
$validation2->expects($this->once())->method("getWarnings")->willReturn([]); $validation2->expects($this->once())->method("getWarnings")->willReturn([]);
$validation2->expects($this->once())->method("getError")->willReturn($error2); $validation2->expects($this->once())->method("getError")->willReturn($error2);
@@ -95,20 +98,44 @@ class MultipleValidationWitAndTest extends TestCase
$this->assertEquals($expectedResult, $multipleValidation->getError()); $this->assertEquals($expectedResult, $multipleValidation->getError());
} }
public function testStopsAfterFirstError()
{
$error1 = new CommaInDomain();
$error2 = new NoDomainPart();
$expectedResult = new MultipleErrors([$error1]);
$lexer = new EmailLexer();
$validation1 = $this->getMockBuilder(EmailValidation::class)->getMock();
$validation1->expects($this->any())->method("isValid")->willReturn(false);
$validation1->expects($this->once())->method("getWarnings")->willReturn([]);
$validation1->expects($this->once())->method("getError")->willReturn($error1);
$validation2 = $this->getMockBuilder(EmailValidation::class)->getMock();
$validation2->expects($this->any())->method("isValid")->willReturn(false);
$validation2->expects($this->never())->method("getWarnings")->willReturn([]);
$validation2->expects($this->never())->method("getError")->willReturn($error2);
$multipleValidation = new MultipleValidationWithAnd([$validation1, $validation2], MultipleValidationWithAnd::STOP_ON_ERROR);
$multipleValidation->isValid("example@example.com", $lexer);
$this->assertEquals($expectedResult, $multipleValidation->getError());
}
public function testBreakOutOfLoopWhenError() public function testBreakOutOfLoopWhenError()
{ {
$error = new CommaInDomain(); $error = new CommaInDomain();
$expectedResult = new MultipleErrors([$error]); $expectedResult = new MultipleErrors([$error]);
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock(); $lexer = new EmailLexer();
$validation1 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock(); $validation1 = $this->getMockBuilder(EmailValidation::class)->getMock();
$validation1->expects($this->any())->method("isValid")->willReturn(false); $validation1->expects($this->any())->method("isValid")->willReturn(false);
$validation1->expects($this->once())->method("getWarnings")->willReturn([]); $validation1->expects($this->once())->method("getWarnings")->willReturn([]);
$validation1->expects($this->once())->method("getError")->willReturn($error); $validation1->expects($this->once())->method("getError")->willReturn($error);
$validation2 = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock(); $validation2 = $this->getMockBuilder(EmailValidation::class)->getMock();
$validation2->expects($this->never())->method("isValid"); $validation2->expects($this->never())->method("isValid");
$validation2->expects($this->never())->method("getWarnings"); $validation2->expects($this->never())->method("getWarnings");
$validation2->expects($this->never())->method("getError"); $validation2->expects($this->never())->method("getError");
@@ -117,4 +144,16 @@ class MultipleValidationWitAndTest extends TestCase
$multipleValidation->isValid("example@example.com", $lexer); $multipleValidation->isValid("example@example.com", $lexer);
$this->assertEquals($expectedResult, $multipleValidation->getError()); $this->assertEquals($expectedResult, $multipleValidation->getError());
} }
public function testBreakoutOnInvalidEmail()
{
$lexer = new EmailLexer();
$validationNotCalled = $this->getMockBuilder(EmailValidation::class)->getMock();
$validationNotCalled->expects($this->never())->method("isValid");
$validationNotCalled->expects($this->never())->method("getWarnings");
$validationNotCalled->expects($this->never())->method("getError");
$multipleValidation = new MultipleValidationWithAnd([new RFCValidation(), $validationNotCalled], MultipleValidationWithAnd::STOP_ON_ERROR);
$this->assertFalse($multipleValidation->isValid("invalid-email", $lexer));
}
} }
@@ -166,6 +166,7 @@ class RFCValidationTest extends TestCase
['test@email>'], ['test@email>'],
['test@email<'], ['test@email<'],
['test@email{'], ['test@email{'],
['test@ '],
]; ];
} }
@@ -264,6 +265,10 @@ class RFCValidationTest extends TestCase
[LocalTooLong::CODE,], [LocalTooLong::CODE,],
'too_long_localpart_too_long_localpart_too_long_localpart_too_long_localpart@invalid.example.com' 'too_long_localpart_too_long_localpart_too_long_localpart_too_long_localpart@invalid.example.com'
], ],
[
[LocalTooLong::CODE],
'too_long_localpart_too_long_localpart_123_too_long_localpart_too_long_localpart@example.com'
],
[ [
[LabelTooLong::CODE,], [LabelTooLong::CODE,],
'example@toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpart.co.uk' 'example@toolonglocalparttoolonglocalparttoolonglocalparttoolonglocalpart.co.uk'
+9 -15
View File
@@ -2,7 +2,6 @@
"name": "egulias/email-validator", "name": "egulias/email-validator",
"description": "A library for validating emails against several RFCs", "description": "A library for validating emails against several RFCs",
"homepage": "https://github.com/egulias/EmailValidator", "homepage": "https://github.com/egulias/EmailValidator",
"type": "Library",
"keywords": ["email", "validation", "validator", "emailvalidation", "emailvalidator"], "keywords": ["email", "validation", "validator", "emailvalidation", "emailvalidator"],
"license": "MIT", "license": "MIT",
"authors": [ "authors": [
@@ -10,23 +9,18 @@
], ],
"extra": { "extra": {
"branch-alias": { "branch-alias": {
"dev-master": "2.0.x-dev" "dev-master": "2.1.x-dev"
} }
}, },
"repositories": [ "require": {
{ "php": ">=5.5",
"type": "git", "doctrine/lexer": "^1.0.1",
"url": "https://github.com/dominicsayers/isemail" "symfony/polyfill-intl-idn": "^1.10"
}
],
"require": {
"php": ">= 5.5",
"doctrine/lexer": "^1.0.1"
}, },
"require-dev" : { "require-dev": {
"satooshi/php-coveralls": "^1.0.1", "satooshi/php-coveralls": "^1.0.1",
"phpunit/phpunit": "^4.8.35||^5.7||^6.0", "phpunit/phpunit": "^4.8.36|^7.5.15",
"dominicsayers/isemail": "dev-master" "dominicsayers/isemail": "^3.0.7"
}, },
"suggest": { "suggest": {
"ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation" "ext-intl": "PHP Internationalization Libraries are required to use the SpoofChecking validation"
@@ -38,7 +32,7 @@
}, },
"autoload-dev": { "autoload-dev": {
"psr-4": { "psr-4": {
"Egulias\\Tests\\": "test" "Egulias\\Tests\\": "Tests"
} }
} }
} }
+3 -4
View File
@@ -8,7 +8,6 @@
convertWarningsToExceptions="true" convertWarningsToExceptions="true"
processIsolation="false" processIsolation="false"
stopOnFailure="false" stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php" bootstrap="vendor/autoload.php"
> >
<testsuites> <testsuites>
@@ -19,8 +18,8 @@
</testsuites> </testsuites>
<filter> <filter>
<blacklist> <whitelist>
<directory>./vendor</directory> <directory>./EmailValidator/</directory>
</blacklist> </whitelist>
</filter> </filter>
</phpunit> </phpunit>
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="3.8.3@389af1bfc739bfdff3f9e3dc7bd6499aee51a831">
<file src="EmailValidator/EmailLexer.php">
<DocblockTypeContradiction occurrences="1">
<code>self::$nullToken</code>
</DocblockTypeContradiction>
</file>
<file src="EmailValidator/Parser/Parser.php">
<MissingReturnType occurrences="1">
<code>parse</code>
</MissingReturnType>
</file>
<file src="EmailValidator/Validation/SpoofCheckValidation.php">
<UndefinedClass occurrences="2">
<code>Spoofchecker</code>
<code>Spoofchecker</code>
</UndefinedClass>
</file>
</files>
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<psalm
requireVoidReturnType="false"
totallyTyped="false"
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"
>
<projectFiles>
<directory name="EmailValidator" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
</issueHandlers>
</psalm>