phpcs-variable-analysis
phpcs-variable-analysis copied to clipboard
Use `File::getMethodParameters()`
https://github.com/sirbrillig/phpcs-variable-analysis/blob/2976bca165ff20efa391028bb1a779c403bbbab8/VariableAnalysis/Sniffs/CodeAnalysis/VariableAnalysisSniff.php#L464-L467
I have no clue how old that comment is, but it definitely isn't valid anymore and hasn't been valid for a long time.
The File::getMethodParameters()
utility method can retrieve information on all declared parameters for functions, closures (since PHPCS 2.8.0), arrow functions (since PHPCS 3.5.4) and closure use statements (since PHPCS 3.5.0).
Ref: https://pear.php.net/package/PHP_CodeSniffer/docs/3.5.4/apidoc/PHP_CodeSniffer/File.html#methodgetMethodParameters
To change this would probably require a refactor, but it would also make the code more stable and simpler.
It looks like it originated in 2011 here: 385b5a8af5e470e7bb7e4f1f8d676213896fdee6
Sounds like a great idea to replace that.
As that would require a refactor and the issue with list
s would also be better off with a refactor (and I can think of some additional issues with global
and static
), we may want to set up a call at some point to discuss how to approach this and who will take care of what, including the implementation of using PHPCSUtils.
That sounds like a good idea. A lot of the code in this sniff has been implemented in a "make the tests pass and we can clean it up later" manner, and I think adding PHPCSUtils is an excellent opportunity to do a lot of that clean up.
This week I'm working on launching a major project at work which is taking up pretty much all of my time but I'd love to chat about this in more detail after we're done... maybe next week or the week after?
I'm prepping for a conference at the moment (or rather: should be) and will be traveling and such for the next two weeks after that. So, realistically, any time after March 9th ;-)
If you want to have a look at what PHPCSUtils offers in the mean time, the documentation is up: https://phpcsutils.com/ and https://phpcsutils.com/phpdoc/index.html