Fix the errors/warnings reported by PHP_CodeSniffer

Created on 7 March 2024, 11 months ago
Updated 30 July 2024, 6 months ago

Problem/Motivation

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

Steps to reproduce

Run the following commands:

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,yml modules/contrib/autoplay/

Report:

FILE: /home/contribution/drupal/web/modules/contrib/autoplay/src/Plugin/WebformHandler/AutoplayHandler.php
----------------------------------------------------------------------------------------------------------------------------------------------
FOUND 12 ERRORS AND 2 WARNINGS AFFECTING 11 LINES
----------------------------------------------------------------------------------------------------------------------------------------------
   9 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\autoplay\AutoplayBase.
  61 | ERROR   | [x] Expected 1 space after cast statement; 0 found
  63 | WARNING | [x] A comma should follow the last multiline array item. Found: configuration
 172 | WARNING | [x] 'TODO? Multiple multiples?? Potentially many permutations/requests' should match the format '@todo Fix problem X here.'
 172 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 260 | ERROR   | [ ] The array declaration extends to column 185 (the limit is 120). The array content should be split up over multiple lines
 266 | ERROR   | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph
 270 | ERROR   | [x] Separate the @param and @return sections by a blank line.
 270 | ERROR   | [ ] Return type missing for @return tag in function comment
 282 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 285 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 305 | ERROR   | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph
 309 | ERROR   | [x] Separate the @param and @return sections by a blank line.
 309 | ERROR   | [ ] Return type missing for @return tag in function comment
----------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/autoplay/src/Plugin/QueueWorker/AutoplaySubmissionHandler.php
------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 11 ERRORS AND 2 WARNINGS AFFECTING 9 LINES
------------------------------------------------------------------------------------------------------------------------------------------------
  5 | ERROR   | [x] No space found before comment text; expected "// use Drupal\Core\Entity\EntityStorageInterface;" but found "//use
    |         |     Drupal\Core\Entity\EntityStorageInterface;"
  5 | ERROR   | [x] Inline comments must start with a capital letter
  5 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
  6 | WARNING | [x] Unused use statement
  8 | ERROR   | [x] No space found before comment text; expected "// use Drupal\node\NodeInterface;" but found "//use
    |         |     Drupal\node\NodeInterface;"
  8 | ERROR   | [x] Inline comments must start with a capital letter
  8 | ERROR   | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 10 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\autoplay\AutoplayBase.
 25 | ERROR   | [x] Expected 1 blank line before function; 0 found
 26 | WARNING | [ ] Line exceeds 80 characters; contains 94 characters
 30 | ERROR   | [x] Missing function doc comment
 36 | ERROR   | [x] Expected 1 blank line after function; 0 found
 37 | ERROR   | [x] The closing brace for the class must have an empty line before it
------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 12 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/autoplay/src/Form/AutoplayConfigForm.php
-----------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
-----------------------------------------------------------------------------------------------------
  8 | ERROR | [x] Missing class doc comment
 75 | ERROR | [x] Expected 1 blank line after function; 0 found
 76 | ERROR | [x] The closing brace for the class must have an empty line before it
-----------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/autoplay/src/AutoplayBase.php
------------------------------------------------------------------------------------------
FOUND 10 ERRORS AND 1 WARNING AFFECTING 11 LINES
------------------------------------------------------------------------------------------
   5 | ERROR   | [x] When importing a class with "use", do not include a leading \
   7 | ERROR   | [x] Missing class doc comment
   9 | ERROR   | [x] Missing function doc comment
  52 | ERROR   | [x] Missing function doc comment
  55 | ERROR   | [x] Expected newline after closing brace
  60 | ERROR   | [x] Missing function doc comment
  67 | ERROR   | [x] Missing function doc comment
  92 | ERROR   | [x] Missing function doc comment
 109 | ERROR   | [x] Missing function doc comment
 132 | WARNING | [ ] The use of function dpm() is discouraged
 148 | ERROR   | [x] Concat operator must be surrounded by a single space
------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 10 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------

šŸ“Œ Task
Status

Needs work

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡³India realsp

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @realsp
  • Merge request !1Fixed the coding standard issues in files ā†’ (Open) created by realsp
  • Issue was unassigned.
  • Status changed to Needs review 11 months ago
  • šŸ‡®šŸ‡³India realsp

    I've created MR to fix the coding standards issues, Please review the MR.
    Thank you.

  • Status changed to Needs work 6 months ago
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi @realsp,

    I applied MR!1, it was applied smoothly and fixed most of the phpcs issues.

    These are the remaining issues:

    āžœ  contrib phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml autoplay
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/autoplay/autoplay.info.yml
    -------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------
     1 | WARNING | Remove "project" from the info file, it will be added by drupal.org packaging automatically
     1 | WARNING | Remove "datestamp" from the info file, it will be added by drupal.org packaging automatically
     1 | WARNING | Remove "version" from the info file, it will be added by drupal.org packaging automatically
    -------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/autoplay/README.md
    ---------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
    ---------------------------------------------------------------------------------------
      3 | WARNING | Line exceeds 80 characters; contains 153 characters
      5 | WARNING | Line exceeds 80 characters; contains 133 characters
     14 | WARNING | Line exceeds 80 characters; contains 98 characters
     18 | WARNING | Line exceeds 80 characters; contains 114 characters
    ---------------------------------------------------------------------------------------
    
    Time: 228ms; Memory: 12MB
    
    āžœ  contrib

    We can ignore the warnings in the info.yml since it is because I downloaded the module via composer.

    Thank you.

Production build 0.71.5 2024