getting issues and warnings in PHPCS
FILE: /Applications/MAMP/htdocs/d9/web/modules/contrib/xmlrpc/xmlrpc.module
------------------------------------------------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
------------------------------------------------------------------------------------------------------------------------------------------
32 | ERROR | Long array syntax must not be used in doc comment code annotations
33 | ERROR | Long array syntax must not be used in doc comment code annotations
57 | ERROR | All functions defined in a module file must be prefixed with the module's name, found "xmlrpc" but expected "xmlrpc_xmlrpc"
------------------------------------------------------------------------------------------------------------------------------------------
FILE: /Applications/MAMP/htdocs/d9/web/modules/contrib/xmlrpc/xmlrpc_example/src/Tests/XmlRpcExampleTest.php
------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 14 WARNINGS AFFECTING 14 LINES
------------------------------------------------------------------------------------------------------------------------------------------
76 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
77 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
81 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
82 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
85 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
94 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
107 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
109 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
112 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
113 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
136 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
137 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
142 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
143 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
----------------------------------------------------------------------------------------------------------------------
| Comment | File | Size | Author |
|---|---|---|---|
| #26 | interdiff-3329633-10-26.txt | 653 bytes | megachriz |
| #26 | xmlrpc-3329633-cs-fixes-26.patch | 5.14 KB | megachriz |
Issue fork xmlrpc-3329633
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3329633-drupal-coding-standard
compare
- 8.x-1.x
changes, plain diff MR !2
Comments
Comment #2
noorulshameera commentedAdding patch with issues fixed.
Comment #5
Charchil Khandelwal commentedPatch #2 working fine in my system.
Create MR for this.
Moving it to RTBC +.
Thank you.
Comment #6
megachrizChanging the name of the function
xmlrpc()toxmlrpc_call()is an API change, so I strongly recommend not to change this, even if it is flagged as a coding standard issue.The
t()calls in tests could be completely removed,t()calls in tests are usually not needed. They could be replaced with strings. For example:could be replaced with:
Comment #7
fgmISTR we can quiet the naming warning by moving the function to a
.incfile included from the module, can't we ?Comment #8
megachriz@fgm
Based on the coding standard message that sounds like it would work, but I wonder if including an extra file on every request is worth doing for just one coding standard issue (an issue I would call a false positive)?
Comment #9
avpadernoI think this is an edge case. The function name is the machine name of the module; there is no risk of name conflict because no other module should have a
xmlrpc()function.Plus, there are surely exceptions to how functions are named, for example a module that implements hooks on behalf of another module.
Moving the function in a different file would not have any effect, since the coding standards are valid also for any .inc file a module could use.
Comment #10
megachrizHere's a patch to fix the CS issues. I found out that with
phpcs:ignoreorphpcs:disableyou can ignore one specific type of coding standard violation.phpcs:ignorewould need to put directly above the line where the coding standard violation is, but that resulted into the coding violation "Missing function doc comment", so that's why I chose to usephpcs:disableinstead.Firstly, phpcs skipped the .module file locally, so I found out that I had to use this command:
The
-soption is to get the sniff code of the violation.Comment #11
avpadernoThe last patch seems good to go, to me.
Comment #12
fgmMostly good with using an ignore. However, I think you can put it at the function phpdoc level rather than at the file level, which makes it more focused.
Comment #13
megachriz@fgm
I tried that first, but I got an other coding standard violation in that case: "Missing function doc comment" (see #10).
Comment #14
fgmDid you try putting it at the end of the function line, like this ?
The line wrapping is d.o. formatting the page: the Drupal.Naming... is on the same line.
Comment #15
megachriz@fgm
I didn't yet, but when I do that:
I get on
phpcs --standard=Drupal . --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml -s:Comment #16
avpadernophpcs:ignoreis applied to the next line, not to the line containing it.Comment #17
akram khanadded updated patch and address comment #14 and #16
Comment #18
avpadernoEither
phpcs:disableorphpcs:ignoreis used. The first disables rules on all the lines following the line containing it until the line precedingphpcs:enable, the second disables rules only for the line following the line containing it. (That meansphpcs:ignorehas been also misplaced.)Comment #19
megachrizI think we'll need to go for the patch in #10 and call it a day. Because putting
// phpcs:ignore Drupal.NamingConventions.ValidFunctionName.InvalidPrefixabove the function results into an other coding standard violation.Comment #20
fgmAIUI it needs to be at the end of the line you want to ignore, not above it.
Comment #21
megachriz@fgm
You are correct. I see that if I put the ignore on the line it should ignore that coding standard violation is indeed ignored. The issue is though that it results into two other coding standard violations.
In examples I've seen the ignore line to be placed above the line it should ignore. That works too. But in this case that also results into an other coding standard violation: "Missing function doc comment".
So because of these results I think we should disable the rule near the top of the file. Two lines above the function docblock is also a possibility - in that case the "phpcs:disable" line is between
xmlrpc_help()andxmlrpc(). Do you like that better, @fgm?Comment #22
avpadernoThe examples given in the PHP_CodeSniffer documentation are clear.
It is not true the comment must be in the same line that needs to be ignored.
Comment #23
chaitanyadessai commentedPatch added please review.
Comment #25
megachriz@chaitanyadessai
Thanks for your contribution, but using
$this->t()in tests is rarely needed. So the changes in the tests were already good in the previous two patches.The only thing were this issue hangs on is where to place the phpcs comment to ignore/disable a coding standard violation.
Options considered:
phpcs::disable Drupal.NamingConventions.ValidFunctionName.InvalidPrefix, but that is less focused.phpcs::disable Drupal.NamingConventions.ValidFunctionName.InvalidPrefix, still less focused.phpcs::ignore Drupal.NamingConventions.ValidFunctionName.InvalidPrefix, but that causes another coding standard violation: "Missing function doc comment".phpcs::ignore Drupal.NamingConventions.ValidFunctionName.InvalidPrefix, but that causes two other coding standard violations.I would choose option 1. Options 3 and 4 are out of the question in my opinion as they create new problems.
Comment #26
megachrizOkay, looked at this again and I changed my mind. I think from the options listed at #25, option 2 is better. This is the closest focus with the function we can get. And ending with
phpcs:enable, so if in the future code is added to the module it checks for the naming conventions again.Comment #27
mahima_mathur23 commentedComment #28
Anmol_Specbee commentedPatch #26 seems to be working as expected and can be moved to RTBC.
Comment #30
megachriz@Anmol_Specbee
Thanks for checking, committed #26.