6
6
use Sms77 \Api \Exception \InvalidBooleanOptionException ;
7
7
use Sms77 \Api \Exception \InvalidOptionalArgumentException ;
8
8
use Sms77 \Api \Exception \InvalidRequiredArgumentException ;
9
- use Sms77 \Api \Params \SmsParamsInterface ;
10
9
use Sms77 \Api \Library \Util ;
10
+ use Sms77 \Api \Params \SmsParamsInterface ;
11
11
12
12
class SmsValidator extends BaseValidator implements ValidatorInterface {
13
13
/* @var SmsParamsInterface $params */
@@ -50,7 +50,7 @@ public function validate(): void {
50
50
public function delay (): void {
51
51
$ delay = $ this ->params ->getDelay ();
52
52
53
- if (null === $ delay ) {
53
+ if (null === $ delay || '' === $ delay ) {
54
54
return ;
55
55
}
56
56
@@ -70,7 +70,7 @@ public function delay(): void {
70
70
public function foreign_id (): void {
71
71
$ foreignId = $ this ->params ->getForeignId ();
72
72
73
- if (null === $ foreignId ) {
73
+ if (null === $ foreignId || '' === $ foreignId ) {
74
74
return ;
75
75
}
76
76
@@ -91,7 +91,7 @@ public function foreign_id(): void {
91
91
public function from (): void {
92
92
$ from = $ this ->params ->getFrom ();
93
93
94
- if (null === $ from ) {
94
+ if (null === $ from || '' === $ from ) {
95
95
return ;
96
96
}
97
97
@@ -123,7 +123,7 @@ public function from(): void {
123
123
public function label (): void {
124
124
$ label = $ this ->params ->getLabel ();
125
125
126
- if (null === $ label ) {
126
+ if (null === $ label || '' === $ label ) {
127
127
return ;
128
128
}
129
129
@@ -161,7 +161,9 @@ public function text(): void {
161
161
162
162
/** @throws InvalidRequiredArgumentException */
163
163
public function to (): void {
164
- if (null === $ this ->params ->getTo ()) {
164
+ $ to = $ this ->params ->getTo ();
165
+
166
+ if (null === $ to || '' === $ to ) {
165
167
throw new InvalidRequiredArgumentException (
166
168
'You cannot send a message without specifying a recipient. ' );
167
169
}
@@ -171,19 +173,26 @@ public function to(): void {
171
173
public function ttl (): void {
172
174
$ ttl = $ this ->params ->getTtl ();
173
175
174
- if (null ! == $ ttl ) {
175
- $ min = SmsConstants:: TTL_MIN ;
176
- $ max = SmsConstants:: TTL_MAX ;
176
+ if (null = == $ ttl ) {
177
+ return ;
178
+ }
177
179
178
- if ($ ttl < $ min ) {
179
- throw new InvalidOptionalArgumentException (
180
- " ttl must be at least $ min . " ) ;
181
- }
180
+ if (0 === $ ttl ) {
181
+ $ this -> params -> setTtl ( null );
182
+ return ;
183
+ }
182
184
183
- if ($ ttl > $ max ) {
184
- throw new InvalidOptionalArgumentException (
185
- "ttl may not exceed $ max. " );
186
- }
185
+ $ min = SmsConstants::TTL_MIN ;
186
+ $ max = SmsConstants::TTL_MAX ;
187
+
188
+ if ($ ttl < $ min ) {
189
+ throw new InvalidOptionalArgumentException (
190
+ "ttl must be at least $ min. " );
191
+ }
192
+
193
+ if ($ ttl > $ max ) {
194
+ throw new InvalidOptionalArgumentException (
195
+ "ttl may not exceed $ max. " );
187
196
}
188
197
}
189
198
}
0 commit comments