mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-08-30 03:59:20 +00:00
removes trailing spaces (#136)
This commit is contained in:
committed by
Eduardo Gulias Davis
parent
181a2fc726
commit
c0c888ae10
@@ -11,7 +11,7 @@ class EmailValidator
|
||||
* @var EmailLexer
|
||||
*/
|
||||
private $lexer;
|
||||
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@@ -21,7 +21,7 @@ class EmailValidator
|
||||
* @var InvalidEmail
|
||||
*/
|
||||
protected $error;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->lexer = new EmailLexer();
|
||||
@@ -37,7 +37,7 @@ class EmailValidator
|
||||
$isValid = $emailValidation->isValid($email, $this->lexer);
|
||||
$this->warnings = $emailValidation->getWarnings();
|
||||
$this->error = $emailValidation->getError();
|
||||
|
||||
|
||||
return $isValid;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ abstract class InvalidEmail extends \InvalidArgumentException
|
||||
{
|
||||
const REASON = "Invalid email";
|
||||
const CODE = 0;
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(static::REASON, static::CODE);
|
||||
|
||||
@@ -170,7 +170,7 @@ class DomainPart extends Parser
|
||||
|
||||
return $domain;
|
||||
}
|
||||
|
||||
|
||||
private function checkNotAllowedChars($token)
|
||||
{
|
||||
$notAllowed = [EmailLexer::S_BACKSLASH => true, EmailLexer::S_SLASH=> true];
|
||||
|
||||
@@ -46,7 +46,7 @@ class DNSCheckValidation implements EmailValidation
|
||||
{
|
||||
$Aresult = true;
|
||||
$MXresult = checkdnsrr($host, 'MX');
|
||||
|
||||
|
||||
if (!$MXresult) {
|
||||
$this->warnings[NoDNSMXRecord::CODE] = new NoDNSMXRecord();
|
||||
$Aresult = checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA');
|
||||
|
||||
@@ -12,13 +12,13 @@ class MultipleErrors extends InvalidEmail
|
||||
* @var array
|
||||
*/
|
||||
private $errors = [];
|
||||
|
||||
|
||||
public function __construct(array $errors)
|
||||
{
|
||||
$this->errors = $errors;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
public function getErrors()
|
||||
{
|
||||
return $this->errors;
|
||||
|
||||
@@ -48,7 +48,7 @@ class MultipleValidationWithAnd implements EmailValidation
|
||||
if (count($validations) == 0) {
|
||||
throw new EmptyValidationList();
|
||||
}
|
||||
|
||||
|
||||
$this->validations = $validations;
|
||||
$this->mode = $mode;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ class RFCValidation implements EmailValidation
|
||||
* @var InvalidEmail
|
||||
*/
|
||||
private $error;
|
||||
|
||||
|
||||
public function isValid($email, EmailLexer $emailLexer)
|
||||
{
|
||||
$this->parser = new EmailParser($emailLexer);
|
||||
@@ -32,7 +32,7 @@ class RFCValidation implements EmailValidation
|
||||
$this->error = $invalid;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$this->warnings = $this->parser->getWarnings();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,11 +18,11 @@ class SpoofCheckValidation implements EmailValidation
|
||||
{
|
||||
$checker = new Spoofchecker();
|
||||
$checker->setChecks(Spoofchecker::SINGLE_SCRIPT);
|
||||
|
||||
|
||||
if ($checker->isSuspicious($email)) {
|
||||
$this->error = new SpoofEmail();
|
||||
}
|
||||
|
||||
|
||||
return $this->error === null;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ abstract class Warning
|
||||
{
|
||||
return $this->rfcNumber;
|
||||
}
|
||||
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->message() . " rfc: " . $this->rfcNumber . "interal code: " . static::CODE;
|
||||
|
||||
@@ -17,7 +17,7 @@ class EmailValidatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertTrue($validator->isValid("example@example.com", $validation));
|
||||
}
|
||||
|
||||
|
||||
public function testMultipleValidation()
|
||||
{
|
||||
$validator = new EmailValidator();
|
||||
|
||||
@@ -34,13 +34,13 @@ class DNSCheckValidationTest extends \PHPUnit_Framework_TestCase
|
||||
$validation = new DNSCheckValidation();
|
||||
$this->assertTrue($validation->isValid($validEmail, new EmailLexer()));
|
||||
}
|
||||
|
||||
|
||||
public function testInvalidDNS()
|
||||
{
|
||||
$validation = new DNSCheckValidation();
|
||||
$this->assertFalse($validation->isValid("example@invalid.example.com", new EmailLexer()));
|
||||
}
|
||||
|
||||
|
||||
public function testDNSWarnings()
|
||||
{
|
||||
$validation = new DNSCheckValidation();
|
||||
@@ -48,7 +48,7 @@ class DNSCheckValidationTest extends \PHPUnit_Framework_TestCase
|
||||
$validation->isValid("example@invalid.example.com", new EmailLexer());
|
||||
$this->assertEquals($expectedWarnings, $validation->getWarnings());
|
||||
}
|
||||
|
||||
|
||||
public function testNoDNSError()
|
||||
{
|
||||
$validation = new DNSCheckValidation();
|
||||
|
||||
@@ -28,8 +28,8 @@ class IsEmailFunctionTests extends \PHPUnit_Framework_TestCase
|
||||
public function isEmailTestSuite()
|
||||
{
|
||||
$testSuite = dirname(__FILE__) . '/../../resources/is_email_tests.xml';
|
||||
$document = new \DOMDocument();
|
||||
$document->load($testSuite);
|
||||
$document = new \DOMDocument();
|
||||
$document->load($testSuite);
|
||||
$elements = $document->getElementsByTagName('test');
|
||||
$tests = [];
|
||||
|
||||
@@ -40,5 +40,4 @@ class IsEmailFunctionTests extends \PHPUnit_Framework_TestCase
|
||||
|
||||
return $tests;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -54,16 +54,16 @@ class MultipleValidationWitAndTest extends \PHPUnit_Framework_TestCase
|
||||
DomainLiteral::CODE => new DomainLiteral()
|
||||
];
|
||||
$expectedResult = array_merge($warnings1, $warnings2);
|
||||
|
||||
|
||||
$lexer = $this->getMock("Egulias\\EmailValidator\\EmailLexer");
|
||||
$validation1 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
|
||||
$validation1->expects($this->any())->method("isValid")->willReturn(true);
|
||||
$validation1->expects($this->once())->method("getWarnings")->willReturn($warnings1);
|
||||
|
||||
|
||||
$validation2 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
|
||||
$validation2->expects($this->any())->method("isValid")->willReturn(false);
|
||||
$validation2->expects($this->once())->method("getWarnings")->willReturn($warnings2);
|
||||
|
||||
|
||||
$multipleValidation = new MultipleValidationWithAnd([$validation1, $validation2]);
|
||||
$multipleValidation->isValid("example@example.com", $lexer);
|
||||
$this->assertEquals($expectedResult, $multipleValidation->getWarnings());
|
||||
@@ -73,11 +73,11 @@ class MultipleValidationWitAndTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$error1 = new CommaInDomain();
|
||||
$error2 = new NoDomainPart();
|
||||
|
||||
|
||||
$expectedResult = new MultipleErrors([$error1, $error2]);
|
||||
|
||||
$lexer = $this->getMock("Egulias\\EmailValidator\\EmailLexer");
|
||||
|
||||
|
||||
$validation1 = $this->getMock("Egulias\\EmailValidator\\Validation\\EmailValidation");
|
||||
$validation1->expects($this->any())->method("isValid")->willReturn(true);
|
||||
$validation1->expects($this->once())->method("getWarnings")->willReturn([]);
|
||||
|
||||
@@ -12,7 +12,7 @@ class NoRFCWarningsValidationTest extends \PHPUnit_Framework_TestCase
|
||||
public function testInvalidEmailIsInvalid()
|
||||
{
|
||||
$validation = new NoRFCWarningsValidation();
|
||||
|
||||
|
||||
$this->assertFalse($validation->isValid('non-email-string', new EmailLexer()));
|
||||
$this->assertInstanceOf(NoDomainPart::class, $validation->getError());
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class NoRFCWarningsValidationTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($validation->isValid(str_repeat('x', 254).'@example.com', new EmailLexer())); // too long email
|
||||
$this->assertInstanceOf(RFCWarnings::class, $validation->getError());
|
||||
}
|
||||
|
||||
|
||||
public function testEmailWithoutWarningsIsValid()
|
||||
{
|
||||
$validation = new NoRFCWarningsValidation();
|
||||
|
||||
@@ -47,7 +47,7 @@ class RFCValidationTest extends \PHPUnit_Framework_TestCase
|
||||
* @var EmailLexer
|
||||
*/
|
||||
protected $lexer;
|
||||
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->validator = new RFCValidation();
|
||||
@@ -106,7 +106,7 @@ class RFCValidationTest extends \PHPUnit_Framework_TestCase
|
||||
$email = "\x80\x81\x82@\x83\x84\x85.\x86\x87\x88";
|
||||
$this->assertFalse($this->validator->isValid($email, $this->lexer));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @dataProvider getInvalidEmails
|
||||
*/
|
||||
@@ -228,7 +228,7 @@ class RFCValidationTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertTrue(isset($expectedWarnings[$warning->code()]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getInvalidEmailsWithWarnings()
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -14,17 +14,17 @@ class SpoofCheckValidationTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->markTestSkipped("Skipped for Travis CI since it is failing on this test for unknown reasons.");
|
||||
$validation = new SpoofCheckValidation();
|
||||
|
||||
|
||||
$this->assertTrue($validation->isValid($email, new EmailLexer()));
|
||||
}
|
||||
|
||||
|
||||
public function testEmailWithSpoofsIsInvalid()
|
||||
{
|
||||
$validation = new SpoofCheckValidation();
|
||||
|
||||
$this->assertFalse($validation->isValid("Кириллица"."latin漢字"."ひらがな"."カタカナ", new EmailLexer()));
|
||||
}
|
||||
|
||||
|
||||
public function validUTF8EmailsProvider()
|
||||
{
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user