SmsBuildClass   B
last analyzed

Complexity

Total Complexity 50

Size/Duplication

Total Lines 350
Duplicated Lines 0 %

Test Coverage

Coverage 66.67%

Importance

Changes 0
Metric Value
dl 0
loc 350
ccs 80
cts 120
cp 0.6667
rs 8.6206
c 0
b 0
f 0
wmc 50

22 Methods

Rating   Name   Duplication   Size   Complexity  
A buildCampaign() 0 7 2
A addUnicode() 0 6 2
A buildAfterMinutes() 0 7 2
A buildBulkAuth() 0 7 2
A buildUnicode() 0 7 2
A addAuth() 0 6 2
A addCampaign() 0 6 2
A buildFlash() 0 7 2
A addFlash() 0 6 2
A buildSmsSender() 0 7 2
A addResponse() 0 6 2
A addSchtime() 0 6 2
A addAfterMinutes() 0 6 2
A buildSchtime() 0 10 4
A buildResponse() 0 7 2
A addMobileNumber() 0 9 4
A buildCountry() 0 9 3
A addCountry() 0 6 2
A addMessage() 0 6 2
A addSender() 0 6 2
A buildMessage() 0 7 2
A addContent() 0 9 3

How to fix   Complexity   

Complex Class

Complex classes like SmsBuildClass often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use SmsBuildClass, and based on these observations, apply Extract Interface, too.

1
<?php
2
namespace Sender\Sms;
3
4
use Sender\Deliver;
5
use Sender\Validation;
6
use Sender\Sms\SmsBulk;
7
use Sender\Sms\SmsNormal;
8
use Sender\MobileNumber;
9
use Sender\Traits\SmsBuildTrait;
10
use Sender\Traits\SmsOtpCommonTrait;
11
use Sender\Traits\SmsBuildSupportTrait;
12
use Sender\Config\Config as ConfigClass;
13
use Sender\ExceptionClass\ParameterException;
14
15
/**
16
 * This Class for Build and send the SMS
17
 *
18
 * @package    Msg91 SMS&OTP package
19
 * @author     VenkatS <[email protected]>
20
 * @link       https://github.com/tesark/msg91-php
21
 * @license    MIT
22
 */
23
24
class SmsBuildClass extends SmsDefineClass
25
{
26
    use SmsBuildTrait;
27
    use SmsOtpCommonTrait;
28
    use SmsBuildSupportTrait;
29
    /**
30
     * This function for Add mobile number
31
     * @param array $xmlDoc
32
     * @param array $smsTag
33
     *
34 80
     */
35
    public function addMobileNumber($xmlDoc, $smsTag)
36 80
    {
37 80
        if ($this->setMobile()) {
38 80
            $mobile = $this->getMobile();
39
            if (isset($mobile) && is_string($mobile)) {
40
                $result = $this->isValidNumber($mobile);
41
                $this->addMobileToXml($xmlDoc, $smsTag, $result);
42
            } else {
43
                throw ParameterException::invalidArrtibuteType("mobile", "numericString", $mobile);
44
            }
45
        }
46
    }
47
    /**
48
     * This function for build country
49
     * @param int $category
50
     * @param string $key
51
     * @param array $buildSmsData
52
     *
53
     * @return array
54
     */
55
    public function buildCountry($category, $key, $buildSmsData, $xmlDoc)
56
    {
57
        if ($this->setCountry()) {
58
            $value = $this->getCountry();
59
            if ($this->isNumeric($value)) {
60
                $buildSmsData = $this->buildData($category, $key, $value, $buildSmsData, $xmlDoc);
61
                return $buildSmsData;
62
            } else {
63
                throw ParameterException::invalidArrtibuteType($key, "numeric", $value);
64
            }
65 12
        }
66
    }
67 12
    /**
68 12
     * This function for build flash
69 12
     * @param int $category
70 8
     * @param string $key
71 8
     * @param array $buildSmsData
72
     *
73 4
     * @return array
74
     */
75
    public function buildFlash($category, $key, $buildSmsData, $xmlDoc)
76
    {
77
        if ($this->setFlash()) {
78
            $value = $this->getFlash();
79
            $buildSmsData = $this->checkArrayValue($category, $key, $value, $buildSmsData, $xmlDoc);
80
        }
81
        return $buildSmsData;
82
    }
83
    /**
84
     * This function for build Unicode
85 4
     * @param int $category
86
     * @param string $key
87 4
     * @param array $buildSmsData
88 4
     *
89 4
     * @return array
90
     */
91
    public function buildUnicode($category, $key, $buildSmsData, $xmlDoc)
92
    {
93
        if ($this->setUnicode()) {
94
            $value = $this->getUnicode();
95
            $buildSmsData = $this->checkArrayValue($category, $key, $value, $buildSmsData, $xmlDoc);
96
        }
97
        return $buildSmsData;
98
    }
99
    /**
100
     * This function for build schtime
101 2
     * @param int $category
102
     * @param string $key
103 2
     * @param array $buildSmsData
104 2
     *
105 2
     * @return array
106
     */
107
    public function buildSchtime($category, $key, $buildSmsData, $xmlDoc)
108
    {
109
        if ($this->setSchtime()) {
110
            $value = $this->getSchtime();
111
            if ($this->isString($value) && $this->isVaildDateTime($value)) {
112
                $buildSmsData = $this->buildData($category, $key, $value, $buildSmsData, $xmlDoc);
113
                return $buildSmsData;
114
            } else {
115
                $message = "Allowed string value format like Y-m-d h:i:s Or Y/m/d h:i:s Or timestamp ";
116
                throw ParameterException::invalidInput($key, "string", $value, $message);
117 20
            }
118
        }
119 20
    }
120 20
    /**
121 20
     * This function for build sender
122
     * @param int $category
123
     * @param string $key
124
     * @param array $buildSmsData
125 20
     *
126 20
     * @return array
127
     */
128
    public function buildSmsSender($category, $key, $buildSmsData, $xmlDoc)
129
    {
130
        if ($this->setSender()) {
131
            $value = $this->getSender();
132
            $buildSmsData = $this->stringTypeCheckAndBuildData($category, $key, $value, $buildSmsData, $xmlDoc);
133
        }
134
        return $buildSmsData;
135
    }
136
    /**
137
     * This function for build afterminutes
138 58
     * @param int $category
139
     * @param string $key
140 58
     * @param array $buildSmsData
141 58
     *
142 58
     * @return array
143
     */
144 48
    public function buildAfterMinutes($category, $key, $buildSmsData)
145
    {
146
        if ($this->setAfterminutes()) {
147
            $value = $this->getAfterminutes();
148
            $buildSmsData = $this->simplifyAfterMinutes($category, $key, $buildSmsData, $value);
149
        }
150
        return $buildSmsData;
151
    }
152
    /**
153
     * This function for build Message
154 8
     * @param int $category
155
     * @param string $key
156 8
     * @param array $buildSmsData
157 8
     *
158 8
     * @return array
159
     */
160
    public function buildMessage($category, $key, $buildSmsData, $xmlDoc)
161
    {
162
        if ($this->setMessage()) {
163
            $value = $this->getMessage();
164
            $buildSmsData = $this->stringTypeCheckAndBuildData($category, $key, $value, $buildSmsData, $xmlDoc);
165
        }
166
        return $buildSmsData;
167
    }
168
    /**
169
     * This function for build Response
170 72
     * @param int $category
171
     * @param string $key
172 72
     * @param array $buildSmsData
173 72
     *
174 72
     * @return array
175
     */
176 62
    public function buildResponse($category, $key, $buildSmsData)
177
    {
178
        if ($this->setResponse()) {
179
            $value = $this->getResponse();
180
            $buildSmsData = $this->stringTypeCheckAndBuildData($category, $key, $value, $buildSmsData);
181
        }
182
        return $buildSmsData;
183
    }
184
    /**
185
     * This function for build Authkey
186 6
     * @param int $category
187
     * @param string $key
188 6
     * @param array $buildSmsData
189 6
     *
190 6
     * @return array
191
     */
192
    public function buildBulkAuth($category, $key, $buildSmsData, $xmlDoc)
193
    {
194
        if ($this->setAuthKey()) {
195
            $value = $this->getAuthKey();
196
            $buildSmsData = $this->stringTypeCheckAndBuildData($category, $key, $value, $buildSmsData, $xmlDoc);
197
        }
198
        return $buildSmsData;
199
    }
200
    /**
201
     * This function for build campaign
202
     * @param int $category
203
     * @param string $key
204
     * @param array $buildSmsData
205
     *
206
     * @return array
207
     */
208
    public function buildCampaign($category, $key, $buildSmsData, $xmlDoc)
209
    {
210
        if ($this->setCampaign()) {
211
            $value = $this->getCampaign();
212
            $buildSmsData = $this->stringTypeCheckAndBuildData($category, $key, $value, $buildSmsData, $xmlDoc);
213
        }
214
        return $buildSmsData;
215
    }
216
    /**
217
     * Add Content
218 4
     *
219
     *
220 4
     */
221 4
    public function addContent($root, $category, $xmlDoc)
222 4
    {
223
        if ($this->isKeyExists('content', $this->inputData) && $this->setContent()) {
224
            $bulkSms      = $this->getContent();
225
            $lenOfBulkSms = Validation::getSize($bulkSms);
226
            $this->checkContent($lenOfBulkSms, $bulkSms, $root, $category, $xmlDoc);
227
        } else {
228
            $message = "content Must be present";
229
            throw ParameterException::missinglogic($message);
230
        }
231
    }
232
    /**
233 10
     * This function for sms array Build with message
234
     * @param  array $buildSmsData
235 10
     *
236 10
     * @throws ParameterException missing parameters or return empty
237 10
     * @return array $buildSmsData
238 10
     */
239
    public function addMessage($buildSmsData, $category, $xmlDoc = null)
240
    {
241
        $result = $this->keyPresent('message');
242
        if ($result) {
0 ignored issues
show
introduced by
The condition $result can never be false.
Loading history...
243
            $buildSmsData = $this->buildMessage($category, 'message', $buildSmsData, $xmlDoc);
244
            return $buildSmsData;
245
        }
246
    }
247
    /**
248
     * This function for sms array Build with Authkey
249
     * @param  int $category
250
     *
251
     * @throws ParameterException missing parameters or type error
252
     * @return array $root
253
     *
254
     */
255
    public function addAuth($buildSmsData, $category, $xmlDoc = null)
256
    {
257
        $result = $this->keyPresent('authkey');
258
        if ($result) {
0 ignored issues
show
introduced by
The condition $result can never be false.
Loading history...
259
            $buildSmsData = $this->buildBulkAuth($category, 'authkey', $buildSmsData, $xmlDoc);
260
            return $buildSmsData;
261
        }
262
    }
263
    /**
264
     * This function for sms array Build with sender
265
     * @param  int $category
266
     *
267 80
     * @throws ParameterException missing parameters or type error
268
     * @return array $root
269 80
     *
270 72
     */
271 72
    public function addSender($buildSmsData, $category, $xmlDoc = null)
272 62
    {
273
        $result = $this->keyPresent('sender');
274
        if ($result) {
0 ignored issues
show
introduced by
The condition $result can never be false.
Loading history...
275
            $buildSmsData = $this->buildSmsSender($category, 'sender', $buildSmsData, $xmlDoc);
276
            return $buildSmsData;
277
        }
278
    }
279
    /**
280
     * This function for sms array build with country
281
     *
282
     * @throws ParameterException missing parameters or type error
283
     * @return array $root
284
     */
285
    public function addCountry($buildSmsData, $category, $xmlDoc = null)
286
    {
287
        if ($this->isKeyPresent('country')) {
288
            $buildSmsData = $this->buildCountry($category, 'country', $buildSmsData, $xmlDoc);
289
        }
290
        return $buildSmsData;
291
    }
292
    /**
293
     * This function for sms array build with flash
294
     *
295
     * @throws ParameterException missing parameters or type error
296
     * @return array $root
297
     *
298
     */
299
    public function addFlash($buildSmsData, $category, $xmlDoc = null)
300
    {
301
        if ($this->isKeyPresent('flash')) {
302
            $buildSmsData = $this->buildFlash($category, 'flash', $buildSmsData, $xmlDoc);
303
        }
304
        return $buildSmsData;
305 62
    }
306
    /**
307 62
     * This function for sms array build with flash
308 62
     *
309 58
     * @throws ParameterException missing parameters or type error
310 48
     * @return array $buildSmsData
311
     *
312 4
     */
313 4
    public function addUnicode($buildSmsData, $category, $xmlDoc = null)
314
    {
315
        if ($this->isKeyPresent('unicode')) {
316
            $buildSmsData = $this->buildUnicode($category, 'unicode', $buildSmsData, $xmlDoc);
317
        }
318
        return $buildSmsData;
319
    }
320
    /**
321
     * This function for sms array build with schtime
322 48
     * @param  int $category
323
     *
324 48
     * @throws ParameterException missing parameters or type error
325 12
     * @return array $root
326
     *
327 44
     */
328
    public function addSchtime($buildSmsData, $category, $xmlDoc = null)
329
    {
330
        if ($this->isKeyPresent('schtime')) {
331
            $buildSmsData = $this->buildSchtime($category, 'schtime', $buildSmsData, $xmlDoc);
332
        }
333
        return $buildSmsData;
334
    }
335
    /**
336 44
     * This function for sms array build with
337
     *
338 44
     * @throws ParameterException missing parameters or type error
339 4
     * @return array $buildSmsData
340
     *
341 40
     */
342
    public function addAfterMinutes($buildSmsData, $category)
343
    {
344
        if ($this->isKeyPresent('afterminutes')) {
345
            $buildSmsData = $this->buildAfterMinutes($category, 'afterminutes', $buildSmsData);
346
        }
347
        return $buildSmsData;
348
    }
349
    /**
350 40
     * This function for sms array build with Response
351
     *
352 40
     * @throws ParameterException missing parameters or type error
353 2
     * @return array $buildSmsData
354
     */
355 38
    public function addResponse($buildSmsData, $category)
356
    {
357
        if ($this->isKeyPresent('response')) {
358
            $buildSmsData = $this->buildResponse($category, 'response', $buildSmsData);
359
        }
360
        return $buildSmsData;
361
    }
362
    /**
363
     * This function for sms array build with campaign
364
     *
365 38
     * @throws ParameterException missing parameters or type error
366
     * @return array $root
367 38
     */
368 20
    public function addCampaign($buildSmsData, $category, $xmlDoc = null)
369
    {
370 18
        if ($this->isKeyPresent('campaign')) {
371
            $buildSmsData = $this->buildCampaign($category, 'campaign', $buildSmsData, $xmlDoc);
372
        }
373
        return $buildSmsData;
374
    }
375
}
376