I've tried the new VariableComment sniff on our codebase and it turned up a large number of instances where developers had mistakenly declared the variable name in the docblock, like this:
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface $user
*/
protected $user;
This presumably happens by copy-pasting from a parameter docblock, or by sheer muscle memory.
The current warning that the sniff is throwing is a little bit confusing:
Expected "\Drupal\Core\Session\AccountProxyInterfaceuser" but found "\Drupal\Core\Session\AccountProxyInterface $user" for @var tag in member variable comment
Let's provide a helpful warning + an auto fixer for this common mistake.
Comments
Comment #2
pfrenssenComment #3
pfrenssenComment #4
pfrenssenProposed a solution in a PR: https://github.com/klausi/coder/pull/11
Comment #5
klausiLooks like this conflicts with #2790657: VariableCommentSniff doesn't recognize multiple types, can you resolve?
Comment #6
pfrenssenCertainly! I merged it.
Comment #7
klausiMerged, thanks!