Compare commits

...

5 Commits

Author SHA1 Message Date
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
14 changed files with 83 additions and 47 deletions
+4 -4
View File
@@ -9,7 +9,7 @@ php:
- 7.1 - 7.1
- 7.2 - 7.2
- 7.3 - 7.3
- hhvm - 7.4snapshot
env: env:
global: global:
@@ -29,8 +29,8 @@ install:
- if [ "$deps" = "high" ]; then composer update; fi - if [ "$deps" = "high" ]; then composer update; fi
script: script:
- mkdir -p build/logs - mkdir -p build/logs
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml - vendor/bin/phpunit --coverage-clover build/logs/clover.xml
after_script: after_script:
- php vendor/bin/coveralls - php vendor/bin/coveralls
+18 -4
View File
@@ -77,10 +77,22 @@ class EmailLexer extends AbstractLexer
protected $previous; protected $previous;
private static $nullToken = [
'value' => '',
'type' => null,
'position' => 0,
];
public function __construct()
{
$this->previous = $this->token = self::$nullToken;
}
public function reset() public function reset()
{ {
$this->hasInvalidTokens = false; $this->hasInvalidTokens = false;
parent::reset(); parent::reset();
$this->previous = $this->token = self::$nullToken;
} }
public function hasInvalidTokens() public function hasInvalidTokens()
@@ -89,7 +101,7 @@ class EmailLexer extends AbstractLexer
} }
/** /**
* @param $type * @param string $type
* @throws \UnexpectedValueException * @throws \UnexpectedValueException
* @return boolean * @return boolean
*/ */
@@ -122,8 +134,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;
} }
/** /**
@@ -189,7 +203,7 @@ class EmailLexer extends AbstractLexer
} }
/** /**
* @param $value * @param string $value
* @return bool * @return bool
*/ */
protected function isNullType($value) protected function isNullType($value)
@@ -202,7 +216,7 @@ class EmailLexer extends AbstractLexer
} }
/** /**
* @param $value * @param string $value
* @return bool * @return bool
*/ */
protected function isUTF8Invalid($value) protected function isUTF8Invalid($value)
+1 -1
View File
@@ -33,7 +33,7 @@ class EmailParser
} }
/** /**
* @param $str * @param string $str
* @return array * @return array
*/ */
public function parse($str) public function parse($str)
+1 -1
View File
@@ -28,7 +28,7 @@ class EmailValidator
} }
/** /**
* @param $email * @param string $email
* @param EmailValidation $emailValidation * @param EmailValidation $emailValidation
* @return bool * @return bool
*/ */
+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;
+34 -16
View File
@@ -41,21 +41,7 @@ class DomainPart extends Parser
{ {
$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,6 +63,38 @@ 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();
}
}
public function getDomainPart() public function getDomainPart()
{ {
return $this->domainPart; return $this->domainPart;
@@ -166,7 +184,7 @@ 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;
} }
+3 -3
View File
@@ -21,8 +21,8 @@ class LocalPart extends Parser
$closingQuote = false; $closingQuote = false;
$openedParenthesis = 0; $openedParenthesis = 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();
} }
@@ -86,7 +86,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();
+2 -2
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;
@@ -50,7 +50,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] =
+2 -2
View File
@@ -1,5 +1,5 @@
# 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)
============================= =============================
## Suported RFCs ## ## Suported RFCs ##
This library aims to support: This library aims to support:
@@ -16,7 +16,7 @@ RFC 5321, 5322, 6530, 6531, 6532.
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 ##
@@ -2,6 +2,7 @@
namespace Egulias\Tests\EmailValidator\Validation; namespace Egulias\Tests\EmailValidator\Validation;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\EmailValidator; use Egulias\EmailValidator\EmailValidator;
use Egulias\EmailValidator\Exception\CommaInDomain; use Egulias\EmailValidator\Exception\CommaInDomain;
use Egulias\EmailValidator\Exception\NoDomainPart; use Egulias\EmailValidator\Exception\NoDomainPart;
@@ -17,7 +18,7 @@ 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([]);
@@ -38,7 +39,7 @@ class MultipleValidationWithAndTest 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("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation->expects($this->any())->method("isValid")->willReturn(true); $validation->expects($this->any())->method("isValid")->willReturn(true);
@@ -59,7 +60,7 @@ class MultipleValidationWithAndTest 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);
@@ -81,7 +82,7 @@ class MultipleValidationWithAndTest 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("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation1->expects($this->once())->method("isValid")->willReturn(false); $validation1->expects($this->once())->method("isValid")->willReturn(false);
@@ -105,7 +106,7 @@ class MultipleValidationWithAndTest extends TestCase
$expectedResult = new MultipleErrors([$error1]); $expectedResult = new MultipleErrors([$error1]);
$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(false); $validation1->expects($this->any())->method("isValid")->willReturn(false);
@@ -128,7 +129,7 @@ class MultipleValidationWithAndTest extends TestCase
$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("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validation1->expects($this->any())->method("isValid")->willReturn(false); $validation1->expects($this->any())->method("isValid")->willReturn(false);
@@ -147,7 +148,7 @@ class MultipleValidationWithAndTest extends TestCase
public function testBreakoutOnInvalidEmail() public function testBreakoutOnInvalidEmail()
{ {
$lexer = $this->getMockBuilder("Egulias\\EmailValidator\\EmailLexer")->getMock(); $lexer = new EmailLexer();
$validationNotCalled = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock(); $validationNotCalled = $this->getMockBuilder("Egulias\\EmailValidator\\Validation\\EmailValidation")->getMock();
$validationNotCalled->expects($this->never())->method("isValid"); $validationNotCalled->expects($this->never())->method("isValid");
@@ -166,6 +166,7 @@ class RFCValidationTest extends TestCase
['test@email>'], ['test@email>'],
['test@email<'], ['test@email<'],
['test@email{'], ['test@email{'],
['test@ '],
]; ];
} }
+1
View File
@@ -26,6 +26,7 @@
"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.35||^5.7||^6.0",
"symfony/phpunit-bridge": "^4.4@dev",
"dominicsayers/isemail": "dev-master" "dominicsayers/isemail": "dev-master"
}, },
"suggest": { "suggest": {
+7 -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,12 @@
</testsuites> </testsuites>
<filter> <filter>
<blacklist> <whitelist>
<directory>./vendor</directory> <directory>./EmailValidator/</directory>
</blacklist> </whitelist>
</filter> </filter>
<listeners>
<listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener" />
</listeners>
</phpunit> </phpunit>