SMS   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 186
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 34
c 3
b 1
f 0
dl 0
loc 186
ccs 41
cts 41
cp 1
rs 10
wmc 14

12 Methods

Rating   Name   Duplication   Size   Complexity  
A deleteDeliveryReceiptNotificationUrl() 0 4 2
A ordersHistory() 0 4 1
A checkDeliveryReceiptNotificationUrl() 0 4 1
A send() 0 8 1
A setDeliveryReceiptNotificationUrl() 0 4 2
A from() 0 7 1
A to() 0 5 1
A setClient() 0 5 1
A message() 0 5 1
A __construct() 0 3 1
A statistics() 0 4 1
A balance() 0 4 1
1
<?php
2
3
namespace Mediumart\Orange\SMS;
4
5
use Mediumart\Orange\SMS\Http\SMSClient;
6
use Mediumart\Orange\SMS\Http\Requests\ContractsRequest;
7
use Mediumart\Orange\SMS\Http\Requests\StatisticsRequest;
8
use Mediumart\Orange\SMS\Http\Requests\OutboundSMSRequest;
9
use Mediumart\Orange\SMS\Http\Requests\OrdersHistoryRequest;
10
use Mediumart\Orange\SMS\Http\Requests\SMSDRCheckCallbackRequest;
11
use Mediumart\Orange\SMS\Http\Requests\SMSDRDeleteCallbackRequest;
12
use Mediumart\Orange\SMS\Http\Requests\SMSDRRegisterCallbackRequest;
13
14
class SMS
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $recipientNumber;
20
    /**
21
     * @var string
22
     */
23
    protected $senderNumber;
24
25
    /**
26
     * @var string
27
     */
28
    protected $senderName;
29
30
    /**
31
     * @var string
32
     */
33
    protected $message;
34
35
    /**
36
     * @var SMSClient
37
     */
38
    protected $client;
39
40
    /**
41
     * Outbound SMS Object constructor.
42
     *
43
     * @param SMSClient $client
44
     */
45 9
    public function __construct(SMSClient $client)
46
    {
47 9
        $this->client = $client;
48 9
    }
49
50
     /**
51
      * Set SMS client.
52
      *
53
     * @param SMSClient $client
54
     * @return $this
55
     */
56 1
    public function setClient(SMSClient $client)
57
    {
58 1
        $this->client = $client;
59
60 1
        return $this;
61
    }
62
63
    /**
64
     * Set SMS recipient.
65
     *
66
     * @param string $recipientNumber
67
     * @return $this
68
     */
69 1
    public function to($recipientNumber)
70
    {
71 1
        $this->recipientNumber = $recipientNumber;
72
73 1
        return $this;
74
    }
75
76
    /**
77
     * set SMS sender details.
78
     *
79
     * @param string $number
80
     * @param string|null $name
81
     * @return $this
82
     */
83 1
    public function from($number, $name = null)
84
    {
85 1
        $this->senderNumber = $number;
86
87 1
        $this->senderName = $name;
88
89 1
        return $this;
90
    }
91
92
    /**
93
     * Set SMS message.
94
     *
95
     * @param string $message
96
     * @return $this
97
     */
98 1
    public function message($message)
99
    {
100 1
        $this->message = $message;
101
102 1
        return $this;
103
    }
104
105
    /**
106
     * Send SMS.
107
     *
108
     * @return array
109
     */
110 1
    public function send()
111
    {
112 1
        return $this->client->executeRequest(
113 1
            new OutboundSMSRequest(
114 1
                $this->message,
115 1
                $this->recipientNumber,
116 1
                $this->senderNumber,
117 1
                $this->senderName
118
            )
119
        );
120
    }
121
122
    /**
123
     * Get SMS contracts.
124
     *
125
     * @param string|null $country
126
     * @return array
127
     */
128 1
    public function balance($country = null)
129
    {
130 1
        return $this->client->executeRequest(
131 1
            new ContractsRequest($country)
132
        );
133
    }
134
135
    /**
136
     * Get SMS orders history.
137
     *
138
     * @param string|null $country
139
     * @return array
140
     */
141 1
    public function ordersHistory($country = null)
142
    {
143 1
        return $this->client->executeRequest(
144 1
            new OrdersHistoryRequest($country)
145
        );
146
    }
147
148
    /**
149
     * Get SMS statistics.
150
     *
151
     * @param string|null $country
152
     * @param string|null $appID
153
     * @return array
154
     */
155 1
    public function statistics($country = null, $appID = null)
156
    {
157 1
        return $this->client->executeRequest(
158 1
            new StatisticsRequest($country, $appID)
159
        );
160
    }
161
162
    /**
163
     * Set the SMS DR notification endpoint.
164
     *
165
     * @param $url
166
     * @param $sender
167
     * @return array
168
     */
169 2
    public function setDeliveryReceiptNotificationUrl($url, $sender = null)
170
    {
171 2
        return $this->client->executeRequest(
172 2
            new SMSDRRegisterCallbackRequest($url, $sender ?: $this->senderNumber)
173
        );
174
    }
175
176
    /**
177
     * Check the SMS DR notification endpoint.
178
     *
179
     * @param $id
180
     * @return array
181
     */
182 1
    public function checkDeliveryReceiptNotificationUrl($id)
183
    {
184 1
        return $this->client->executeRequest(
185 1
            new SMSDRCheckCallbackRequest($id)
186
        );
187
    }
188
189
    /**
190
     * Delete the SMS DR notification endpoint.
191
     *
192
     * @param $id
193
     * @param $sender
194
     * @return array
195
     */
196 1
    public function deleteDeliveryReceiptNotificationUrl($id, $sender = null)
197
    {
198 1
        return $this->client->executeRequest(
199 1
            new SMSDRDeleteCallbackRequest($id, $sender ?: $this->senderNumber)
200
        );
201
    }
202
}
203