mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-09-04 14:38:21 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 19674b35a0 | |||
| 92fd7ea285 | |||
| 0d6268fde5 | |||
| e7dacfc97f | |||
| 758a77525b | |||
| 5642614492 | |||
| b8bb147f46 |
@@ -1,2 +1,4 @@
|
|||||||
|
.idea
|
||||||
|
composer.lock
|
||||||
report/
|
report/
|
||||||
vendor/
|
vendor/
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
filter:
|
||||||
|
excluded_paths:
|
||||||
|
- 'documentation/*'
|
||||||
|
- 'tests/*'
|
||||||
|
|
||||||
|
tools:
|
||||||
|
external_code_coverage:
|
||||||
|
runs: 1
|
||||||
+24
-22
@@ -1,35 +1,37 @@
|
|||||||
sudo: false
|
|
||||||
|
|
||||||
language: php
|
language: php
|
||||||
|
|
||||||
php:
|
|
||||||
- 5.3
|
|
||||||
- 5.4
|
|
||||||
- 5.5
|
|
||||||
- 5.6
|
|
||||||
- 7.0
|
|
||||||
- hhvm
|
|
||||||
|
|
||||||
env:
|
|
||||||
global:
|
|
||||||
- deps=high
|
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
|
||||||
include:
|
include:
|
||||||
- php: 5.3
|
- php: 5.3
|
||||||
|
dist: precise
|
||||||
env: deps=low
|
env: deps=low
|
||||||
|
- php: 5.3
|
||||||
|
dist: precise
|
||||||
- php: 5.4
|
- php: 5.4
|
||||||
env: deps=no
|
dist: trusty
|
||||||
- php: 5.5
|
- php: 5.5
|
||||||
env: deps=no
|
dist: trusty
|
||||||
|
- php: 5.6
|
||||||
|
dist: xenial
|
||||||
|
- php: 7.0
|
||||||
|
dist: xenial
|
||||||
|
- php: 7.1
|
||||||
|
dist: bionic
|
||||||
|
- php: 7.2
|
||||||
|
dist: bionic
|
||||||
|
- php: 7.3
|
||||||
|
dist: bionic
|
||||||
|
- php: 7.4
|
||||||
|
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 [ "$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
|
||||||
- phpunit --coverage-clover build/logs/clover.xml
|
|
||||||
|
|
||||||
|
after_script:
|
||||||
|
- php vendor/bin/coveralls
|
||||||
|
|||||||
+8
-10
@@ -2,27 +2,25 @@
|
|||||||
"name": "egulias/email-validator",
|
"name": "egulias/email-validator",
|
||||||
"description": "A library for validating emails",
|
"description": "A library for validating emails",
|
||||||
"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": [
|
||||||
{"name": "Eduardo Gulias Davis"}
|
{"name": "Eduardo Gulias Davis"}
|
||||||
],
|
],
|
||||||
"extra": {
|
"require": {
|
||||||
"branch-alias": {
|
"php": ">=5.3.3",
|
||||||
"dev-master": "2.0.x-dev"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"require": {
|
|
||||||
"php": ">= 5.3.3",
|
|
||||||
"doctrine/lexer": "^1.0.1"
|
"doctrine/lexer": "^1.0.1"
|
||||||
},
|
},
|
||||||
"require-dev" : {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "^4.8.24"
|
"satooshi/php-coveralls": "^1.0.1",
|
||||||
|
"phpunit/phpunit": "^4.8.36|^7.5.15"
|
||||||
},
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-0": {
|
"psr-0": {
|
||||||
"Egulias\\": "src/"
|
"Egulias\\": "src/"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "phpunit"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
-1078
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,6 @@
|
|||||||
convertWarningsToExceptions="true"
|
convertWarningsToExceptions="true"
|
||||||
processIsolation="false"
|
processIsolation="false"
|
||||||
stopOnFailure="false"
|
stopOnFailure="false"
|
||||||
syntaxCheck="false"
|
|
||||||
bootstrap="tests/bootstrap.php"
|
bootstrap="tests/bootstrap.php"
|
||||||
>
|
>
|
||||||
<testsuites>
|
<testsuites>
|
||||||
|
|||||||
@@ -77,10 +77,22 @@ class EmailLexer extends AbstractLexer
|
|||||||
|
|
||||||
protected $previous;
|
protected $previous;
|
||||||
|
|
||||||
|
private static $nullToken = array(
|
||||||
|
'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()
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ namespace Egulias\EmailValidator;
|
|||||||
*
|
*
|
||||||
* @author Eduardo Gulias Davis <me@egulias.com>
|
* @author Eduardo Gulias Davis <me@egulias.com>
|
||||||
*/
|
*/
|
||||||
class EmailValidator
|
class EmailValidator implements EmailValidatorInterface
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Critical validation errors used to indicate that
|
* Critical validation errors used to indicate that
|
||||||
@@ -113,26 +113,7 @@ class EmailValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates an email address against the following standards:
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* RFC-5321: Simple Mail Transfer Protocol
|
|
||||||
* RFC-5322: Internet Message Format
|
|
||||||
* RFC-6530: Overview and Framework for Internationalized Email
|
|
||||||
* RFC-6531: SMTP Extension for Internationalized Email
|
|
||||||
* RFC-6532: Internationalized Email Headers
|
|
||||||
* RFC-1123 section 2.1: Requirements for Internet Hosts -- Application and Support
|
|
||||||
* RFC-4291 section 2.2: IP Version 6 Addressing Architecture
|
|
||||||
*
|
|
||||||
* @param string $email The email address to validate.
|
|
||||||
* @param bool $checkDNS Whether or not the email address's hostname should
|
|
||||||
* be confirmed with a DNS lookup. This only comes
|
|
||||||
* into play if strict mode is also enabled.
|
|
||||||
* @param bool $strict If this is true, and any informational warnings
|
|
||||||
* were raised during validation, the email address
|
|
||||||
* will be considered invalid. Additionally, if
|
|
||||||
* $checkDNS is true and the DNS lookup failed,
|
|
||||||
* the email address will be considered invalid.
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function isValid($email, $checkDNS = false, $strict = false)
|
public function isValid($email, $checkDNS = false, $strict = false)
|
||||||
{
|
{
|
||||||
@@ -152,11 +133,11 @@ class EmailValidator
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ($strict ? (!$this->hasWarnings() && !$dnsProblemExists) : true);
|
return !($dnsProblemExists || $strict && $this->hasWarnings());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return boolean
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function hasWarnings()
|
public function hasWarnings()
|
||||||
{
|
{
|
||||||
@@ -164,7 +145,7 @@ class EmailValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getWarnings()
|
public function getWarnings()
|
||||||
{
|
{
|
||||||
@@ -172,7 +153,7 @@ class EmailValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return string
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getError()
|
public function getError()
|
||||||
{
|
{
|
||||||
@@ -180,9 +161,7 @@ class EmailValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $threshold
|
* {@inheritdoc}
|
||||||
*
|
|
||||||
* @return EmailValidator
|
|
||||||
*/
|
*/
|
||||||
public function setThreshold($threshold)
|
public function setThreshold($threshold)
|
||||||
{
|
{
|
||||||
@@ -192,7 +171,7 @@ class EmailValidator
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function getThreshold()
|
public function getThreshold()
|
||||||
{
|
{
|
||||||
@@ -205,7 +184,10 @@ class EmailValidator
|
|||||||
*/
|
*/
|
||||||
protected function checkDNS()
|
protected function checkDNS()
|
||||||
{
|
{
|
||||||
$mxRecordExists = checkdnsrr(trim($this->parser->getParsedDomainPart()), 'MX');
|
$host = $this->parser->getParsedDomainPart();
|
||||||
|
$host = rtrim($host, '.') . '.';
|
||||||
|
|
||||||
|
$mxRecordExists = checkdnsrr($host, 'MX');
|
||||||
|
|
||||||
if (!$mxRecordExists) {
|
if (!$mxRecordExists) {
|
||||||
$this->warnings[] = self::DNSWARN_NO_RECORD;
|
$this->warnings[] = self::DNSWARN_NO_RECORD;
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Egulias\EmailValidator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EmailValidatorInterface
|
||||||
|
*
|
||||||
|
* @author Chris McCafferty <cilefen@gmail.com>
|
||||||
|
*/
|
||||||
|
interface EmailValidatorInterface
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Validates an email address against the following standards:
|
||||||
|
*
|
||||||
|
* RFC-5321: Simple Mail Transfer Protocol
|
||||||
|
* RFC-5322: Internet Message Format
|
||||||
|
* RFC-6530: Overview and Framework for Internationalized Email
|
||||||
|
* RFC-6531: SMTP Extension for Internationalized Email
|
||||||
|
* RFC-6532: Internationalized Email Headers
|
||||||
|
* RFC-1123 section 2.1: Requirements for Internet Hosts -- Application and Support
|
||||||
|
* RFC-4291 section 2.2: IP Version 6 Addressing Architecture
|
||||||
|
*
|
||||||
|
* @param string $email The email address to validate.
|
||||||
|
* @param bool $checkDNS Whether or not the email address's hostname should
|
||||||
|
* be confirmed with a DNS lookup. This only comes
|
||||||
|
* into play if strict mode is also enabled.
|
||||||
|
* @param bool $strict If this is true, and any informational warnings
|
||||||
|
* were raised during validation, the email address
|
||||||
|
* will be considered invalid. Additionally, if
|
||||||
|
* $checkDNS is true and the DNS lookup failed,
|
||||||
|
* the email address will be considered invalid.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isValid($email, $checkDNS = false, $strict = false);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function hasWarnings();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getWarnings();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getError();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $threshold The acceptable number of deprecation warnings.
|
||||||
|
*
|
||||||
|
* @return EmailValidator
|
||||||
|
*/
|
||||||
|
public function setThreshold($threshold);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getThreshold();
|
||||||
|
}
|
||||||
@@ -141,7 +141,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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,9 +13,12 @@ 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) {
|
||||||
throw new \InvalidArgumentException('ERR_DOT_START');
|
$previous = $this->lexer->getPrevious();
|
||||||
|
if (null === $previous['type']) {
|
||||||
|
throw new \InvalidArgumentException('ERR_DOT_START');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$closingQuote = $this->checkDQUOTE($closingQuote);
|
$closingQuote = $this->checkDQUOTE($closingQuote);
|
||||||
@@ -78,7 +81,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[] = EmailValidator::CFWS_FWS;
|
$this->warnings[] = EmailValidator::CFWS_FWS;
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
namespace Egulias\EmailValidator\Tests;
|
namespace Egulias\EmailValidator\Tests;
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailLexer;
|
use Egulias\EmailValidator\EmailLexer;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class EmailLexerTests extends \PHPUnit_Framework_TestCase
|
class EmailLexerTests extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
public function testLexerExtendsLib()
|
public function testLexerExtendsLib()
|
||||||
|
|||||||
@@ -3,8 +3,9 @@
|
|||||||
namespace Egulias\Tests\EmailValidator;
|
namespace Egulias\Tests\EmailValidator;
|
||||||
|
|
||||||
use Egulias\EmailValidator\EmailValidator;
|
use Egulias\EmailValidator\EmailValidator;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
class EmailValidatorTest extends TestCase
|
||||||
{
|
{
|
||||||
protected $validator;
|
protected $validator;
|
||||||
|
|
||||||
@@ -180,7 +181,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testValidEmailsWithWarningsCheck($warnings, $email)
|
public function testValidEmailsWithWarningsCheck($warnings, $email)
|
||||||
{
|
{
|
||||||
$this->assertTrue($this->validator->isValid($email, true));
|
$this->assertFalse($this->validator->isValid($email, true));
|
||||||
|
|
||||||
$this->assertEquals($warnings, $this->validator->getWarnings());
|
$this->assertEquals($warnings, $this->validator->getWarnings());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user