-
Notifications
You must be signed in to change notification settings - Fork 5
More precise types after Option::filter()
#23
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
Conversation
|
Hello, the first step you should do is to run the build on your local machine before you create a PR. |
|
Of course I'm here to help you get your contribution over the finish line but please respect my time and try to learn the substance behind the code. You can start here https://phpstan.org/developing-extensions/core-concepts |
|
I don't exactly understand what this new extension does..
Even if phpstan knows for a fact that @devnix could you please explain what the goal is here exactly? |
|
Is the goal for example to turn |
|
Sorry, @ondrejmirtes, I just wanted to gauge interest in finishing a feature like this. Maybe I should have created a draft instead of a PR, or as you stated, invest some more time into cleaning all the CI. Until I figure out how to make those Hi @azjezz!
Yes, that's the whole purpose, I guess it can also be applied to other filtrable monads 😊 |
|
I would suggest then marking this PR as a draft, looking how something like this is implemented already for |
|
You don't need to copy and paste the array_filter implementation from phpstan-src, you can create "fake AST" that will just call the logic, like: |
|
Now I see that there's a |
|
That's not part of BC promise. |
Psl\Option\Option::filter() type inference PoCOption::filter()
|
Thank you for your comments! It took me a while to figure out how to make it work, and I learned a lot through the process, discovering It's indeed a much simpler and smarter approach, I'm really really grateful.
@azjezz, if the implementation is correct, I'm probably extracting it to a helper and applying it to more implementations for other classes that have similar methods. What are your thoughts about azjezz/psl#535? That would greatly simplify the extension, if it makes sense for the general use cases of the library 🙂 |
5ca8540 to
f303cc6
Compare
|
Comment edited, after taking a third closer look, I found that I was using a couple of non-existent methods that probably were hallucinated at my first attempt, sorry for the noise there, tests should be green now. |
|
Fixed (I hope) workflows for lower versions of PHP and PSL |
|
Sorry, the support for older PHP and PSL versions is biting me. Additionally, now that I'm aware of the widespread support the plugin has, introducing an interface would not simplify anything, as implementing a I'm going to close this pull request and enable Github actions on my branch, and I will create a pull request when I've got everything green. Sorry for the extra noise. |
I've been digging into trying to refine the type inside of
Option<T>as I made a heavy use of it. Right now I'm writing a lot of code that looks like this:that I think could be easily avoided.
As I've been able to write a handful of Rector rules, I decided to try to make an implementation, but I have to confess that I ✨vibed✨ it a little bit. I'm trying to fully understand each step, but some details are escaping my current knowledge.
Right now it seems to work, except for cases like
\Psl\Type\non_empty_list()->matches(...). I think that there should be a generic way of handling those and not hardcoding theTypeInterface, but I'm not getting it to work.Do you think it could be a nice-to-have feature, and how it's done? I will happily receive any kind of feedback so I can become less dependent on LLMs to write PHPStan rules. I also would love to implement this feature on
VectorInterface,MapInterface, etc.