SmsBuildTrait::checkContent()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 11
nc 3
nop 5
dl 0
loc 15
ccs 0
cts 9
cp 0
crap 20
rs 9.2
c 0
b 0
f 0
1
<?php
2
namespace Sender\Traits;
3
4
use Sender\Validation;
5
use Sender\MobileNumber;
6
use Sender\Sms\SmsDefineClass;
7
use Sender\Sms\SmsBuildClass;
8
use Sender\ExceptionClass\ParameterException;
9
10
/**
11
 * This trait for SMS OTP FUNCTIONS
12
 *
13
 * @package    Msg91 SMS&OTP package
14
 * @author     VenkatS <[email protected]>
15
 * @link       https://github.com/tesark/msg91-php
16
 * @license    MIT
17
 */
18
19
trait SmsBuildTrait
20
{
21
    protected $inputData;
22
    /**
23
     * This function for Check String Type
24
     * @param int $category
25
     * @param string $key
26
     * @param array $buildSmsData
27
     *
28 66
     */
29
    public function buildStringData($category, $key, $value, $buildSmsData, $xmlDoc)
30 66
    {
31 66
        $buildSmsData = $this->checkAuthCampaignData($category, $key, $value, $buildSmsData, $xmlDoc);
32 66
        $buildSmsData = $this->checkSenderData($category, $key, $value, $buildSmsData, $xmlDoc);
33 62
        $buildSmsData = $this->checkMessageData($category, $key, $value, $buildSmsData, $xmlDoc);
34 62
        $buildSmsData = $this->checkResponseData($category, $key, $value, $buildSmsData);
35
        return $buildSmsData;
36
    }
37
    /**
38
     * This function for Check String Type
39
     * @param int $category
40
     * @param string $key
41
     * @param array $buildSmsData
42
     *
43 66
     */
44
    public function checkSenderData($category, $key, $value, $buildSmsData, $xmlDoc)
45 66
    {
46 52
        if ($key === 'sender') {
47
            $buildSmsData = $this->validLength($key, $value, $buildSmsData, 'sms', $category, $xmlDoc);
0 ignored issues
show
Bug introduced by
It seems like validLength() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

47
            /** @scrutinizer ignore-call */ 
48
            $buildSmsData = $this->validLength($key, $value, $buildSmsData, 'sms', $category, $xmlDoc);
Loading history...
48 66
        }
49
        return $buildSmsData;
50
    }
51
    /**
52
     * This function for Check String Type
53
     * @param int $category
54
     * @param string $key
55
     * @param array $buildSmsData
56
     *
57 66
     */
58
    public function checkAuthCampaignData($category, $key, $value, $buildSmsData, $xmlDoc)
59 66
    {
60
        if ($key === 'authkey' || $key === 'campaign') {
61
            $buildSmsData = $this->buildData($category, $key, $value, $buildSmsData, $xmlDoc);
0 ignored issues
show
Bug introduced by
It seems like buildData() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
            /** @scrutinizer ignore-call */ 
62
            $buildSmsData = $this->buildData($category, $key, $value, $buildSmsData, $xmlDoc);
Loading history...
62 66
        }
63
        return $buildSmsData;
64
    }
65
    /**
66
     * This function for Check String Type
67
     * @param int $category
68
     * @param string $key
69
     * @param array $buildSmsData
70
     *
71 66
     */
72
    public function checkMessageData($category, $key, $value, $buildSmsData, $xmlDoc)
73 66
    {
74 66
        if ($key === 'message') {
75
            $buildSmsData = $this->messageCondition($category, $key, $buildSmsData, $value, $xmlDoc);
76 62
        }
77
        return $buildSmsData;
78
    }
79
    /**
80
     * Message condition Check
81
     * @param int $category
82
     * @param string $key
83
     * @param array $buildSmsData
84
     * @param int $value
85
     *
86
     * @return array
87 66
     */
88
    public function messageCondition($category, $key, $buildSmsData, $value, $xmlDoc)
89 66
    {
90 62
        if (!$this->isKeyExists('unicode', $this->inputData)) {
0 ignored issues
show
Bug introduced by
It seems like isKeyExists() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

90
        if (!$this->/** @scrutinizer ignore-call */ isKeyExists('unicode', $this->inputData)) {
Loading history...
91 4
            $buildSmsData = $this->checkMessageLength($key, $buildSmsData, 160, $value, $category, $xmlDoc);
0 ignored issues
show
Bug introduced by
The method checkMessageLength() does not exist on Sender\Traits\SmsBuildTrait. Did you maybe mean checkMessageData()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

91
            /** @scrutinizer ignore-call */ 
92
            $buildSmsData = $this->checkMessageLength($key, $buildSmsData, 160, $value, $category, $xmlDoc);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
92 4
        } elseif ($this->isKeyExists('unicode', $this->inputData)) {
93
            $buildSmsData = $this->checkMessageLength($key, $buildSmsData, 70, $value, $category, $xmlDoc);
94 62
        }
95
        return $buildSmsData;
96
    }
97
    /**
98
     * This function for Check String Type
99
     * @param int $category
100
     * @param string $key
101
     * @param array $buildSmsData
102
     *
103 62
     */
104
    public function checkResponseData($category, $key, $value, $buildSmsData)
105 62
    {
106
        if ($key === 'response') {
107
            $value = $this->checkResponse($value);
0 ignored issues
show
Bug introduced by
The method checkResponse() does not exist on Sender\Traits\SmsBuildTrait. Did you maybe mean checkResponseData()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

107
            /** @scrutinizer ignore-call */ 
108
            $value = $this->checkResponse($value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
108
            $buildSmsData = $this->buildData($category, $key, $value, $buildSmsData);
109 62
        }
110
        return $buildSmsData;
111
    }
112
    /**
113
     * This function check the content length
114
     *
115
     *
116
     */
117
    public function checkContent($lenOfBulkSms, $bulkSms, $root, $category, $xmlDoc)
118
    {
119
        for ($j = 0; $j < $lenOfBulkSms; $j++) {
120
            $currentData = $bulkSms[$j];
121
            if (array_key_exists('message', $currentData) && array_key_exists('mobile', $currentData)) {
122
                $this->inputData['message'] = $currentData['message'];
123
                $this->inputData['mobile'] = $currentData['mobile'];
124
                $smsTag = $this->createElement($xmlDoc, "SMS", $root);
125
                //check message length
126
                $smsTag = $this->buildMessage($category, 'message', $smsTag, $xmlDoc);
0 ignored issues
show
Bug introduced by
It seems like buildMessage() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

126
                /** @scrutinizer ignore-call */ 
127
                $smsTag = $this->buildMessage($category, 'message', $smsTag, $xmlDoc);
Loading history...
127
                //check mobile contents
128
                $this->addMobileNumber($xmlDoc, $smsTag);
0 ignored issues
show
Bug introduced by
It seems like addMobileNumber() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

128
                $this->/** @scrutinizer ignore-call */ 
129
                       addMobileNumber($xmlDoc, $smsTag);
Loading history...
129
            } else {
130
                $message = "parameters authkey or message missing";
131
                throw ParameterException::missinglogic($message);
132
            }
133
        }
134
    }
135
    /**
136
     * This function Create Element only
137
     * @param string $element
138
     * @param array $root
139
     *
140
     * @return array
141
     */
142
    public function createElement($xmlDoc, $element, $root = null)
143
    {
144
        if (is_null($root)) {
145
            $root = $xmlDoc->appendChild($xmlDoc->createElement($element));
146
        } else {
147
            $root = $root->appendChild($xmlDoc->createElement($element));
148
        }
149
        return $root;
150
    }
151
    /**
152
     * This function for Check String Type
153
     * @param int $category
154
     * @param string $key
155 72
     * @param array $buildSmsData
156
     *
157 72
     */
158 66
    public function stringTypeCheckAndBuildData($category, $key, $value, $buildSmsData, $xmlDoc = null)
159 62
    {
160
        if ($this->isString($value)) {
0 ignored issues
show
Bug introduced by
It seems like isString() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

160
        if ($this->/** @scrutinizer ignore-call */ isString($value)) {
Loading history...
161 22
            $buildSmsData = $this->buildStringData($category, $key, $value, $buildSmsData, $xmlDoc);
162 22
            return $buildSmsData;
163
        } else {
164
            $message = "string values only accept";
165
            throw ParameterException::invalidInput($key, "string", $value, $message);
166
        }
167
    }
168
    /**
169
     * This function used for Array inside present 0 or 1
170
     * @param int $category
171
     * @param string $key
172 6
     * @param array $buildSmsData
173
     *
174 6
     */
175 6
    public function checkArrayValue($category, $key, $value, $buildSmsData, $xmlDoc)
176
    {
177
        $value = $this->checkArray($value);
0 ignored issues
show
Bug introduced by
The method checkArray() does not exist on Sender\Traits\SmsBuildTrait. Did you maybe mean checkArrayValue()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

177
        /** @scrutinizer ignore-call */ 
178
        $value = $this->checkArray($value);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
178
        if (!is_null($value)) {
179 6
            $buildSmsData = $this->buildData($category, $key, $value, $buildSmsData, $xmlDoc);
180 6
            return $buildSmsData;
181
        } else {
182
            $message = "Allowed only 0 or 1";
183
            throw ParameterException::invalidInput($key, "int", $value, $message);
184
        }
185
    }
186
    
187
    /**
188
     * This function for sms array Build with mobilenumbers
189
     * @param string $key
190
     * @param array $buildSmsData
191
     * @param int $category
192
     *
193 80
     * @throws ParameterException missing parameters or return empty
194
     * @return array
195 80
     */
196 70
    public function checkIntegerOrString($key, $value, $buildSmsData, $category)
197 10
    {
198 10
        if ($this->isInterger($value)) {
0 ignored issues
show
Bug introduced by
It seems like isInterger() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

198
        if ($this->/** @scrutinizer ignore-call */ isInterger($value)) {
Loading history...
199
            $buildSmsData = $this->buildData($category, $key, $value, $buildSmsData);
200
        } elseif ($this->isString($value)) {
201
            $buildSmsData = $this->buildMobile($key, $value, $buildSmsData, $category);
202
        } else {
203 80
            $message = "interger or string comma seperate values";
204
            throw ParameterException::invalidInput($key, "string or integer", $value, $message);
205
        }
206
        return $buildSmsData;
207
    }
208
    /**
209
     * This function for sms array Build with mobilenumbers
210
     * @param  array $buildSmsData
211
     *
212
     *
213
     * @return array
214
     */
215
    public function buildMobile($key, $value, $buildSmsData, $category)
216
    {
217
        $result = $this->isValidNumber($value);
0 ignored issues
show
Bug introduced by
It seems like isValidNumber() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

217
        /** @scrutinizer ignore-call */ 
218
        $result = $this->isValidNumber($value);
Loading history...
218
        if (!empty($result) && $result['value'] == true) {
219
            $buildSmsData = $this->buildData($category, $key, $value, $buildSmsData);
220
            return $buildSmsData;
221
        } else {
222
            $message = "this number not the correct:_".$result['mobile'];
223
            throw ParameterException::invalidInput("mobiles", "string", $value, $message);
224
        }
225
    }
226
}
227