Conversation
| ?int $numberCharacters = 1, | ||
| ?bool $strict = false, |
There was a problem hiding this comment.
Same comments as for uppercase.
| private function countLowerCase(string $message) :int { | ||
| $upperCase = strtoupper($message); | ||
| $similar = similar_text($message,$upperCase); | ||
| return strlen($message)-$similar; |
jwillp
left a comment
There was a problem hiding this comment.
Hi Mykhailo,
There are a few issues here to be looked at before I can merge.
This rule is not working as intended.
| ) | ||
| { | ||
| if($numberCharacters<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 validate($v): bool | ||
| { | ||
| if($this->strict){ | ||
| return $this->countLowerCase($v)<=$this->numberCharacters; |
There was a problem hiding this comment.
There is a mistake here actually.
Can you find it?
| return $this->message; | ||
| } | ||
| if($this->strict){ | ||
| return "Number of lowercase characters exceeds ".${$this->numberCharacters}; |
There was a problem hiding this comment.
The message here should be:
"The value '{$v}' should have exactly {$this->numberCharacters} lower cased characters"| if($this->strict){ | ||
| return "Number of lowercase characters exceeds ".${$this->numberCharacters}; | ||
| } | ||
| return "Number of lowercase characters should exceed ".${$this->numberCharacters}; |
There was a problem hiding this comment.
The message here should be:
"The value '{$v}' should have at least {$this->numberCharacters} lower cased characters"| $ruleFirst = new ContainsLowercaseCharacters(1,true); | ||
| $ruleSecond = new ContainsLowercaseCharacters(1,false); | ||
| $ruleThird= new ContainsLowercaseCharacters(1,false,"Custom Message"); |
There was a problem hiding this comment.
It would be better to test using different number of character values.
The value 1 here causes some false positives.
| int $numberCharacters, | ||
| bool $strict, |
There was a problem hiding this comment.
Could you also set the default parameter values I had provided in the issue?
No description provided.