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

Reduce use of inner validators #14

Merged
merged 2 commits into from
Nov 2, 2023
Merged

Reduce use of inner validators #14

merged 2 commits into from
Nov 2, 2023

Conversation

dlh01
Copy link
Member

@dlh01 dlh01 commented Oct 31, 2023

Summary

Profiling conducted on a recent client project suggests the use of validators within validators becomes relatively slow. This PR removes the use of these inner validators, which makes the code less DRY but should make it more performant.

Since most of the slowdown caused by the inner validators occurred during processing by the abstract validator class, it might be worth considering moving this library's validators away from that abstract validator, making it more palatable to use inner validators again.

Notes for reviewers

None.

Changelog entries

Added

Changed

  • Reduce uses of validators within validators.

Deprecated

Removed

Fixed

Security

@dlh01 dlh01 changed the title Remove use of inner validators Reduce use of inner validators Oct 31, 2023
Copy link

@mogmarsh mogmarsh left a comment

Choose a reason for hiding this comment

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

👍

if (! $valid) {
$messages = $this->validDivisors->getMessages();
throw new InvalidArgumentException("Invalid 'divisor': " . current($messages));
if ($divisor === 0) {
Copy link

Choose a reason for hiding this comment

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

do we need to check if the divisor is an int as well? Or is that handled somewhere else?

Copy link
Member Author

Choose a reason for hiding this comment

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

The divisor can also be a float or a string or whatever else PHP can convert to an integer. I'm kinda inclined to not get in the way of that. Also, I don't want to introduce a restriction with this change that would require a major version bump.

@dlh01 dlh01 merged commit bcc5eec into main Nov 2, 2023
4 checks passed
@dlh01 dlh01 deleted the fix/inner-validators branch November 2, 2023 02:59
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