From: Michele Locati <michele@locati.it>
Date: Fri, 4 Dec 2020 14:18:28 +0100
Subject: [PATCH] Fix "Trying to access array offset on value of type null"

---

--- a/src/Egulias/EmailValidator/Parser/DomainPart.php
+++ b/src/Egulias/EmailValidator/Parser/DomainPart.php
@@ -15,6 +15,10 @@ class DomainPart extends Parser
     {
         $this->lexer->moveNext();
 
+        if (!$this->lexer->token) {
+            throw new \InvalidArgumentException('ERR_NODOMAIN');
+        }
+    
         if ($this->lexer->token['type'] === EmailLexer::S_DOT) {
             throw new \InvalidArgumentException('ERR_DOT_START');
         }

--- a/src/Egulias/EmailValidator/Parser/LocalPart.php
+++ b/src/Egulias/EmailValidator/Parser/LocalPart.php
@@ -13,7 +13,7 @@ class LocalPart extends Parser
         $closingQuote = false;
         $openedParenthesis = 0;
 
-        while ($this->lexer->token['type'] !== EmailLexer::S_AT && $this->lexer->token) {
+        while ($this->lexer->token && $this->lexer->token['type'] !== EmailLexer::S_AT) {
             if ($this->lexer->token['type'] === EmailLexer::S_DOT && !$this->lexer->getPrevious()) {
                 throw new \InvalidArgumentException('ERR_DOT_START');
             }

--- a/src/Egulias/EmailValidator/Parser/Parser.php
+++ b/src/Egulias/EmailValidator/Parser/Parser.php
@@ -129,7 +129,7 @@ abstract class Parser
     {
         $previous = $this->lexer->getPrevious();
 
-        if ($previous['type'] === EmailLexer::S_BACKSLASH
+        if ($previous && $previous['type'] === EmailLexer::S_BACKSLASH
             &&
             $this->lexer->token['type'] !== EmailLexer::GENERIC
         ) {
