-
-
Notifications
You must be signed in to change notification settings - Fork 35
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
Refactor Current
operation - Let specify a default value
#205
Conversation
df658a1
to
d3e95e2
Compare
bfefcea
to
01bcd17
Compare
01bcd17
to
97ab2c7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need some new checks that use a default value with current
here:
https://github.com/loophp/collection/blob/master/tests/static-analysis/current.php
get_checkIntElement(Collection::fromIterable([1, 2, 3])->get(1)->current()); | ||
/** @psalm-suppress PossiblyNullArgument @phpstan-ignore-next-line */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same with all of these, has the behaviour changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this slight behaviour change is because of the Psalm issue: vimeo/psalm#6685
08cb578
to
296c496
Compare
296c496
to
8f3eef0
Compare
8f3eef0
to
85a1a2f
Compare
src/Contract/Operation/Getable.php
Outdated
* @param TKey $key | ||
* @param T|null $default | ||
* @param V|null $default |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @param V|null $default | |
* @param V $default |
I'm wondering whether this will be enough to prevent NullArgument
in the static analysis checks here: https://github.com/loophp/collection/pull/205/files#diff-a937b0d4bd3a09eb4429e096dacf9b26f2dd67d7c351847aa12020dc44fdabe3R71
the return type would also be @return Collection<TKey, T|V>
It's basically saying that null
is included in the template V. Seems to be working fine for the updated find
operation: https://github.com/loophp/collection/pull/204/files?diff=split&w=1#diff-24b4b03ac10151d1e45f941532d787d12da924e784810b814dcb366380c2bdbcR26-R33. See the static analysis checks there as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Faire enough. TBH, this is something that I'm unsure of. I never know if we have to add this |null
or not.
I will follow your advice and remove it. Let me know if it's ok.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll have a look and do some testing in a bit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made a commit to remove some of these remaining null
: f6e05ee
ca94605
to
0c5e433
Compare
I'll add the suggested tests tomorrow. |
Ok I'm done with this one, let me know what you think @AlexandruGG . I removed the |
f30db13
to
4430daa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@drupol thanks for this nice addition; it should be good to go now, but have a look at the last commit I made
Excellent. |
This PR:
Current
operation and allow users to specify a default value when the user index is out of bound. The default value by default isnull
to stay backward compatible.Current
class is used on its own.