Type Aware Mutators #1916
Replies: 2 comments 1 reply
-
Hi @MidnightDesign, you are absolutely right. Infection doesn't have knowledge about types under the hood, only when mutating the current function/method, it can understand it's return type or parameter types. But in your example, we would need to know return type of methods of Personally, I think, the only 1 way how to achieve this is to reuse PHPStan's internal engine, the same way how Rector did it (as far as I know). This requires deep investigation and ideally conversation with Ondrej/Tomas to use their knowledge and experience. We don't know how much it will affect performance, but Infection will 100% be slower. Should we implement our own simplified "static analysis" feature without using PHPStan's engine? Well, to answer to this question we need to understand how it would work with PHPStan's one and what it means for us to implemen it (I don't know how such things work under the hood, so I think it's a very complex task). |
Beta Was this translation helpful? Give feedback.
-
There is this package: https://github.com/Roave/infection-static-analysis-plugin In my experience it was faster to run Infection alone rather than wait for static analysis tools to come up with verdict, although if you have a lot of impure tests (e.g. hitting a database) it could provide a fair compromise. |
Beta Was this translation helpful? Give feedback.
-
I'm surprised I couldn't find any issues or discussions about this, so I'm starting one.
As far as I know, Infection is currently unable to perform a mutation like this:
I'm pretty sure this is because Infection doesn't know what the return types of
create()
andwithFooEnabled()
are. If they had different return types, this mutant wouldn't make any sense.Over the years of working with Infection, I've come across several examples of "Why isn't there a mutation for this?? Oooh, because Infection would have to know more about the types." Is that the case or is there a different reason? I'm guessing it would require a ton of overhead to analyze the codebase more thoroughly.
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions