PromotionalSms::sendBulkSms()   B
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 15
nc 3
nop 1
dl 0
loc 19
ccs 0
cts 13
cp 0
crap 30
rs 8.8571
c 0
b 0
f 0
1
<?php
2
namespace Sender;
3
4
use Sender\Sms\SmsBulk;
5
use Sender\Sms\SmsNormal;
6
use Sender\Config\Config as ConfigClass;
7
use Sender\ExceptionClass\ParameterException;
8
9
/**
10
 * This Class provide Promotional SMS APIs
11
 *
12
 * @package    Sender\PromotionalSms
13
 * @author     VenkatS <[email protected]>
14
 * @link       https://github.com/tesark/msg91-php
15
 * @license    MIT
16
 */
17
18
class PromotionalSms
19
{
20
    /**
21
     * @var string $promoAuthKey
22
     */
23
    protected $promoAuthKey;
24 40
    public function __construct($authkey = null)
25
    {
26 40
        $this->promoAuthKey = $authkey;
27 40
    }
28
    /**
29
     * Send promotional SMS MSG91 Service
30
     * @param  string $mobileNumber
31
     * @param  array  $data
32
     *
33
     * @return string
34
     */
35 40
    public function sendPromotional($mobileNumber, $data)
36
    {
37 40
        $sms = new SmsNormal();
38 40
        $promoAuthKey = $this->promoAuthKey;
39 40
        $data['mobile'] = $mobileNumber;
40 40
        $response = $sms->smsCategory($data, 0, $promoAuthKey);
41
        return $response;
42
    }
43
44
    /**
45
     * Send Bulk promotional SMS MSG91 Service
46
     * @param array $data
47
     *
48
     * @throws ParameterException missing parameters or return empty
49
     * @return string
50
     */
51
    public function sendBulkSms($data)
52
    {
53
        if (is_array($data)) {
0 ignored issues
show
introduced by
The condition is_array($data) can never be false.
Loading history...
54
            $response = null;
55
            $arrayLength = sizeof($data);
56
            if (isset($arrayLength) && $arrayLength == 1) {
57
                $currentArray = $data[0];
58
                $sms          = new SmsBulk();
59
                $response     = $sms->buildAndSendXmlSms($currentArray);
60
            } else {
61
                for ($i = 0; $i < $arrayLength; $i++) {
62
                    $currentArray = $data[$i];
63
                    $sms          = new SmsBulk();
64
                    $response     = $sms->buildAndSendXmlSms($currentArray);
65
                }
66
            }
67
            return $response;
68
        } else {
69
            throw ParameterException::missinglogic("Check parameter is must be array.");
70
        }
71
    }
72
}
73