Message::getTemplate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace HoomanMirghasemi\Sms;
4
5
use HoomanMirghasemi\Sms\Contracts\Message as MessageContract;
6
7
class Message implements MessageContract
8
{
9
    /**
10
     * Plain text message.
11
     *
12
     * @param string
13
     */
14
    protected string $message;
15
16
    /**
17
     * Template options.
18
     *
19
     * @var array
20
     */
21
    protected array $template = [
22
        'identifier' => null,
23
        'params'     => null,
24
    ];
25
26
    /**
27
     * Message constructor.
28
     *
29
     * @param string $message
30
     */
31
    public function __construct(string $message)
32
    {
33
        $this->message = $message;
34
    }
35
36
    /**
37
     * Retrieve string format of message.
38
     *
39
     * @return string
40
     */
41
    public function toString(): string
42
    {
43
        return $this->message;
44
    }
45
46
    /**
47
     * Retrieve string format of message.
48
     *
49
     * @param string $templateIdentifier
50
     * @param array  $params
51
     *
52
     * @return self
53
     */
54
    public function useTemplateIfSupports(string $templateIdentifier, array $params = []): self
55
    {
56
        $this->template['identifier'] = $templateIdentifier;
57
        $this->template['params'] = $params;
58
59
        return $this;
60
    }
61
62
    /**
63
     * Determine if message uses a template.
64
     */
65
    public function usesTemplate(): bool
66
    {
67
        return !is_null($this->template['identifier']);
68
    }
69
70
    /**
71
     * Retrieve template options.
72
     *
73
     * @return array
74
     */
75
    public function getTemplate(): array
76
    {
77
        return $this->template;
78
    }
79
}
80