When running the module code against Drupal coding standards based on Drupal standard, the module shows errors

phpcs -s --standard=Drupal sites/default/modules/display_field_copy/

FILE: ...dules/display_field_copy/src/Plugin/DsField/DisplayFieldCopy.php
----------------------------------------------------------------------
FOUND 7 ERRORS AFFECTING 6 LINES
----------------------------------------------------------------------
 61 | ERROR | [x] The first parameter of a multi-line function
    |       |     declaration must be on the line after the opening
    |       |     bracket
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.FirstParamSpacing)
 62 | ERROR | [x] Multi-line function declaration not indented correctly;
    |       |     expected 6 spaces but found 30
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 63 | ERROR | [x] Multi-line function declaration not indented correctly;
    |       |     expected 6 spaces but found 30
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 64 | ERROR | [x] Multi-line function declaration not indented correctly;
    |       |     expected 6 spaces but found 30
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 65 | ERROR | [x] Multi-line function declaration not indented correctly;
    |       |     expected 6 spaces but found 30
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 66 | ERROR | [x] Multi-line function declaration not indented correctly;
    |       |     expected 6 spaces but found 30
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 66 | ERROR | [x] The closing parenthesis of a multi-line function
    |       |     declaration must be on a new line
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.CloseBracketLine)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


FILE: ...ult/modules/display_field_copy/src/Form/DisplayFieldCopyForm.php
----------------------------------------------------------------------
FOUND 7 ERRORS AFFECTING 6 LINES
----------------------------------------------------------------------
 45 | ERROR | [x] The first parameter of a multi-line function
    |       |     declaration must be on the line after the opening
    |       |     bracket
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.FirstParamSpacing)
 46 | ERROR | [x] Multi-line function declaration not indented correctly;
    |       |     expected 6 spaces but found 30
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 47 | ERROR | [x] Multi-line function declaration not indented correctly;
    |       |     expected 6 spaces but found 30
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 48 | ERROR | [x] Multi-line function declaration not indented correctly;
    |       |     expected 6 spaces but found 30
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 49 | ERROR | [x] Multi-line function declaration not indented correctly;
    |       |     expected 6 spaces but found 30
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 50 | ERROR | [x] Multi-line function declaration not indented correctly;
    |       |     expected 6 spaces but found 30
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.Indent)
 50 | ERROR | [x] The closing parenthesis of a multi-line function
    |       |     declaration must be on a new line
    |       |     (Squiz.Functions.MultiLineFunctionDeclaration.CloseBracketLine)
----------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Time: 82ms; Memory: 6Mb

Comments

anoopjohn created an issue. See original summary.

anoopjohn’s picture

Status: Active » Needs review
StatusFileSize
new2.51 KB

Please find attached a patch that fixes the errors.

davidwbarratt’s picture

Status: Needs review » Postponed (maintainer needs more info)

I think you might be using an old version of Coder... here's what I have:

$ pwd
/Users/dbarratt/.composer
$ composer show
drupal/coder                          8.2.7  Coder is a library to review Drupal code.
squizlabs/php_codesniffer             2.6.1  PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects

which produces (in the repo directory):

$ pwd
/Users/dbarratt/git/display_field_copy/display_field_copy
$ phpcs --standard=/Users/dbarratt/.composer/vendor/drupal/coder/coder_sniffer/Drupal .
$ phpcs --standard=/Users/dbarratt/.composer/vendor/drupal/coder/coder_sniffer/DrupalPractice .
$
anoopjohn’s picture

Status: Postponed (maintainer needs more info) » Needs review

Yes you are right. I am using the latest dev version of coder :-). You might still want to fix the issue as the issue is something that coder has already been modified to address.

You can avoid using the full path to the standard by registering the standard's paths

phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer

This should allow you to run it using

phpcs -s --standard=Drupal path

You can checkout the latest coder 8.x-2.x in the coder folder by making coder use the source (https://www.drupal.org/node/1419988)

composer global update drupal/coder --prefer-source

and then

cd /Users/dbarratt/.composer/vendor/drupal/coder
git checkout 8.x-2.x
davidwbarratt’s picture

This issue #1539712: [policy, no patch] Coding standards for breaking function calls and language constructs across lines is still in "Needs Review" so I'll mark this issue as postponed until it can be resolved.

Looks like there's a bug in the next version of Coder that needs to be resolved before it's release. Would you mind creating an issue for them in their queue?

davidwbarratt’s picture

Status: Needs review » Postponed
anoopjohn’s picture

Thanks for pointing to that issue @davidwbarratt. I had a couple of questions myself which I have asked in the issue. I have reported the issue in coder queue as well #2747203: Coder currently checks for Squiz.Functions.MultiLineFunctionDeclaration.* while this is not yet approwed by TWG. BTW it looks like the standard is in the approved state and is waiting for announcement.

jannakha’s picture

Status: Postponed » Closed (outdated)

Drupal 8 is out of support.
Please upgrade to Drupal 10+ and use latest version of the module.