Passed
Branch master (e1825b)
by Hirofumi
26:10 queued 08:29
created

TemplateNotificationFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 60
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A create() 0 24 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