Completed
Push — master ( 33fb79...c738ff )
by Adam
12s queued 10s
created

Message::setSubject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * Message.php
4
 *
5
 * @copyright      More in license.md
6
 * @license        https://www.ipublikuj.eu
7
 * @author         Adam Kadlec <[email protected]>
8
 * @package        iPublikuj:EmailModule!
9
 * @subpackage     Message
10
 * @since          1.0.0
11
 *
12
 * @date           30.12.16
13
 */
14
15
declare(strict_types = 1);
16
17
namespace IPub\EmailModule\Message;
18
19
use Nette\Mail;
20
use Nette\Utils;
21
22
use IPub\EmailModule\Entities;
23
24
use IPub\Framework;
25
26
/**
27
 * Email message
28
 *
29
 * @package        iPublikuj:EmailModule!
30
 * @subpackage     Message
31
 *
32
 * @author         Adam Kadlec <[email protected]>
33
 */
34
final class Message extends Mail\Message implements IMessage
35
{
36
	/**
37
	 * @param Entities\Addresses\IAddress $from
38
	 * @param Entities\Addresses\IAddress|NULL $replyTo
39
	 */
40
	function __construct(
0 ignored issues
show
Best Practice introduced by Adam Kadlec
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
41
		Entities\Addresses\IAddress $from,
42
		Entities\Addresses\IAddress $replyTo = NULL
43
	) {
44
		parent::__construct();
45
46
		// Remove nette header
47
		$this->clearHeader('X-Mailer');
48
		// Set framework header
49
		$this->setHeader('X-Mailer', 'iPublikuj:Framework!');
50
51
		parent::setFrom($from->getEmail(), $from->getName());
52
53
		if ($replyTo) {
54
			parent::addReplyTo($replyTo->getEmail(), $replyTo->getName());
55
		}
56
	}
57
58
	/**
59
	 * {@inheritDoc}
60
	 */
61
	public function addReplyTo(string $email, string $name = NULL) : void
62
	{
63
		if (!Utils\Validators::isEmail($email)) {
64
			throw new Framework\Exceptions\InvalidArgumentException(sprintf('Provided email address "%s" is not valid.', $email));
65
		}
66
67
		parent::addReplyTo($email, $name);
68
	}
69
70
	/**
71
	 * {@inheritDoc}
72
	 */
73
	public function addTo(string $email, string $name = NULL) : void
74
	{
75
		if (!Utils\Validators::isEmail($email)) {
76
			throw new Framework\Exceptions\InvalidArgumentException(sprintf('Provided email address "%s" is not valid.', $email));
77
		}
78
79
		parent::addTo($email, $name);
80
	}
81
82
	/**
83
	 * {@inheritDoc}
84
	 */
85
	public function setSubject(string $subject) : void
86
	{
87
		parent::setSubject($subject);
88
	}
89
}
90