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: Add Find operation #204

Merged
merged 14 commits into from
Oct 26, 2021

Conversation

Radiergummi
Copy link
Contributor

@Radiergummi Radiergummi commented Oct 20, 2021

This PR:

  • Provides a find() operation
  • Has unit tests (phpspec)
  • Has static analysis tests (psalm, phpstan)
  • Has documentation

Fixes #198.

@drupol
Copy link
Collaborator

drupol commented Oct 20, 2021

Hey hi !

That's a nice start! I'm going to review it carefully today in the evening :)

@drupol
Copy link
Collaborator

drupol commented Oct 20, 2021

Could you give me write access to the repo so I can push the code-review changes?

I pushed my local branch here: https://github.com/loophp/collection/tree/feature/add-find-helper but I prefer to push my changes on your branch, so you can continue to push things if needed.

I did some changes in your Find operation, find them here: f97ee42

@drupol drupol added the enhancement New feature or request label Oct 20, 2021
@Radiergummi
Copy link
Contributor Author

Radiergummi commented Oct 21, 2021

Ah, of course. For some reason GitHub won't allow access to PR branches for org repos. I'll migrate it to my personal one.
Edit: Done.
Edit 2: Nice, appending the default after the filter is an elegant solution! 🙂

@drupol
Copy link
Collaborator

drupol commented Oct 21, 2021

Edit 2: Nice, appending the default after the filter is an elegant solution! slightly_smiling_face

Yeah I'm trying to avoid repeating the same code all over the place. Using simple operations allows you to "compose" a new operation with a custom behavior without rewriting anything (almost).

@drupol
Copy link
Collaborator

drupol commented Oct 21, 2021

I just added 4 commits, it should fix the implementation and the code-style.

Let me know if you plan to continue your work on this.

Thanks for your contribution!

@Radiergummi
Copy link
Contributor Author

No, I'm done. Thank you!

@drupol
Copy link
Collaborator

drupol commented Oct 21, 2021

Do you think you could provide the changes in api.rst containing an explanation of what the operation you introduce is doing?

For the rest, I'll do it myself if you don't have time.

@drupol
Copy link
Collaborator

drupol commented Oct 22, 2021

Thanks, much appreciated!

@Radiergummi
Copy link
Contributor Author

I hope its okay style-wise - I'm not happy with the examples, it's hard to come up with something not too contrived, find really only makes sense at the end of a longer chain of operations...

@drupol
Copy link
Collaborator

drupol commented Oct 22, 2021

The code style can be fixed automatically by doing: ./vendor/bin/grumphp run --tasks=phpcsfixer,phpcs

I quickly checked the example file and I think it's nice, it definitely shows how this find command could be useful with Doctrine.

WDYT @AlexandruGG ?

@AlexandruGG
Copy link
Collaborator

The code style can be fixed automatically by doing: ./vendor/bin/grumphp run --tasks=phpcsfixer,phpcs

I quickly checked the example file and I think it's nice, it definitely shows how this find command could be useful with Doctrine.

WDYT @AlexandruGG ?

Overall looks good, there's a few things to improve on the documentation and tests side but we can make the additions. Do you want me to take care of it @drupol?

@drupol
Copy link
Collaborator

drupol commented Oct 24, 2021

As you wish, if you have time to do it, go ahead, or else I'll take care myself next week.

@AlexandruGG
Copy link
Collaborator

As you wish, if you have time to do it, go ahead, or else I'll take care myself next week.

Happy to do it, leave it with me :)

AlexandruGG added 5 commits October 24, 2021 18:54
- variable and param naming consistency
- default value
- update operation typing
- add static analysis checks
- fix typing
- add more unit tests
Comment on lines 62 to 77
/*
PHP 8 - using named parameters and the default `null` value -> these should legitimately fail,
but Psalm reports no issue and PHPStan is reporting a different error than expected:
"Parameter #1 $value of function find_checkNullableInt expects int|null, (Closure)|int given."

find_checkNullableInt(Collection::fromIterable([1, 2, 3])->find(callbacks: $intValueCallback));
find_checkNullableString(Collection::fromIterable(['foo' => 'a', 'bar' => 'b'])->find(callbacks: $stringValueCallback));
*/

/*
PHP 8 - using named parameters and the default `null` value -> these should legitimately fail,
but Psalm reports no issue and the current PHPStan failures are due to the error mentioned above.

find_checkIntElement(Collection::fromIterable([1, 2, 3])->find(callbacks: $intValueCallback));
find_checkStringElement(Collection::fromIterable(['foo' => 'a', 'bar' => 'b'])->find(callbacks: $stringValueCallback));
*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

I put these here for info, but we cannot turn them on because the CI checks will fail on 7.4.

The issue reported by PHPstan is weird; it might be a bug but I can't be bothered to reproduce it in the playground right now

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks for providing the documentation and examples!

@drupol
Copy link
Collaborator

drupol commented Oct 24, 2021

💯 !

@AlexandruGG AlexandruGG marked this pull request as ready for review October 24, 2021 19:35
@AlexandruGG
Copy link
Collaborator

@drupol this is ready for review!

@Radiergummi thank you for the contribution, have a look at the latest code and let me know if everything's as you expected :)

Copy link
Collaborator

@drupol drupol left a comment

Choose a reason for hiding this comment

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

I followed the commits and I'm ok with everything! Thanks for spotting all the things!

Copy link
Collaborator

@drupol drupol left a comment

Choose a reason for hiding this comment

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

LGTM

@AlexandruGG
Copy link
Collaborator

@Radiergummi this is ready to go. If you have any comments let me know, otherwise I will merge it tomorrow

@drupol
Copy link
Collaborator

drupol commented Oct 26, 2021

I guess we can merge...

@Radiergummi
Copy link
Contributor Author

Yup, LGTM. Thank you so much! :)

@AlexandruGG AlexandruGG merged commit c2189f4 into loophp:master Oct 26, 2021
@AlexandruGG
Copy link
Collaborator

@Radiergummi @drupol thank you both for the work on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add find/search/where/single/firstWhere method
3 participants