- ๐ฎ๐ณIndia Charchil Khandelwal
Charchil Khandelwal โ made their first commit to this issueโs fork.
- Merge request !2Issue #3329633: Drupal coding standard | PHPCS โ (Closed) created by Charchil Khandelwal
- Status changed to RTBC
almost 2 years ago 10:11am 31 January 2023 - ๐ฎ๐ณIndia Charchil Khandelwal
Patch #2 working fine in my system.
Create MR for this.
Moving it to RTBC +.Thank you.
- Status changed to Needs work
over 1 year ago 11:43am 24 March 2023 - ๐ณ๐ฑNetherlands megachriz
Changing 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:$this->assertSession()->pageTextContains(t('The XML-RPC server returned this response: @num', ['@num' => 77]));
could be replaced with:
$this->assertSession()->pageTextContains('The XML-RPC server returned this response: 77');
- ๐ซ๐ทFrance fgm Paris, France
ISTR we can quiet the naming warning by moving the function to a
.inc
file included from the module, can't we ? - ๐ณ๐ฑNetherlands 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)? - ๐ฎ๐นItaly apaderno Brescia, ๐ฎ๐น
I 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.
- Status changed to Needs review
over 1 year ago 7:17am 29 March 2023 - ๐ณ๐ฑNetherlands megachriz
Here's a patch to fix the CS issues. I found out that with
phpcs:ignore
orphpcs:disable
you can ignore one specific type of coding standard violation.phpcs:ignore
would 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:disable
instead.Firstly, phpcs skipped the .module file locally, so I found out that I had to use this command:
phpcs --standard=Drupal . --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml -s
The
-s
option is to get the sniff code of the violation. - ๐ฎ๐นItaly apaderno Brescia, ๐ฎ๐น
The last patch seems good to go, to me.
- Status changed to Needs work
over 1 year ago 1:45pm 29 March 2023 - ๐ซ๐ทFrance fgm Paris, France
Mostly 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.
- ๐ซ๐ทFrance fgm Paris, France
Did you try putting it at the end of the function line, like this ?
function xmlrpc() { // phpcs:ignore Drupal.NamingConventions.ValidFunctionName.InvalidPrefix
- ๐ณ๐ฑNetherlands megachriz
@fgm
I didn't yet, but when I do that:function xmlrpc($url, array $args, array $headers = []) { // phpcs:ignore Drupal.NamingConventions.ValidFunctionName.InvalidPrefix module_load_include('inc', 'xmlrpc'); return _xmlrpc($url, $args, $headers); }
I get on
phpcs --standard=Drupal . --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml -s
:--------------------------------------------------------------------------------------------------------------------------------- FOUND 1 ERROR AND 1 WARNING AFFECTING 1 LINE --------------------------------------------------------------------------------------------------------------------------------- 59 | ERROR | [x] There should be no white space after an opening "{" | | (Drupal.WhiteSpace.OpenBracketSpacing.OpeningWhitespace) 59 | WARNING | [ ] Line exceeds 80 characters; contains 130 characters (Drupal.Files.LineLength.TooLong) --------------------------------------------------------------------------------------------------------------------------------- PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY ---------------------------------------------------------------------------------------------------------------------------------
- ๐ฎ๐นItaly apaderno Brescia, ๐ฎ๐น
phpcs:ignore
is applied to the next line, not to the line containing it. - Status changed to Needs review
over 1 year ago 5:01am 31 March 2023 - ๐ฎ๐ณIndia Akram Khan Cuttack, Odisha
added updated patch and address comment #14
- Status changed to Needs work
over 1 year ago 7:30am 31 March 2023 - ๐ฎ๐นItaly apaderno Brescia, ๐ฎ๐น
+// phpcs:disable Drupal.NamingConventions.ValidFunctionName.InvalidPrefix +
+// phpcs:ignore Drupal.NamingConventions.ValidFunctionName.InvalidPrefix
Either
phpcs:disable
orphpcs:ignore
is 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:ignore
has been also misplaced.) - ๐ซ๐ทFrance fgm Paris, France
AIUI it needs to be at the end of the line you want to ignore, not above it.
- ๐ณ๐ฑNetherlands 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? - ๐ฎ๐นItaly apaderno Brescia, ๐ฎ๐น
The examples given in the PHP_CodeSniffer documentation are clear.
// phpcs:ignore $foo = [1,2,3]; bar($foo, false);
// phpcs:disable Generic.Commenting.Todo.Found $xmlPackage = new XMLPackage; $xmlPackage['error_code'] = get_default_error_code_value(); // TODO: Add an error message here. $xmlPackage->send(); // phpcs:enable
It is not true the comment must be in the same line.
- Status changed to Needs review
over 1 year ago 8:16am 11 April 2023 The last submitted patch, 23: 3329633-23-phpcs_fixes.patch, failed testing. View results โ
- Status changed to Needs work
over 1 year ago 8:33am 11 April 2023 - ๐ณ๐ฑNetherlands 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:
- Near the top of the file, using
phpcs::disable Drupal.NamingConventions.ValidFunctionName.InvalidPrefix
, but that is less focused. - Above the function docblock, using
phpcs::disable Drupal.NamingConventions.ValidFunctionName.InvalidPrefix
, still less focused. - Above the function itself, using
phpcs::ignore Drupal.NamingConventions.ValidFunctionName.InvalidPrefix
, but that causes another coding standard violation: "Missing function doc comment". - On the same line as the function, using
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.
- Near the top of the file, using
- Status changed to Needs review
over 1 year ago 2:07pm 12 April 2023 - ๐ณ๐ฑNetherlands megachriz
Okay, 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. - Status changed to RTBC
over 1 year ago 6:27am 25 April 2023 - ๐ฎ๐ณIndia Anmol_Specbee
Patch #26 seems to be working as expected and can be moved to RTBC.
-
MegaChriz โ
authored 0a8517b3 on 8.x-1.x
Issue #3329633 by MegaChriz, Charchil Khandelwal, Akram Khan,...
-
MegaChriz โ
authored 0a8517b3 on 8.x-1.x
- Status changed to Fixed
over 1 year ago 8:20am 25 April 2023 Automatically closed - issue fixed for 2 weeks with no activity.