Conversation
jwillp
left a comment
There was a problem hiding this comment.
Thank you, Mykhailo, see my comments
| private $length; | ||
|
|
||
| public function __construct(int $length) | ||
| /** |
There was a problem hiding this comment.
This file should not be part of the PR.
Although seeing, this it makes me think that a negative integer should not be passed to the function, but it is currently possible.
Could you make it throw an InvalidArgumentException in that case?
| { | ||
| public function testValidate() | ||
| { | ||
| $firstRule = new MaxLength(5); |
There was a problem hiding this comment.
According to my other comment with a negative value, it would require a test that makes sure the exception is thrown.
| ) | ||
| { | ||
| if($length<0) | ||
| throw new InvalidArgumentException(); |
There was a problem hiding this comment.
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.
| ) | ||
| { | ||
| if($minLength<0) | ||
| throw new InvalidArgumentException(); |
There was a problem hiding this comment.
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.
| */ | ||
| public function getMessage($v): string | ||
| { | ||
| return $this->message?:"'${$v}' is supposed to be at least ".$this->minLength." characters long."; |
There was a problem hiding this comment.
Can you change the message to:
"'The value '{$v}' was expected to be at least {$this->minLength} characters long."
No description provided.