Skip to content

Generic/ForLoopWithTestFunctionCall: sniff should not be triggered when function call receives the variable being incremented as a parameter #298

Open
@rodrigoprimo

Description

@rodrigoprimo

Describe the solution you'd like

While reviewing #235, @jrfnl raised a good point that the Generic.CodeAnalysis.ForLoopWithTestFunctionCall sniff should not trigger a warning when the function call in the second part of the for loop receives as a parameter the variable being incremented in the third part, as moving this function call outside of the for loop is impossible.

Another option is to flag those function calls with a different error code so that it can be excluded.

Examples of code that the sniff should not flag but currently are flagged:

for ($i = 0; someFunction($i); $i++) {}

for ($i = 0; MyClass::staticMethod($i); $i++) {}

I am opening this issue to start a conversation on whether or not this change should be implemented.

  • I intend to create a pull request to implement this feature (I can at least give it a try, I'm unsure if the benefits of this change justify the complexity of implementing it)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions