-
Notifications
You must be signed in to change notification settings - Fork 160
[New Rule] Function/method call in for loop declaration MUST be avoided #28
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
Comments
Hopefully some future versions of PHP compiler will optimize away such constructs to make this sniff unnecessary (most modern compilers handle this well), but for now, if we have this sniff, it should only be a warning. |
This rule requires better description. The title confuses: I thought inside the loop itself, not in "for" statement definition. |
@akiseliov thanks for the feedback. I updated the title. Hope it makes more sense now. |
Hi @lenaorobei, something like this was done in the ECG Sniff: https://github.com/magento-ecg/coding-standard/blob/master/Ecg/Sniffs/Performance/LoopSniff.php Maybe it makes sense to port it. What's your vision generally on those sniffs? |
Hi @Zifius. We use this rule for Magento Marketplace verification and I noticed a lot of false-positive findings. This is the reason why I didn't include this sniff and created a proposal. |
@lenaorobei this rule is totally useless actually and was rejected endless amount of times, for instance: magento/magento2#17501 (comment) |
@orlangur I'm really interested in understanding your firm position regarding this rule. Few points from my side about this:
Looking forward to constructive dialogue. |
Calling function in loop signature is perfectly valid, just like calling within
Proof, please. All previous contributions I met were just about performance impact and I provided an evidence such concerns are groundless.
Security aspect is only applicable to compare some hashes where string may be accidentally interpreted as number with
Don't see how it is related to this issue, generally a real standard is something our code is 100% compliant with (like it was after magento/magento2#8685) and we can have additional checks for new files like it works for So, to summarize this particular rule, there is no need to put some function call out of loop signature until profiler shows it is a bottleneck. |
The rule is already included from OOB Generic Coding Standard:
|
@lenaorobei so what is an actual basis for this list #14? Why it wasn't discussed and cleaned up from useless rules like this one? |
…-coding-standard-231 [Imported] Version 8
Rule
Function
/method
call infor
loop declaration MUST be avoided.Reason
PHP will call the
method
/function
on each iteration of thefor
loop.Bad Example:
Good example:
Implementation
T_FOR
token.T_STRING
with followed by open parentheses).The text was updated successfully, but these errors were encountered: