66use Sms77 \Api \Exception \InvalidBooleanOptionException ;
77use Sms77 \Api \Exception \InvalidOptionalArgumentException ;
88use Sms77 \Api \Exception \InvalidRequiredArgumentException ;
9- use Sms77 \Api \Params \SmsParamsInterface ;
109use Sms77 \Api \Library \Util ;
10+ use Sms77 \Api \Params \SmsParamsInterface ;
1111
1212class SmsValidator extends BaseValidator implements ValidatorInterface {
1313 /* @var SmsParamsInterface $params */
@@ -50,7 +50,7 @@ public function validate(): void {
5050 public function delay (): void {
5151 $ delay = $ this ->params ->getDelay ();
5252
53- if (null === $ delay ) {
53+ if (null === $ delay || '' === $ delay ) {
5454 return ;
5555 }
5656
@@ -70,7 +70,7 @@ public function delay(): void {
7070 public function foreign_id (): void {
7171 $ foreignId = $ this ->params ->getForeignId ();
7272
73- if (null === $ foreignId ) {
73+ if (null === $ foreignId || '' === $ foreignId ) {
7474 return ;
7575 }
7676
@@ -91,7 +91,7 @@ public function foreign_id(): void {
9191 public function from (): void {
9292 $ from = $ this ->params ->getFrom ();
9393
94- if (null === $ from ) {
94+ if (null === $ from || '' === $ from ) {
9595 return ;
9696 }
9797
@@ -123,7 +123,7 @@ public function from(): void {
123123 public function label (): void {
124124 $ label = $ this ->params ->getLabel ();
125125
126- if (null === $ label ) {
126+ if (null === $ label || '' === $ label ) {
127127 return ;
128128 }
129129
@@ -161,7 +161,9 @@ public function text(): void {
161161
162162 /** @throws InvalidRequiredArgumentException */
163163 public function to (): void {
164- if (null === $ this ->params ->getTo ()) {
164+ $ to = $ this ->params ->getTo ();
165+
166+ if (null === $ to || '' === $ to ) {
165167 throw new InvalidRequiredArgumentException (
166168 'You cannot send a message without specifying a recipient. ' );
167169 }
@@ -171,19 +173,26 @@ public function to(): void {
171173 public function ttl (): void {
172174 $ ttl = $ this ->params ->getTtl ();
173175
174- if (null ! == $ ttl ) {
175- $ min = SmsConstants:: TTL_MIN ;
176- $ max = SmsConstants:: TTL_MAX ;
176+ if (null = == $ ttl ) {
177+ return ;
178+ }
177179
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+ }
182184
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. " );
187196 }
188197 }
189198}
0 commit comments