Skip to content

Conversation

@mboiev
Copy link
Contributor

@mboiev mboiev commented Mar 6, 2020

No description provided.

@mboiev mboiev changed the title Contains uppercase characters Contains uppercase characters rule Mar 6, 2020
* @param string|null $message
*/
public function __construct(
?int $numberCharacters = 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you validate that numberCharacters is a positive integer or zero?
Also, why did you make it accept null?

*/
public function __construct(
?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.

Why did you make it accept null?

if($this->message){
return $this->message;
}
else if($this->strict){
Copy link
Contributor

Choose a reason for hiding this comment

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

The conditional workflows rely on return statements.
No neeed for else and elseif -> change to if, if, return

Comment on lines +80 to +82
$lowerCase = strtolower($message);
$similar = similar_text($message, $lowerCase);
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! :)

@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,
Please correct the issues I have mentioned in the comments.

Comment on lines +32 to +34
int $numberCharacters,
bool $strict,
?string $message = null
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?

)
{
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->countUpperCase($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 an error here. Can you find it?

return $this->message;
}
if($this->strict){
return "Number of uppercase 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} upper cased characters"

if($this->strict){
return "Number of uppercase characters exceeds ".${$this->numberCharacters};
}
return "Number of uppercase 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 ContainsUppercaseCharacters(1,true);
$ruleSecond = new ContainsUppercaseCharacters(1,false);
$ruleThird= new ContainsUppercaseCharacters(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 use different values for number of characters in the tests.
The value 1 causes some false positives here.

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