SystemMessage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A setBody() 0 19 4
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