The Commenting.DataTypeNamespace sniff tries to match each use statement against each @var, @param and @return statement to check that they are fully namespaced. However, the way that it is coded currently can lead to matches with more than one 'use' statement and we get the same error reported more than once. Take this real snippet from Rules module http://cgit.drupalcode.org/rules/tree/tests/src/Unit/Integration/Action/...
use Drupal\rules\Engine\RulesComponent;
use Drupal\rules\Entity\RulesComponentConfig;
then later
* @param RulesComponentConfig[] $rules_configs
The method for matching involves the if clause strpos($tokens[($tag + 2)]['content'], $tokens[$classPtr]['content']) === 0 where $tokens[($tag + 2) is going to be RulesComponentConfig[] $rules_configs and $tokens[$classPtr] will be the class name in the use statement. The strPos( ) line matches both of these use statements, when it should match only 'RulesComponentConfig'. This is because 'RulesComponent' is a substring of 'RulesComponentConfig' which also starts at position 0.
Maybe we shoud explode $tokens[($tag + 2)]['content'] on space and [ ] and then check the value directly, instead of using strPos()
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | repeated error for DataTypeNamespace.txt | 1.13 KB | jonathan1055 |
Comments
Comment #2
jonathan1055 commentedSomething like
instead of
This works for the example in Rules module, and we get only one error on line 177 instead of two. Patch to follow - but I guess this will also need a test to prove it is the correct fix.
Comment #3
jonathan1055 commentedHere's the current phpcs output on the Rules file in the example
Comment #4
klausiThe DataTypeNamespace sniff has been removed in Coder 9. We use sniffs from Slevomat now instead. Please open a new issue if there is still a problem with that.