MessageFactory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 47
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 6 1
A bindReturnPath() 0 4 2
A bindFrom() 0 4 2
A createSystemMessage() 0 6 1
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