You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Instigated by the bug report in #590, I have done a review of this sniff and can only conclude that this sniff is fundamentally flawed.
The sniff looks at variables, but does not take variable scope into account.
Code example demonstrating the issue:
functionfoo() {
$var = 'extract';
}
functionbar( callable$var ) {
$var(); // <= The sniff would throw an error here for dynamically calling `extract()`.
}
While the simple example above demonstrates the problem, the actual problem is much larger as the sniff also doesn't keep track of file changes, so a variable declared in file A, could lead to a false positive for a dynamic function call in file H.
The cache will also overwrite previously identified variables without taking context into account, compounding the issue.
While PR #592 will get rid of the immediate issues in the sniff, it does not address this fundamental flaw.
Limited check
As annotated in the sniff, it only looks for a select syntax to detect the issue, ignoring the most common problem case of the function names being used in callbacks.
Conclusion
Fixing the flaws in this sniff would not be an easy fix and basically requires writing a completely new sniff.
As there are no significant bug reports about this, I'm going to suggest leaving it as is for now.
If, at some point, bug reports start coming in for the identified issues, I suggest removing the sniff altogether.
If, at some point, the PHPCompatibility standard would add a (better) sniff for this, I suggest switching over or removing the sniff here and recommending people use the PHPCompatibility standard for these type of issues.
Note: the PHPCompatibility standard does not detect this issue at this time exactly because it is not easy to get this right.
Review the
WordPressVIPMinimum.Functions.DynamicCalls
sniff for the following in as far as relevant to that sniff:Typical things to add tests for and verify correct handling of:
list
statementsTypical things to add tests for and verify correct handling of (where applicable):
::class
use function/const
Other:
Sniff basics, but changes need to be lined up for next major release:
public
properties (Audit Public Sniff Properties #234)Once PHPCS/PHPCSUtils supports this:
match
expressionsThe text was updated successfully, but these errors were encountered: