Infection: ForeachKey mutation

Created on 14 Apr 2020  路  2Comments  路  Source: infection/infection

-foreach ($results as $index => $result) {
+foreach ($results as $result) {

_Originally posted by @theofidry in https://github.com/infection/infection/pull/1242_

Good First Issue / Easy Pick Mutator

Most helpful comment

For what its worth, i found those unused variables with help of the 'find dead code' feature from psalm.

So i'm not convinced this is something that should be part of infection, but rather it should be part of a static analysis tool.

All 2 comments

Q:

this mutation will in most cases be killed because of "undefined variable", no?

A:

That, unless $index is unused.


So, in my opinion (although I didn't do any real checks) this can lead to killed mutants in majority of the cases.

We should not do this mutation _if the variable is used_, but at the moment Infection has no such knowledge about variables. As I said many times before, probably we need to integrate PHPStan's engine to track variables usages & types to accomplish it.

For what its worth, i found those unused variables with help of the 'find dead code' feature from psalm.

So i'm not convinced this is something that should be part of infection, but rather it should be part of a static analysis tool.

Was this page helpful?
0 / 5 - 0 ratings