Skip to content

Commit

Permalink
#32 - Fixed usage of DNS check and strict parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
egulias committed Nov 2, 2014
1 parent 49494c3 commit 749b423
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/Egulias/EmailValidator/EmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function isValid($email, $checkDNS = false, $strict = false)
return false;
}

$dns = true;
$dns = false;
if ($checkDNS) {
$dns = $this->checkDNS();
}
Expand All @@ -95,7 +95,12 @@ public function isValid($email, $checkDNS = false, $strict = false)
return false;
}

return ($strict) ? (!$this->hasWarnings() && $dns) : true;
return ($strict) ? $this->checkStrict($dns) : true;
}

private function checkStrict($dns)
{
return !($this->hasWarnings() && !$dns);
}

/**
Expand Down Expand Up @@ -144,16 +149,9 @@ public function getThreshold()

protected function checkDNS()
{
$checked = false;
if (!function_exists('dns_get_record') && (
in_array(self::DNSWARN_NO_RECORD, $this->warnings) &&
in_array(self::DNSWARN_NO_MX_RECORD, $this->warnings)
)) {
return $checked;
}
$checked = true;

$result = checkdnsrr(trim($this->parser->getParsedDomainPart()), 'MX');
$checked = true;

if (!$result) {
$this->warnings[] = self::DNSWARN_NO_RECORD;
Expand Down
10 changes: 10 additions & 0 deletions tests/egulias/Tests/EmailValidator/EmailValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,14 @@ public function getInvalidEmailsWithWarnings()
),
);
}

public function testInvalidEmailsWithDNSAndStrict()
{
$this->assertFalse($this->validator->isValid('test@test', true, true));
}

public function testInvalidEmailsWithStrict()
{
$this->assertFalse($this->validator->isValid('"test"@test', false, true));
}
}

0 comments on commit 749b423

Please sign in to comment.