DomainComment.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace Egulias\EmailValidator\Parser\CommentStrategy;
  3. use Egulias\EmailValidator\EmailLexer;
  4. use Egulias\EmailValidator\Result\Result;
  5. use Egulias\EmailValidator\Result\ValidEmail;
  6. use Egulias\EmailValidator\Result\InvalidEmail;
  7. use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
  8. class DomainComment implements CommentStrategy
  9. {
  10. public function exitCondition(EmailLexer $lexer, int $openedParenthesis) : bool
  11. {
  12. if (($openedParenthesis === 0 && $lexer->isNextToken(EmailLexer::S_DOT))){ // || !$internalLexer->moveNext()) {
  13. return false;
  14. }
  15. return true;
  16. }
  17. public function endOfLoopValidations(EmailLexer $lexer) : Result
  18. {
  19. //test for end of string
  20. if (!$lexer->isNextToken(EmailLexer::S_DOT)) {
  21. return new InvalidEmail(new ExpectingATEXT('DOT not found near CLOSEPARENTHESIS'), $lexer->token['value']);
  22. }
  23. //add warning
  24. //Address is valid within the message but cannot be used unmodified for the envelope
  25. return new ValidEmail();
  26. }
  27. public function getWarnings(): array
  28. {
  29. return [];
  30. }
  31. }