vendor/egulias/email-validator/src/MessageIDParser.php line 32

Open in your IDE?
  1. <?php
  2. namespace Egulias\EmailValidator;
  3. use Egulias\EmailValidator\Parser;
  4. use Egulias\EmailValidator\EmailLexer;
  5. use Egulias\EmailValidator\Result\Result;
  6. use Egulias\EmailValidator\Parser\IDLeftPart;
  7. use Egulias\EmailValidator\Parser\IDRightPart;
  8. use Egulias\EmailValidator\Result\ValidEmail;
  9. use Egulias\EmailValidator\Result\InvalidEmail;
  10. use Egulias\EmailValidator\Warning\EmailTooLong;
  11. use Egulias\EmailValidator\Result\Reason\NoLocalPart;
  12. class MessageIDParser extends Parser
  13. {
  14.     const EMAILID_MAX_LENGTH 254;
  15.     /**
  16.      * @var string
  17.      */
  18.     protected $idLeft '';
  19.     /**
  20.      * @var string
  21.      */
  22.     protected $idRight '';
  23.     public function parse(string $str) : Result
  24.     {
  25.         $result parent::parse($str);
  26.         $this->addLongEmailWarning($this->idLeft$this->idRight);
  27.         return $result;
  28.     }
  29.     
  30.     protected function preLeftParsing(): Result
  31.     {
  32.         if (!$this->hasAtToken()) {
  33.             return new InvalidEmail(new NoLocalPart(), $this->lexer->token["value"]);
  34.         }
  35.         return new ValidEmail();
  36.     }
  37.     protected function parseLeftFromAt(): Result
  38.     {
  39.         return $this->processIDLeft();
  40.     }
  41.     protected function parseRightFromAt(): Result
  42.     {
  43.         return $this->processIDRight();
  44.     }
  45.     private function processIDLeft() : Result
  46.     {
  47.         $localPartParser = new IDLeftPart($this->lexer);
  48.         $localPartResult $localPartParser->parse();
  49.         $this->idLeft $localPartParser->localPart();
  50.         $this->warnings array_merge($localPartParser->getWarnings(), $this->warnings);
  51.         return $localPartResult;
  52.     }
  53.     private function processIDRight() : Result
  54.     {
  55.         $domainPartParser = new IDRightPart($this->lexer);
  56.         $domainPartResult $domainPartParser->parse();
  57.         $this->idRight $domainPartParser->domainPart();
  58.         $this->warnings array_merge($domainPartParser->getWarnings(), $this->warnings);
  59.         
  60.         return $domainPartResult;
  61.     }
  62.     public function getLeftPart() : string
  63.     {
  64.         return $this->idLeft;
  65.     }
  66.     public function getRightPart() : string
  67.     {
  68.         return $this->idRight;
  69.     }
  70.     private function addLongEmailWarning(string $localPartstring $parsedDomainPart) : void
  71.     {
  72.         if (strlen($localPart '@' $parsedDomainPart) > self::EMAILID_MAX_LENGTH) {
  73.             $this->warnings[EmailTooLong::CODE] = new EmailTooLong();
  74.         }
  75.     }
  76. }