Skip to content
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

Contains lowercase characters rule #21

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from

Conversation

mboiev
Copy link
Collaborator

@mboiev mboiev commented Mar 6, 2020

No description provided.

Comment on lines 32 to 33
?int $numberCharacters = 1,
?bool $strict = false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as for uppercase.

Comment on lines +79 to +82
private function countLowerCase(string $message) :int {
$upperCase = strtoupper($message);
$similar = similar_text($message,$upperCase);
return strlen($message)-$similar;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice solution again :)

@jwillp jwillp linked an issue Mar 8, 2020 that may be closed by this pull request
Copy link
Contributor

@jwillp jwillp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Contributor

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

public function validate($v): bool
{
if($this->strict){
return $this->countLowerCase($v)<=$this->numberCharacters;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a mistake here actually.
Can you find it?

return $this->message;
}
if($this->strict){
return "Number of lowercase characters exceeds ".${$this->numberCharacters};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message here should be:

"The value '{$v}' should have at least {$this->numberCharacters} lower cased characters"

Comment on lines +12 to +14
$ruleFirst = new ContainsLowercaseCharacters(1,true);
$ruleSecond = new ContainsLowercaseCharacters(1,false);
$ruleThird= new ContainsLowercaseCharacters(1,false,"Custom Message");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to test using different number of character values.
The value 1 here causes some false positives.

Comment on lines +33 to +34
int $numberCharacters,
bool $strict,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also set the default parameter values I had provided in the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Password checking related validation rules
2 participants