MessageFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
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
class MessageFactory implements IMessageFactory
8
{
9
10
	/** @var string */
11
	private $from;
12
13
	/** @var string */
14
	private $returnPath;
15
16
17
	public function __construct(string $from, string $returnPath)
18
	{
19
		$this->from = $from;
20
		$this->returnPath = $returnPath;
21
	}
22
23
24
	public function create(): Mail\Message
25
	{
26
		$message = new Mail\Message;
27
		$this->bindFrom($message);
28
		$this->bindReturnPath($message);
29
		return $message;
30
	}
31
32
33
	public function createSystemMessage(): SystemMessage
34
	{
35
		$message = new SystemMessage;
36
		$this->bindFrom($message);
37
		$this->bindReturnPath($message);
38
		return $message;
39
	}
40
41
42
	private function bindFrom(Mail\Message $message): void
43
	{
44
		if ($this->from !== '') {
45
			$message->setFrom($this->from);
46
		}
47
	}
48
49
50
	private function bindReturnPath(Mail\Message $message): void
51
	{
52
		if ($this->returnPath !== '') {
53
			$message->setReturnPath($this->returnPath);
54
		}
55
	}
56
57
}
58