Passed
Push — master ( 61339d...e1825b )
by Hirofumi
50:38 queued 46:30
created

TemplateNotificationFactory::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 24
ccs 14
cts 14
cp 1
rs 9.536
c 0
b 0
f 0
cc 1
nc 1
nop 4
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shippinno\Notification\Domain\Model;
5
6
use Shippinno\Template\LoadFailedException;
7
use Shippinno\Template\RenderFailedException;
8
use Shippinno\Template\Template;
9
use Shippinno\Template\TemplateNotFoundException;
10
11
class TemplateNotificationFactory
12
{
13
    /**
14
     * @var Template
15
     */
16
    private $template;
17
18
    /**
19
     * @var string
20
     */
21
    private $subjectTemplateNameFormat = '%s.subject';
22
23
    /**
24
     * @var string
25
     */
26
    private $bodyTemplateNameFormat = '%s.body';
27
28
    /**
29
     * @param Template $template
30
     */
31 1
    public function __construct(Template $template)
32
    {
33 1
        $this->template = $template;
34 1
    }
35
36
    /**
37
     * @param string $templateName
38
     * @param array $templateVariables
39
     * @param Destination $destination
40
     * @param DeduplicationKey|null $deduplicationKey
41
     * @return Notification
42
     * @throws LoadFailedException
43
     * @throws RenderFailedException
44
     * @throws TemplateNotFoundException
45
     */
46 1
    public function create(
47
        string $templateName,
48
        array $templateVariables,
49
        Destination $destination,
50
        DeduplicationKey $deduplicationKey = null
51
    ) {
52 1
        $subject = $this->template->render(
53 1
            sprintf($this->subjectTemplateNameFormat, $templateName),
54 1
            $templateVariables
55
        );
56 1
        $body = $this->template->render(
57 1
            sprintf($this->bodyTemplateNameFormat, $templateName),
58 1
            $templateVariables
59
        );
60
61 1
        return new Notification(
62 1
            $destination,
63 1
            new Subject($subject),
64 1
            new Body($body),
65 1
            $deduplicationKey,
66 1
            $templateName,
67 1
            $templateVariables
68
        );
69
    }
70
}
71