55use Sms77 \Api \Exception \InvalidOptionalArgumentException ;
66use Sms77 \Api \Exception \InvalidRequiredArgumentException ;
77
8- class SmsValidator extends BaseValidator implements ValidatorInterface
9- {
10- public function validate ()
11- {
8+ class SmsValidator extends BaseValidator implements ValidatorInterface {
9+ public function validate () {
1210 $ this ->debug ();
1311 $ this ->delay ();
1412 $ this ->details ();
@@ -28,17 +26,15 @@ public function validate()
2826 $ this ->ttl ();
2927 }
3028
31- public function debug ()
32- {
29+ public function debug () {
3330 $ debug = isset ($ this ->parameters ['debug ' ]) ? $ this ->parameters ['debug ' ] : null ;
3431
3532 if ((null !== $ debug ) && !$ this ->isValidBool ($ debug )) {
3633 throw new InvalidOptionalArgumentException ('debug can be either 1 or 0. ' );
3734 }
3835 }
3936
40- public function delay ()
41- {
37+ public function delay () {
4238 $ delay = isset ($ this ->parameters ['delay ' ]) ? $ this ->parameters ['delay ' ] : null ;
4339
4440 if (null !== $ delay ) {
@@ -48,31 +44,31 @@ public function delay()
4844
4945 if (false === strpos ($ delay , '- ' )) {
5046 if (!$ this ->isValidUnixTimestamp ($ delay )) {
51- throw new InvalidOptionalArgumentException ("Delay must be a valid UNIX timestamp or in the format of $ dateFormat. " );
47+ throw new InvalidOptionalArgumentException (
48+ "Delay must be a valid UNIX timestamp or in the format of $ dateFormat. " );
5249 }
5350 } else {
5451 if (!preg_match ('/^([0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$/ ' , $ hour . ': ' . $ min )) {
5552 throw new InvalidOptionalArgumentException ('date seems to have an invalid format. ' );
5653 }
5754
5855 if (!checkdate ($ month , $ day , $ year )) {
59- throw new InvalidOptionalArgumentException ("Delay must be a valid UNIX timestamp or in the format of $ dateFormat. " );
56+ throw new InvalidOptionalArgumentException (
57+ "Delay must be a valid UNIX timestamp or in the format of $ dateFormat. " );
6058 }
6159 }
6260 }
6361 }
6462
65- public function details ()
66- {
63+ public function details () {
6764 $ details = isset ($ this ->parameters ['details ' ]) ? $ this ->parameters ['details ' ] : null ;
6865
6966 if (null !== $ details && !$ this ->isValidBool ($ details )) {
7067 throw new InvalidOptionalArgumentException ('details can be either 1 or 0. ' );
7168 }
7269 }
7370
74- public function label ()
75- {
71+ public function label () {
7672 //TODO: max length?! there must be one.
7773
7874 $ label = isset ($ this ->parameters ['label ' ]) ? $ this ->parameters ['label ' ] : null ;
@@ -86,8 +82,7 @@ public function label()
8682 }
8783 }
8884
89- public function flash ()
90- {
85+ public function flash () {
9186 $ flash = isset ($ this ->parameters ['flash ' ]) ? $ this ->parameters ['flash ' ] : null ;
9287
9388 if (null !== $ flash ) {
@@ -103,8 +98,7 @@ public function flash()
10398 }
10499 }
105100
106- public function from ()
107- {
101+ public function from () {
108102 $ from = isset ($ this ->parameters ['from ' ]) ? $ this ->parameters ['from ' ] : null ;
109103
110104 if (null !== $ from ) {
@@ -124,50 +118,47 @@ public function from()
124118 "Argument 'from' must be numeric. if > $ alphaNumericMax chars. " );
125119 }
126120
127- if (!ctype_alnum ($ from )) {
121+ $ allowedSpecialChars = ['/ ' , ' ' , '. ' , '- ' , '@ ' , '_ ' , '! ' , '( ' , ') ' , '+ ' , '$ ' , ', ' , '& ' ,];
122+ if (!ctype_alnum (str_ireplace ($ allowedSpecialChars , '' , $ from ))) {
128123 throw new InvalidOptionalArgumentException ("Argument 'from' must be alphanumeric. " );
129124 }
130125 }
131126 }
132127
133- public function json ()
134- {
128+ public function json () {
135129 $ json = isset ($ this ->parameters ['json ' ]) ? $ this ->parameters ['json ' ] : null ;
136130
137131 if ((null !== $ json ) && !$ this ->isValidBool ($ json )) {
138132 throw new InvalidOptionalArgumentException ('json can be either 1 or 0. ' );
139133 }
140134 }
141135
142- public function no_reload ()
143- {
136+ public function no_reload () {
144137 $ noReload = isset ($ this ->parameters ['no_reload ' ]) ? $ this ->parameters ['no_reload ' ] : null ;
145138
146139 if ((null !== $ noReload ) && !$ this ->isValidBool ($ noReload )) {
147140 throw new InvalidOptionalArgumentException ('no_reload can be either 1 or 0. ' );
148141 }
149142 }
150143
151- public function performance_tracking ()
152- {
153- $ performanceTracking = isset ($ this ->parameters ['performance_tracking ' ]) ? $ this ->parameters ['performance_tracking ' ] : null ;
144+ public function performance_tracking () {
145+ $ performanceTracking =
146+ isset ($ this ->parameters ['performance_tracking ' ]) ? $ this ->parameters ['performance_tracking ' ] : null ;
154147
155148 if ((null !== $ performanceTracking ) && !$ this ->isValidBool ($ performanceTracking )) {
156149 throw new InvalidOptionalArgumentException ('performance_tracking can be either 1 or 0. ' );
157150 }
158151 }
159152
160- public function return_msg_id ()
161- {
153+ public function return_msg_id () {
162154 $ returnMsgId = isset ($ this ->parameters ['return_msg_id ' ]) ? $ this ->parameters ['return_msg_id ' ] : null ;
163155
164156 if ((null !== $ returnMsgId ) && !$ this ->isValidBool ($ returnMsgId )) {
165157 throw new InvalidOptionalArgumentException ('return_msg_id can be either 1 or 0. ' );
166158 }
167159 }
168160
169- public function text ()
170- {
161+ public function text () {
171162 $ text = isset ($ this ->parameters ['text ' ]) ? $ this ->parameters ['text ' ] : null ;
172163
173164 if (null === $ text ) {
@@ -183,21 +174,21 @@ public function text()
183174 $ maxTextLength = 1520 ;
184175
185176 if ($ maxTextLength < $ length ) {
186- throw new InvalidRequiredArgumentException ("The text can not be longer than $ maxTextLength characters. " );
177+ throw new InvalidRequiredArgumentException (
178+ "The text can not be longer than $ maxTextLength characters. " );
187179 }
188180 }
189181
190- public function to ()
191- {
182+ public function to () {
192183 $ to = isset ($ this ->parameters ['to ' ]) ? $ this ->parameters ['to ' ] : null ;
193184
194185 if (null === $ to ) {
195- throw new InvalidRequiredArgumentException ('You cannot send a message without specifying a recipient. ' );
186+ throw new InvalidRequiredArgumentException (
187+ 'You cannot send a message without specifying a recipient. ' );
196188 }
197189 }
198190
199- public function ttl ()
200- {
191+ public function ttl () {
201192 $ ttl = isset ($ this ->parameters ['ttl ' ]) ? $ this ->parameters ['ttl ' ] : null ;
202193
203194 if (null !== $ ttl ) {
@@ -214,13 +205,11 @@ public function ttl()
214205 }
215206 }
216207
217- public function type ()
218- {
208+ public function type () {
219209 $ this ->throwOnOptionalBadType ();
220210 }
221211
222- public function udh ()
223- {
212+ public function udh () {
224213 $ udh = isset ($ this ->parameters ['udh ' ]) ? $ this ->parameters ['udh ' ] : null ;
225214
226215 if (null !== $ udh ) {
@@ -234,8 +223,7 @@ public function udh()
234223 }
235224 }
236225
237- public function unicode ()
238- {
226+ public function unicode () {
239227 $ unicode = isset ($ this ->parameters ['unicode ' ]) ? $ this ->parameters ['unicode ' ] : null ;
240228
241229 if (null !== $ unicode ) {
@@ -249,8 +237,7 @@ public function unicode()
249237 }
250238 }
251239
252- public function utf8 ()
253- {
240+ public function utf8 () {
254241 $ utf8 = isset ($ this ->parameters ['utf8 ' ]) ? $ this ->parameters ['utf8 ' ] : null ;
255242
256243 if ((null !== $ utf8 ) && !$ this ->isValidBool ($ utf8 )) {
0 commit comments