SpoofCheckValidation.php 990 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace Egulias\EmailValidator\Validation;
  3. use Egulias\EmailValidator\EmailLexer;
  4. use Egulias\EmailValidator\Exception\InvalidEmail;
  5. use Egulias\EmailValidator\Validation\Error\SpoofEmail;
  6. use \Spoofchecker;
  7. class SpoofCheckValidation implements EmailValidation
  8. {
  9. /**
  10. * @var InvalidEmail
  11. */
  12. private $error;
  13. public function __construct()
  14. {
  15. if (!extension_loaded('intl')) {
  16. throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
  17. }
  18. }
  19. public function isValid($email, EmailLexer $emailLexer)
  20. {
  21. $checker = new Spoofchecker();
  22. $checker->setChecks(Spoofchecker::SINGLE_SCRIPT);
  23. if ($checker->isSuspicious($email)) {
  24. $this->error = new SpoofEmail();
  25. }
  26. return $this->error === null;
  27. }
  28. public function getError()
  29. {
  30. return $this->error;
  31. }
  32. public function getWarnings()
  33. {
  34. return [];
  35. }
  36. }