SystemMessage::setBody()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 2
nop 1
dl 0
loc 19
rs 9.8666
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace h4kuna\MailManager\Message;
4
5
use Nette\Mail;
6
7
/**
8
 * Send system mail
9
 */
10
class SystemMessage extends Mail\Message
11
{
12
13
	public function setBody(string $body)
14
	{
15
		$find = null;
16
		preg_match_all('/^([A-Z].*?): (.*)$/m', $body, $find);
17
		if ($find[0]) {
18
			foreach ($find[1] as $k => $header) {
19
				$method = 'add' . ucfirst($header);
20
				if (method_exists($this, $method)) {
21
					$this->{$method}($find[2][$k]);
22
				} else {
23
					$this->setHeader($header, $find[2][$k]);
24
				}
25
			}
26
27
			preg_match("/\n{2,}(.*)$/s", $body, $find);
28
29
			$body = $find[1];
30
		}
31
		return parent::setBody($body);
32
	}
33
34
}
35