-
-
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
Introduce helpers for static constructors #158
Conversation
public function getMatchers(): array | ||
{ | ||
return [ | ||
'beSameAs' => static fn (CollectionInterface $subject, CollectionInterface $expected): bool => $subject->same($expected), | ||
]; | ||
} |
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.
adding a custom matcher based on: https://www.phpspec.net/en/stable/cookbook/matchers.html#inline-matcher
Couldn't find a better way to test the function, let me know if you can think of any
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.
This is a good way indeed! And I don't see any other option at the moment.
@drupol does this look good to you? If so, I can add functions for the other constructors |
Hi Alex, Static constructors are already helpers and I don't like adding this so much. Even after reading the description, I'm still having troubles seeing the advantages of this. The documentation is hopefully written correctly now to explain how to create Collection, why would we want to have a function that does it on top of what's already existing? |
Hey @drupol, Thanks for the feedback. I had a few conflicting thoughts about this as well, but I still think I would find it useful. I think it would be great if we could list both the pros and cons of this. These are the ones I can think of: Pros:
Cons:
We could argue that the pros are not that significant and I partly agree, but would be nice to hear your reasoning. |
Hello there,
But why would this be a pro? I don't see any issue of having 1 or 2
Yeah... but we have autocompletion and I never write it completely, but rely on my IDE to autocomplete it. So here, I don't see the difference between the 2 options.
Yeah. I also made it clear since I started to write this library: avoid repeated code and let the user deal with userland implementations.
True. I could have use functions for creating all the Collection operations, but I choose not to and created Classes. So for me creating functions for constructors doesn't make sense. This is the reason why we have multiple static constructors in Collection.
Exactly, so, 1 or 2
I added some feedback below each argument. I usually like when people contributing inject their ideas, but honestly, for this one I don't follow you 😞. Maybe we should think about all these things in an extra-package, something like |
Fair enough, I think the pros are not that great for this one. Thanks for taking the time to go through this! |
Thanks for the constructive discussion Alex! |
This PR provides helper functions that can be used to instantiate Collection.
The main advantages are:
Related to #135 (comment).