TemplateMessage::addContent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * This file is part of the theroadbunch/mandrill-sdk package.
5
 *
6
 * (c) Dan McAdams <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace RoadBunch\Mandrill\Message;
13
14
15
/**
16
 * Class TemplateMessage
17
 *
18
 * @author  Dan McAdams
19
 * @package RoadBunch\Mandrill\Message
20
 */
21
class TemplateMessage extends Message implements TemplateMessageInterface
22
{
23
    /**
24
     * the immutable name or slug of a template that exists in the user's account.
25
     *  For backwards-compatibility, the template name may also be used but the immutable slug is preferred.
26
     *
27
     * @var string $name
28
     */
29
    protected $name;
30
31
    /**
32
     * an array of template content to send.
33
     * Each item in the array should be a struct with two keys
34
     *  - name:     the name of the content block to set the content for
35
     *  - content:  the actual content to put into the block
36
     *
37
     * @var array $content
38
     */
39
    protected $content = [];
40
41
    public function __construct(string $name)
42
    {
43
        $this->name = $name;
44
    }
45
46
    /**
47
     * the immutable name or slug of a template that exists in the user's account.
48
     *
49
     * @return string
50
     */
51
    public function getName(): string
52
    {
53
        return $this->name;
54
    }
55
56
57
    /**
58
     * @param string $name    the name of the mc:edit editable region to inject into
59
     * @param string $content the content to inject
60
     */
61
    public function addContent(string $name, string $content)
62
    {
63
        $this->content[] = [
64
            'name'    => $name,
65
            'content' => $content
66
        ];
67
    }
68
69
    /**
70
     * an array of template content to send.
71
     *
72
     * [[
73
     *      'name' => 'template_constant',
74
     *      'content' => 'template content'
75
     * ]]
76
     *
77
     * @return array
78
     */
79
    public function getContent(): array
80
    {
81
        return $this->content;
82
    }
83
}
84