-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Length rule #24
base: dev
Are you sure you want to change the base?
Length rule #24
Conversation
*/ | ||
public function validate($v): bool | ||
{ | ||
return strlen($v) == $this->length; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In PHP, it is a best practice to test with a strict comparison: !== and ===
*/ | ||
public function getMessage($v): string | ||
{ | ||
return $this->message?:"'${$v}' is supposed to be exactly ".$this->length." characters long"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change supposed to 'expected'?
) | ||
{ | ||
if($length <0) | ||
throw new InvalidArgumentException(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When throwing an exception, a message should always be provided in order to inform the user why the exception was thrown without needing to look at the source code.
No description provided.