[BUG] Initialize variable to prevent error when not set
And do refactoring
MODIFY
src/EmailAddress.php
src/EmailAddress.php
@@ -511,6 +511,7 @@ class EmailAddress extends AbstractValidator
}
// Match hostname part
+ $hostname = false;
if ($this->options['useDomainCheck']) {
$hostname = $this->validateHostnamePart();
}
@@ -518,13 +519,7 @@ class EmailAddress extends AbstractValidator
$local = $this->validateLocalPart();
// If both parts valid, return true
- if ($local && $length) {
- if (($this->options['useDomainCheck'] && $hostname) || ! $this->options['useDomainCheck']) {
- return true;
- }
- }
-
- return false;
+ return ($local && $length) && (! $this->options['useDomainCheck'] || $hostname);
}
/**

MODIFY
test/EmailAddressTest.php
test/EmailAddressTest.php
@@ -685,6 +685,11 @@ class EmailAddressTest extends TestCase
$this->assertInstanceOf(Hostname::class, $hostname);
}
+ public function testIsMxSupported()
+ {
+ $validator = new EmailAddress(['useMxCheck' => true, 'allow' => Hostname::ALLOW_ALL]);
+ $this->assertInternalType('bool', $validator->isMxSupported());
+ }
/**
* Test getMXRecord
*/
@@ -692,7 +697,6 @@ class EmailAddressTest extends TestCase
{
$this->skipIfOnlineTestsDisabled();
- $validator = new EmailAddress(['useMxCheck' => true, 'allow' => Hostname::ALLOW_ALL]);
$validator = new EmailAddress(['useMxCheck' => true, 'allow' => Hostname::ALLOW_ALL]);
if (! $validator->isMxSupported()) {

[BUG] Initialize variable to prevent error when not set

And do refactoring