change left for right, which is the right one

This commit is contained in:
Eduardo Gulias Davis
2021-02-28 16:05:41 +01:00
parent 07464f87c8
commit b79cd8f033
5 changed files with 25 additions and 19 deletions
+3 -3
View File
@@ -39,7 +39,7 @@ class EmailParser extends Parser
return $result;
}
protected function preRightParsing(): Result
protected function preLeftParsing(): Result
{
if (!$this->hasAtToken()) {
return new InvalidEmail(new NoLocalPart(), $this->lexer->token["value"]);
@@ -47,12 +47,12 @@ class EmailParser extends Parser
return new ValidEmail();
}
protected function parseRightFromAt(): Result
protected function parseLeftFromAt(): Result
{
return $this->processLocalPart();
}
protected function parseLeftFromAt(): Result
protected function parseRightFromAt(): Result
{
return $this->processDomainPart();
}
+11 -11
View File
@@ -6,7 +6,7 @@ use Egulias\EmailValidator\Parser;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Result\Result;
use Egulias\EmailValidator\Parser\LocalPart;
use Egulias\EmailValidator\Parser\IDLeftPart;
use Egulias\EmailValidator\Parser\IDRightPart;
use Egulias\EmailValidator\Result\ValidEmail;
use Egulias\EmailValidator\Result\InvalidEmail;
use Egulias\EmailValidator\Warning\EmailTooLong;
@@ -36,12 +36,12 @@ class MessageIDParser extends Parser
{
$result = parent::parse($str);
$this->addLongEmailWarning($this->localPart, $this->domainPart);
$this->addLongEmailWarning($this->idLeft, $this->idRight);
return $result;
}
protected function preRightParsing(): Result
protected function preLeftParsing(): Result
{
if (!$this->hasAtToken()) {
return new InvalidEmail(new NoLocalPart(), $this->lexer->token["value"]);
@@ -49,17 +49,17 @@ class MessageIDParser extends Parser
return new ValidEmail();
}
protected function parseRightFromAt(): Result
{
return $this->processIDRight();
}
protected function parseLeftFromAt(): Result
{
return $this->processIDLeft();
}
private function processIDRight() : Result
protected function parseRightFromAt(): Result
{
return $this->processIDRight();
}
private function processIDLeft() : Result
{
$localPartParser = new LocalPart($this->lexer);
$localPartResult = $localPartParser->parse();
@@ -69,9 +69,9 @@ class MessageIDParser extends Parser
return $localPartResult;
}
private function processIDLeft() : Result
private function processIDRight() : Result
{
$domainPartParser = new IDLeftPart($this->lexer);
$domainPartParser = new IDRightPart($this->lexer);
$domainPartResult = $domainPartParser->parse();
$this->domainPart = $domainPartParser->domainPart();
$this->warnings = array_merge($domainPartParser->getWarnings(), $this->warnings);
+7 -4
View File
@@ -22,8 +22,11 @@ abstract class Parser
abstract protected function parseRightFromAt() : Result;
abstract protected function parseLeftFromAt() : Result;
abstract protected function preRightParsing() : Result;
abstract protected function preLeftParsing() : Result;
/**
* id-left "@" id-right
*/
public function parse(string $str) : Result
{
$this->lexer->setInput($str);
@@ -32,18 +35,18 @@ abstract class Parser
return new InvalidEmail(new ExpectingATEXT("Invalid tokens found"), $this->lexer->token["value"]);
}
$preParsingResult = $this->preRightParsing();
$preParsingResult = $this->preLeftParsing();
if ($preParsingResult->isInvalid()) {
return $preParsingResult;
}
$localPartResult = $this->parseRightFromAt();
$localPartResult = $this->parseLeftFromAt();
if ($localPartResult->isInvalid()) {
return $localPartResult;
}
$domainPartResult = $this->parseLeftFromAt();
$domainPartResult = $this->parseRightFromAt();
if ($domainPartResult->isInvalid()) {
return $domainPartResult;
@@ -8,7 +8,7 @@ use Egulias\EmailValidator\Result\ValidEmail;
use Egulias\EmailValidator\Result\InvalidEmail;
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
class IDLeftPart extends DomainPart
class IDRightPart extends DomainPart
{
protected function validateTokens(bool $hasComments) : Result
{
@@ -42,6 +42,9 @@ class MessageIDValidationTest extends TestCase
{
return [
['example'],
['example@with space'],
['example@iana.'],
['example@ia\na.'],
];
}
}