SpoofCheckValidation.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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|null
  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. /**
  20. * @psalm-suppress InvalidArgument
  21. */
  22. public function isValid($email, EmailLexer $emailLexer)
  23. {
  24. $checker = new Spoofchecker();
  25. $checker->setChecks(Spoofchecker::SINGLE_SCRIPT);
  26. if ($checker->isSuspicious($email)) {
  27. $this->error = new SpoofEmail();
  28. }
  29. return $this->error === null;
  30. }
  31. /**
  32. * @return InvalidEmail|null
  33. */
  34. public function getError()
  35. {
  36. return $this->error;
  37. }
  38. public function getWarnings()
  39. {
  40. return [];
  41. }
  42. }