Skip to content

Commit 51f84a3

Browse files
committed
SmsValidator: refactored logic for method from()
1 parent 503dd31 commit 51f84a3

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/Validator/SmsValidator.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,12 @@ function flash()
104104

105105
if (null !== $flash) {
106106
if (!$this->isValidBool($flash)) {
107-
throw new InvalidOptionalArgumentException("flash can be either 1 or 0.");
107+
throw new InvalidOptionalArgumentException("Argument 'flash' can be either 1 or 0.");
108108
}
109109

110110
if ("direct" != $this->parameters["type"] && $flash) {
111-
throw new InvalidOptionalArgumentException("Only messages of type direct can be sent as flash messages.");
111+
throw new InvalidOptionalArgumentException(
112+
"Only messages of type 'direct' can be sent as 'flash' messages.");
112113
}
113114

114115
}
@@ -127,15 +128,16 @@ function from()
127128
$isNumeric = is_numeric($from);
128129

129130
if ($length > $numericMax) {
130-
throw new InvalidOptionalArgumentException("from is too long as it exceeds $numericMax characters.");
131+
throw new InvalidOptionalArgumentException("Argument 'from' may not exceed $numericMax chars.");
131132
}
132133

133-
if ($length > $alphaNumericMax) {
134-
if (!$isNumeric) {
135-
throw new InvalidOptionalArgumentException("from longer than $alphaNumericMax characters must be numeric.");
136-
}
137-
} elseif (!$isNumeric || !ctype_alnum($from)) {
138-
throw new InvalidOptionalArgumentException("from does not seem to be a valid sender.");
134+
if ($length > $alphaNumericMax && !$isNumeric) {
135+
throw new InvalidOptionalArgumentException(
136+
"Argument 'from' must be numeric. if > $alphaNumericMax chars.");
137+
}
138+
139+
if (!ctype_alnum($from)) {
140+
throw new InvalidOptionalArgumentException("Argument 'from' must be alphanumeric.");
139141
}
140142
}
141143
}

0 commit comments

Comments
 (0)