Passed
Push — master ( a9f547...49cca7 )
by Raffael
04:18
created

UserMessage::decorate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 0
cts 8
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
crap 2
eloc 6
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * balloon
7
 *
8
 * @copyright   Copryright (c) 2012-2018 gyselroth GmbH (https://gyselroth.com)
9
 * @license     GPL-3.0 https://opensource.org/licenses/GPL-3.0
10
 */
11
12
namespace Balloon\App\Notification;
13
14
use Balloon\Server\User;
15
16
class UserMessage implements MessageInterface
17
{
18
    /**
19
     * Subject.
20
     *
21
     * @var string
22
     */
23
    protected $subject;
24
25
    /**
26
     * Message.
27
     *
28
     * @var string
29
     */
30
    protected $body;
31
32
    /**
33
     * Template handler.
34
     *
35
     * @var TemplateHandler
36
     */
37
    protected $template;
38
39
    /**
40
     * Constructor.
41
     */
42
    public function __construct(string $subject, string $body, TemplateHandler $template)
43
    {
44
        $this->subject = $subject;
45
        $this->body = $body;
46
        $this->template = $template;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getSubject(User $user): string
53
    {
54
        return $this->template->getSubject('user_message', [
55
            'user' => $user,
56
            'user_subject' => $this->subject,
57
        ]);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getBody(User $user): string
64
    {
65
        return $this->template->getBody('user_message', [
66
            'user' => $user,
67
            'user_body' => $this->body,
68
        ]);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function renderTemplate(string $template, User $user): string
75
    {
76
        return $this->template->renderTemplate('user_message', $template, [
77
            'user' => $user,
78
            'user_body' => $this->body,
79
        ]);
80
    }
81
}
82