Skip to content

Replace, improve, or drop VariableAnalysis #236

@GaryJones

Description

@GaryJones

What problem would the enhancement address for VIP?

The VariableAnalysis sniff isn't up to the same quality as some of the other sniffs.

The unit tests for this sniff are severely lacking - there's basically one test.

The code isn't written in the same way as the rest of the sniffs; there is a helper class, which suggests that the one sniff class is trying to do too much. It is based on https://github.com/illusori/PHP_Codesniffer-VariableAnalysis (last updated 6 years ago), and then updated a few times since by @david-binda .

Describe the solution you'd like

The choices:

Replace

I'm wondering whether making use of https://github.com/sirbrillig/phpcs-variable-analysis by A11n @sirbrillig would be a better route in the long term. It too is forked from the same original code (and is therefore also not written in a typical way), but is active (last updated 6 days ago at the time writing), and has considerably more tests. We could require it as a require dependency, and then reference it in the VIPCS ruleset(s).

I had a quick look at sniffs in the standards built-in to PHPCS, but didn't see anything that would come close.

Improve

It basically needs a rewrite, and many more unit tests. It probably needs splitting into separate sniffs that target different areas of "variable analysis".

The current checks are:

Drop

If the rest of the checks it does are not that useful, or not useful for following critical rules for WPCOM and VIP-Go, then it could be considered to be dropped.

  • Unused variables can be detected by tools like PHP Mess Detector, PHPStan and other static analysis tools.
  • Self/Static outside a class seems like something PHP lint would possibly pick up. - Variable undefined seems like unit tests should pick this up.
  • Variable redeclaration doesn't seem like a big issue.

All of them are things that an inspection in an IDE would flag (static analysis), and none of them seem to be VIP-specific, and so any consideration should be that any sniffs go elsewhere - upstream, or be left to @sirbrillig's package etc.

Leave As Is

The final option is to do nothing. However, there are already bug reports about it (#223), and I wonder if it's a false sense of security, if the code can't be trusted (and with virtually no tests, I don't trust it).

cc @sboisvert @tomjn @gudmdharalds

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions