mirror of
https://github.com/egulias/EmailValidator.git
synced 2026-09-20 15:16:40 +00:00
e834eea530
* experimenting with psalm * loading in symfony polyfill, partially resolves egulias/EmailValidator#177, but SpoofChecker does not seem to be polyfilled in symfony/polyfill-intl-* * removing unused imports, fixes egulias/EmailValidator#168 and egulias/EmailValidator#169 * not actually used for object storage * Egulias\Tests\EmailValidator\Validation\SpoofCheckValidationTest::testEmailWithSpoofsIsInvalid fails if extension is not installed * satisfying psalm * amending indentation * disabling psalm on 5.6 * attempting to resolve psalm issue on 7.0 & 7.1 * dropping psalm from 7.0 matrix * ext-intl removed as per egulias/EmailValidator#231 * updating baseline with psalm 3.8.3 * suppressing issue with Spoofchecker not being present, pending resolution of egulias/EmailValidator#231 * enable psalm on travis config for php 7.3
52 lines
1.1 KiB
PHP
52 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace Egulias\EmailValidator\Validation;
|
|
|
|
use Egulias\EmailValidator\EmailLexer;
|
|
use Egulias\EmailValidator\Exception\InvalidEmail;
|
|
use Egulias\EmailValidator\Validation\Error\SpoofEmail;
|
|
use \Spoofchecker;
|
|
|
|
class SpoofCheckValidation implements EmailValidation
|
|
{
|
|
/**
|
|
* @var InvalidEmail|null
|
|
*/
|
|
private $error;
|
|
|
|
public function __construct()
|
|
{
|
|
if (!extension_loaded('intl')) {
|
|
throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @psalm-suppress InvalidArgument
|
|
*/
|
|
public function isValid($email, EmailLexer $emailLexer)
|
|
{
|
|
$checker = new Spoofchecker();
|
|
$checker->setChecks(Spoofchecker::SINGLE_SCRIPT);
|
|
|
|
if ($checker->isSuspicious($email)) {
|
|
$this->error = new SpoofEmail();
|
|
}
|
|
|
|
return $this->error === null;
|
|
}
|
|
|
|
/**
|
|
* @return InvalidEmail|null
|
|
*/
|
|
public function getError()
|
|
{
|
|
return $this->error;
|
|
}
|
|
|
|
public function getWarnings()
|
|
{
|
|
return [];
|
|
}
|
|
}
|