Completed
Pull Request — master (#1473)
by Tim
31:22 queued 01:19
created

TemplateBasedMailer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 3
dl 0
loc 4
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Frontend\Infrastructure\Mail;
6
7
use WMDE\EmailAddress\EmailAddress;
8
use WMDE\Fundraising\Frontend\Presentation\TwigTemplate;
9
use WMDE\Fundraising\DonationContext\Infrastructure\TemplateMailerInterface as DonationTemplateMailerInterface;
10
use WMDE\Fundraising\MembershipContext\Infrastructure\TemplateMailerInterface as MembershipTemplateMailerInterface;
11
use WMDE\Fundraising\SubscriptionContext\Infrastructure\TemplateMailerInterface as SubscriptionTemplateMailerInterface;
12
13
/**
14
 * @license GNU GPL v2+
15
 */
16
class TemplateBasedMailer implements DonationTemplateMailerInterface, MembershipTemplateMailerInterface,
17
	SubscriptionTemplateMailerInterface, GetInTouchMailerInterface {
18
19
	private $messenger;
20
	private $template;
21
	private $subjectRenderer;
22
23 83
	public function __construct( Messenger $messenger, TwigTemplate $template, MailSubjectRendererInterface $subjectRenderer ) {
24 83
		$this->messenger = $messenger;
25 83
		$this->template = $template;
26 83
		$this->subjectRenderer = $subjectRenderer;
27 83
	}
28
29
	/**
30
	 * @inheritdoc
31
	 * @throws \RuntimeException
32
	 */
33 44
	public function sendMail( EmailAddress $recipient, array $templateArguments = [] ): void {
34 44
		$this->messenger->sendMessageToUser(
35 44
			new Message(
36 44
				$this->subjectRenderer->render( $templateArguments ),
37 44
				MailFormatter::format( $this->template->render( $templateArguments ) )
38
			),
39 44
			$recipient
40
		);
41 42
	}
42
43
}
44