SMS77Message::to()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace NotificationChannels\SMS77;
4
5
class SMS77Message
6
{
7
    protected $payload = [];
8
9
    /**
10
     * @param string $message
11
     */
12
    public function __construct(string $message = '')
13
    {
14
        $this->payload['text'] = $message;
15
        $this->payload['json'] = 1;
16
    }
17
18
    /**
19
     * Get the payload value for a given key.
20
     *
21
     * @param string $key
22
     *
23
     * @return mixed|null
24
     */
25
    public function getPayloadValue(string $key)
26
    {
27
        return $this->payload[$key] ?? null;
28
    }
29
30
    /**
31
     * Return new SMS77Message object.
32
     *
33
     * @param string $message
34
     */
35
    public static function create(string $message = ''): self
36
    {
37
        return new self($message);
38
    }
39
40
    /**
41
     * Returns if recipient number is given or not.
42
     *
43
     * @return bool
44
     */
45
    public function hasToNumber(): bool
46
    {
47
        return isset($this->payload['to']);
48
    }
49
50
    /**
51
     * Return payload.
52
     *
53
     * @return array
54
     */
55
    public function toArray(): array
56
    {
57
        return $this->payload;
58
    }
59
60
    /**
61
     * Set message content.
62
     *
63
     * @param string $message
64
     */
65
    public function content(string $message): self
66
    {
67
        $this->payload['text'] = $message;
68
69
        return $this;
70
    }
71
72
    /**
73
     * Set recipient phone number.
74
     *
75
     * @param string $to
76
     */
77
    public function to(string $to): self
78
    {
79
        $this->payload['to'] = $to;
80
81
        return $this;
82
    }
83
84
    /**
85
     * Set sender name.
86
     *
87
     * @param string $from
88
     */
89
    public function from(string $from): self
90
    {
91
        $this->payload['from'] = $from;
92
93
        return $this;
94
    }
95
96
    /**
97
     * Set notification delay.
98
     *
99
     * @param string $timestamp
100
     */
101
    public function delay(string $timestamp): self
102
    {
103
        $this->payload['delay'] = $timestamp;
104
105
        return $this;
106
    }
107
108
    /**
109
     * Disable reload lock.
110
     */
111
    public function noReload(): self
112
    {
113
        $this->payload['no_reload'] = 1;
114
115
        return $this;
116
    }
117
118
    /**
119
     * Activate debug mode.
120
     */
121
    public function debug(): self
122
    {
123
        $this->payload['debug'] = 1;
124
125
        return $this;
126
    }
127
128
    /**
129
     * Set encoding to unicode.
130
     */
131
    public function unicode(): self
132
    {
133
        $this->payload['unicode'] = 1;
134
135
        return $this;
136
    }
137
138
    /**
139
     * SMS is sent as flash message.
140
     */
141
    public function flash(): self
142
    {
143
        $this->payload['flash'] = 1;
144
145
        return $this;
146
    }
147
148
    /**
149
     * The API returns more details about the SMS sent.
150
     */
151
    public function details(): self
152
    {
153
        $this->payload['details'] = 1;
154
155
        return $this;
156
    }
157
}
158