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

Min length rule #25

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

Min length rule #25

wants to merge 6 commits into from

Conversation

mboiev
Copy link
Collaborator

@mboiev mboiev commented Mar 6, 2020

No description provided.

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.

Thank you, Mykhailo, see my comments

@@ -13,9 +13,18 @@ class MaxLength implements ValidationRuleInterface
*/
private $length;

public function __construct(int $length)
/**
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

src/Rule/MinLength.php Show resolved Hide resolved
{
public function testValidate()
{
$firstRule = new MaxLength(5);
Copy link
Contributor

Choose a reason for hiding this comment

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

According to my other comment with a negative value, it would require a test that makes sure the exception is thrown.

tests/Rule/MinLengthTest.php Show resolved Hide resolved
{
if($length<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.

)
{
if($minLength<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 getMessage($v): string
{
return $this->message?:"'${$v}' is supposed to be at least ".$this->minLength." characters long.";
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 change the message to:

"'The value '{$v}' was expected to be at least {$this->minLength} characters long."

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.

2 participants