Skip to content

Commit

Permalink
Extract method to create Email/Fragment objects
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Nov 28, 2013
1 parent 117b80e commit 3e97213
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions src/EmailReplyParser/Parser/EmailParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,7 @@ public function parse($text)
$this->addFragment($fragment);
}

$fragments = array();
foreach (array_reverse($this->fragments) as $fragment) {
$fragments[] = new Fragment(
preg_replace("/^\n/", '', strrev(implode("\n", $fragment->lines))),
$fragment->isHidden,
$fragment->isSignature,
$fragment->isQuoted
);
}

return new Email($fragments);
return $this->createEmail($this->fragments);
}

/**
Expand All @@ -125,6 +115,26 @@ public function setQuoteHeadersRegex(array $quoteHeadersRegex)
return $this;
}

/**
* @param FragmentDTO[]
*
* @return Email
*/
protected function createEmail(array $fragmentDTOs)
{
$fragments = array();
foreach (array_reverse($fragmentDTOs) as $fragment) {
$fragments[] = new Fragment(
preg_replace("/^\n/", '', strrev(implode("\n", $fragment->lines))),
$fragment->isHidden,
$fragment->isSignature,
$fragment->isQuoted
);
}

return new Email($fragments);
}

private function isQuoteHeader($line)
{
foreach ($this->quoteHeadersRegex as $regex) {
Expand Down

0 comments on commit 3e97213

Please sign in to comment.