Completed
Push — master ( afaf42...8ac772 )
by Raffael
20:10 queued 16:21
created

Message::getSubject()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 6
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 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 Message implements MessageInterface
17
{
18
    /**
19
     * Message type.
20
     *
21
     * @var string
22
     */
23
    protected $type;
24
25
    /**
26
     * Context.
27
     *
28
     * @var array
29
     */
30
    protected $context = [];
31
32
    /**
33
     * Template handler.
34
     *
35
     * @var TemplateHandler
36
     */
37
    protected $template;
38
39
    /**
40
     * Constructor.
41
     */
42
    public function __construct(string $type, TemplateHandler $template, array $context = [])
43
    {
44
        $this->type = $type;
45
        $this->template = $template;
46
        $this->context = $context;
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function getSubject(?User $user = null): string
53
    {
54
        $context = $this->context;
55
        $context['user'] = $user;
56
57
        return $this->template->getSubject($this->type, $context);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function getBody(?User $user = null): string
64
    {
65
        $context = $this->context;
66
        $context['user'] = $user;
67
68
        return $this->template->getBody($this->type, $context);
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74
    public function getContext(): array
75
    {
76
        return $this->context;
77
    }
78
79
    /**
80
     * {@inheritdoc}
81
     */
82
    public function getType(): string
83
    {
84
        return $this->type;
85
    }
86
87
    /**
88
     * {@inheritdoc}
89
     */
90
    public function renderTemplate(string $template, ?User $user = null): string
91
    {
92
        $context = $this->context;
93
        $context['user'] = $user;
94
95
        return $this->template->renderTemplate($this->type, $template, $context);
96
    }
97
}
98