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

Feature: Strict Integer Checking #131

Merged
merged 1 commit into from
Jul 8, 2016

Conversation

rcatlin
Copy link
Contributor

@rcatlin rcatlin commented Jul 6, 2016

What?

Adds a $strict parameter to Rule\Integer to allow validation of only integer types.

Checklist

  • Added unit test for added/fixed code
  • Updated the documentation
  • Scrutinizer code coverage is 100%
  • Scrutinizer code quality is as high as possible

if (is_int($value)) {
return true;
}
} else if (false !== filter_var($value, FILTER_VALIDATE_INT)) {
Copy link

Choose a reason for hiding this comment

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

The nesting of ifs can be reduced here:

        if ($this->strict && is_int($value)) {
            return true;
        }

        if (!$this->strict && filter_var($value, FILTER_VALIDATE_INT) !== false) {
            return true;
        }

        return $this->error(self::NOT_AN_INTEGER);

That's easier to read if you ask me, what do you think?

@rick-nu
Copy link

rick-nu commented Jul 8, 2016

Hey @rcatlin, thank you for your addition! I have 1 codewise comment, but other than that it's good to go 👍

@rcatlin
Copy link
Contributor Author

rcatlin commented Jul 8, 2016

@RickvdStaaij Thanks for the feedback! I've separated the two conditions and made them more readable.

@rick-nu
Copy link

rick-nu commented Jul 8, 2016

Perfect, thanks a lot! 👍 Also backwards compatible \o/

@rick-nu rick-nu merged commit 0f6b104 into particle-php:master Jul 8, 2016
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.

None yet

2 participants