Redefine parser signature

This commit is contained in:
Eduardo Gulias Davis
2020-09-12 16:35:38 +02:00
parent 0ba6f87f8e
commit a7ebdba30a
9 changed files with 23 additions and 28 deletions
+2 -2
View File
@@ -69,12 +69,12 @@ class EmailParser
return new InvalidEmail(new NoLocalPart(), $this->lexer->token["value"]);
}
$localPartResult = $this->localPartParser->parse($str);
$localPartResult = $this->localPartParser->parse();
if ($localPartResult->isInvalid()) {
return $localPartResult;
}
$domainPartResult = $this->domainPartParser->parse($str);
$domainPartResult = $this->domainPartParser->parse();
if ($domainPartResult->isInvalid()) {
return $domainPartResult;
}
+2 -4
View File
@@ -3,12 +3,10 @@
namespace Egulias\EmailValidator\Parser;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Result\ValidEmail;
use Egulias\EmailValidator\Warning\CFWSNearAt;
use Egulias\EmailValidator\Result\Result;
use Egulias\EmailValidator\Warning\QuotedPart;
use Egulias\EmailValidator\Result\InvalidEmail;
use Egulias\EmailValidator\Parser\CommentStrategy;
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
use Egulias\EmailValidator\Result\Reason\UnclosedComment;
use Egulias\EmailValidator\Result\Reason\UnOpenedComment;
use Egulias\EmailValidator\Warning\Comment as WarningComment;
@@ -25,7 +23,7 @@ class Comment extends Parser
$this->commentStrategy = $commentStrategy;
}
public function parse($str)
public function parse() : Result
{
if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) {
$this->openedParenthesis++;
+2 -2
View File
@@ -25,8 +25,8 @@ class DomainComment implements CommentStrategy
if (!$lexer->isNextToken(EmailLexer::S_DOT)) {
return new InvalidEmail(new ExpectingATEXT('DOT not found near CLOSEPARENTHESIS'), $lexer->token['value']);
}
//add warning
//Address is valid within the message but cannot be used unmodified for the envelope
//add warning
//Address is valid within the message but cannot be used unmodified for the envelope
return new ValidEmail();
}
+5 -4
View File
@@ -2,13 +2,12 @@
namespace Egulias\EmailValidator\Parser;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Result\Reason\CRNoLF;
use Egulias\EmailValidator\Result\Reason\ExpectingDTEXT;
use Egulias\EmailValidator\Result\Result;
use Egulias\EmailValidator\Result\ValidEmail;
use Egulias\EmailValidator\Result\InvalidEmail;
use Egulias\EmailValidator\Warning\DomainLiteral as WarningDomainLiteral;
use Egulias\EmailValidator\Warning\CFWSWithFWS;
use Egulias\EmailValidator\Warning\IPV6BadChar;
use Egulias\EmailValidator\Result\Reason\CRNoLF;
use Egulias\EmailValidator\Warning\IPV6ColonEnd;
use Egulias\EmailValidator\Warning\IPV6MaxGroups;
use Egulias\EmailValidator\Warning\ObsoleteDTEXT;
@@ -17,10 +16,12 @@ use Egulias\EmailValidator\Warning\IPV6ColonStart;
use Egulias\EmailValidator\Warning\IPV6Deprecated;
use Egulias\EmailValidator\Warning\IPV6GroupCount;
use Egulias\EmailValidator\Warning\IPV6DoubleColon;
use Egulias\EmailValidator\Result\Reason\ExpectingDTEXT;
use Egulias\EmailValidator\Warning\DomainLiteral as WarningDomainLiteral;
class DomainLiteral extends Parser
{
public function parse($remove)
public function parse() : Result
{
$this->addTagWarnings();
+3 -3
View File
@@ -31,7 +31,7 @@ class DomainPart extends Parser
*/
protected $domainPart = '';
public function parse($domainPart)
public function parse() : Result
{
$this->lexer->moveNext();
@@ -114,7 +114,7 @@ class DomainPart extends Parser
protected function parseComments()
{
$commentParser = new Comment($this->lexer, new DomainComment());
$result = $commentParser->parse('remove');
$result = $commentParser->parse();
$this->warnings = array_merge($this->warnings, $commentParser->getWarnings());
return $result;
@@ -195,7 +195,7 @@ class DomainPart extends Parser
}
$domainLiteralParser = new DomainLiteralParser($this->lexer);
$result = $domainLiteralParser->parse('remove');
$result = $domainLiteralParser->parse();
$this->warnings = array_merge($this->warnings, $domainLiteralParser->getWarnings());
return $result;
}
+1 -1
View File
@@ -13,7 +13,7 @@ use Egulias\EmailValidator\Result\Result;
class DoubleQuote extends Parser
{
public function parse($qouted)
public function parse() : Result
{
$validQuotedString = $this->checkDQUOTE();
+2 -1
View File
@@ -10,11 +10,12 @@ use Egulias\EmailValidator\Result\Reason\AtextAfterCFWS;
use Egulias\EmailValidator\Result\Reason\CRLFAtTheEnd;
use Egulias\EmailValidator\Result\Reason\CRLFX2;
use Egulias\EmailValidator\Result\Reason\ExpectingCTEXT;
use Egulias\EmailValidator\Result\Result;
use Egulias\EmailValidator\Result\ValidEmail;
class FoldingWhiteSpace extends Parser
{
public function parse($str)
public function parse() : Result
{
if (!$this->isFWS()) {
return new ValidEmail();
+4 -6
View File
@@ -26,9 +26,7 @@ class LocalPart extends Parser
EmailLexer::INVALID => EmailLexer::INVALID
);
private $foldingWS;
public function parse($localPart) : Result
public function parse() : Result
{
$totalLength = 0;
@@ -95,7 +93,7 @@ class LocalPart extends Parser
{
//use $this->parseFWS()
$foldingWS = new FoldingWhiteSpace($this->lexer);
$resultFWS = $foldingWS->parse('remove');
$resultFWS = $foldingWS->parse();
if ($resultFWS->isValid()) {
$this->warnings = array_merge($this->warnings, $foldingWS->getWarnings());
}
@@ -110,7 +108,7 @@ class LocalPart extends Parser
private function parseDoubleQuote() : Result
{
$dquoteParser = new DoubleQuote($this->lexer);
$parseAgain = $dquoteParser->parse("remove useless arg");
$parseAgain = $dquoteParser->parse();
$this->warnings = array_merge($this->warnings, $dquoteParser->getWarnings());
return $parseAgain;
@@ -119,7 +117,7 @@ class LocalPart extends Parser
private function parseComments()
{
$commentParser = new Comment($this->lexer, new LocalComment());
$result = $commentParser->parse('remove');
$result = $commentParser->parse();
$this->warnings = array_merge($this->warnings, $commentParser->getWarnings());
if($result->isInvalid()) {
return $result;
+2 -5
View File
@@ -33,15 +33,12 @@ abstract class Parser
return $this->warnings;
}
/**
* @param string $str
*/
abstract public function parse($str);
abstract public function parse() : Result;
protected function parseFWS() : Result
{
$foldingWS = new FoldingWhiteSpace($this->lexer);
$resultFWS = $foldingWS->parse('remove');
$resultFWS = $foldingWS->parse();
$this->warnings = array_merge($this->warnings, $foldingWS->getWarnings());
return $resultFWS;
}