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

Feat: Support more constraint operators #47

Merged
merged 10 commits into from
Feb 18, 2022
Merged

Conversation

RikudouSage
Copy link
Collaborator

@RikudouSage RikudouSage commented Feb 4, 2022

closes #42

Before merging the reference to client-specifications repository should be put back to the main branch.

'contextName' => 'email',
'operator' => ConstraintOperator::STRING_STARTS_WITH,
'inverted' => true,
// missing 'value' and 'values' and 'inverted' set to true
Copy link
Member

Choose a reason for hiding this comment

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

nice =)

protected function convert(string $number): int|float
{
if (str_contains($number, '.')) {
return (float) $number;
Copy link
Member

Choose a reason for hiding this comment

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

nice, I will add a float test to the specifications also.

{
assert(is_string($searchInValue));

return str_ends_with($searchInValue, $currentValue);
Copy link
Member

Choose a reason for hiding this comment

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

Is str_ends_with supported in PHP 7.2+, or is it only PHP 8.0?

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

8.0, but this repo contains a downgrader which downgrades the code to multiple version, it gets automatically changed to something suitable for each version during deploy, see for example here for version downgraded to php 7.4.

Copy link
Collaborator Author

@RikudouSage RikudouSage Feb 9, 2022

Choose a reason for hiding this comment

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

And here you can see one of the str_* functions downgraded:

if (substr_compare($url, '/', -strlen('/')) !== 0) {

Copy link
Member

Choose a reason for hiding this comment

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

This is nice. Thanks for explaining 👍🏼

{
assert(is_string($searchInValue));

return str_starts_with($currentValue, $searchInValue);
Copy link
Member

Choose a reason for hiding this comment

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

only from PHP 8?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Explained in previous comments, gets downgraded to suitable expression for each version.

{
assert(is_string($searchInValue));

return str_contains($currentValue, $searchInValue);
Copy link
Member

Choose a reason for hiding this comment

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

only from PHP 8?

Copy link
Member

@ivarconr ivarconr left a comment

Choose a reason for hiding this comment

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

It looks good!

It looks to me some of the operators used will only work on PHP 8. It would be good to use simple work-around to make sure they also work on PHP 7, given that it is possible and they are straight forward.

@RikudouSage
Copy link
Collaborator Author

As mentioned before, it gets downgraded for each version, that's why it's kinda easy to support older versions without sacrificing the features of new versions.

Copy link
Member

@ivarconr ivarconr left a comment

Choose a reason for hiding this comment

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

lgtm :D

@RikudouSage RikudouSage merged commit a6d2a39 into main Feb 18, 2022
@RikudouSage RikudouSage deleted the feature/constraints branch February 18, 2022 14:27
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.

feat: Add support for new constraint operators
2 participants