Fix the issues reported by phpcs

Created on 25 May 2023, over 1 year ago
Updated 11 August 2023, over 1 year ago

Problem/Motivation

Missing standards and file doc comment

Steps to reproduce

Run the command:

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml trumba

Proposed resolution

Fix the following coding standards issues and create an MR with fixes.

FILE: /app/modules/contrib/trumba/js/trumba.js                                 
----------------------------------------------------------------------         
FOUND 3 ERRORS AFFECTING 3 LINES                                               
----------------------------------------------------------------------         
  1 | ERROR | [x] End of line character is invalid; expected "\n" but          
    |       |     found "\r\n"                                                 
 12 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found             
 18 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected             
    |       |     "TRUE" but found "true"                                      
----------------------------------------------------------------------         
                                                                               
                                                                               
FILE: /app/modules/contrib/trumba/src/Form/TrumbaConfigurationForm.php         
----------------------------------------------------------------------         
FOUND 1 ERROR AND 2 WARNINGS AFFECTING 3 LINES                                 
----------------------------------------------------------------------         
  1 | ERROR   | [x] End of line character is invalid; expected "\n"            
    |         |     but found "\r\n"                                           
 12 | WARNING | [ ] The class short comment should describe what the           
    |         |     class does and not simply repeat the class name            
 50 | WARNING | [ ] Possible useless method overriding detected                
----------------------------------------------------------------------         
                                                                               
                                                                               
FILE: /app/modules/contrib/trumba/src/Plugin/Block/TrumbaBlockBase.php         
----------------------------------------------------------------------         
FOUND 38 ERRORS AND 3 WARNINGS AFFECTING 26 LINES                              
----------------------------------------------------------------------         
   1 | ERROR   | [x] End of line character is invalid; expected "\n"           
     |         |     but found "\r\n"                                          
  10 | WARNING | [x] Unused use statement                                      
  23 | ERROR   | [x] There must be exactly one blank line before the           
     |         |     tags in a doc comment                                     
  29 | ERROR   | [x] There must be exactly one blank line before the           
     |         |     tags in a doc comment                                     
  32 | ERROR   | [ ] Missing short description in doc comment                  
  42 | WARNING | [ ] \Drupal calls should be avoided in classes, use           
     |         |     dependency injection instead                              
  58 | ERROR   | [x] Expected 1 blank line after function; 0 found             
  67 | ERROR   | [x] Use null coalesce operator instead of ternary             
     |         |     operator.                                                 
  77 | ERROR   | [x] Use null coalesce operator instead of ternary             
     |         |     operator.                                                 
  78 | ERROR   | [x] Short array syntax must be used to define arrays          
  87 | ERROR   | [x] Array indentation error, expected 6 spaces but            
     |         |     found 8                                                   
 100 | ERROR   | [x] Expected 1 blank line after function; 2 found             
 106 | ERROR   | [ ] Missing parameter comment                                 
 107 | ERROR   | [x] Separate the @param and @return sections by a             
     |         |     blank line.                                               
 107 | ERROR   | [ ] Description for the @return value is missing              
 112 | ERROR   | [x] Expected one space after the comma, 0 found               
 123 | WARNING | [ ] Avoid backslash escaping in translatable strings          
     |         |     when possible, use "" quotes instead                      
 139 | ERROR   | [ ] Doc comment short description must end with a             
     |         |     full stop                                                 
 139 | ERROR   | [ ] Doc comment short description must be on a                
     |         |     single line, further text should be a separate            
     |         |     paragraph                                                 
 140 | ERROR   | [x] There must be exactly one blank line before the           
     |         |     tags in a doc comment                                     
 140 | ERROR   | [ ] Missing parameter comment                                 
 140 | ERROR   | [ ] Missing parameter type                                    
 141 | ERROR   | [x] Separate the @param and @return sections by a             
     |         |     blank line.                                               
 141 | ERROR   | [ ] Description for the @return value is missing              
 149 | ERROR   | [ ] Doc comment short description must end with a             
     |         |     full stop                                                 
 149 | ERROR   | [ ] Doc comment short description must be on a                
     |         |     single line, further text should be a separate            
     |         |     paragraph                                                 
 150 | ERROR   | [x] There must be exactly one blank line before the           
     |         |     tags in a doc comment                                     
 150 | ERROR   | [ ] Missing parameter comment                                 
 150 | ERROR   | [ ] Missing parameter type                                    
 151 | ERROR   | [x] Separate the @param and @return sections by a             
     |         |     blank line.                                               
 151 | ERROR   | [ ] Description for the @return value is missing              
 159 | ERROR   | [x] There must be exactly one blank line before the           
     |         |     tags in a doc comment                                     
 159 | ERROR   | [ ] Missing parameter comment                                 
 159 | ERROR   | [ ] Missing parameter type                                    
 160 | ERROR   | [x] Separate the @param and @return sections by a             
     |         |     blank line.                                               
 160 | ERROR   | [ ] Description for the @return value is missing              
 177 | ERROR   | [x] There must be exactly one blank line before the           
     |         |     tags in a doc comment                                     
 177 | ERROR   | [ ] Missing parameter comment                                 
 177 | ERROR   | [ ] Missing parameter type                                    
 178 | ERROR   | [x] Separate the @param and @return sections by a             
     |         |     blank line.                                               
 178 | ERROR   | [ ] Description for the @return value is missing              
----------------------------------------------------------------------        
                                                                               
                                                                               
FILE: .../contrib/trumba/src/Plugin/Block/TrumbaMainCalendarSpudBlock.php      
----------------------------------------------------------------------         
FOUND 4 ERRORS AND 1 WARNING AFFECTING 4 LINES                                 
----------------------------------------------------------------------         
  1 | ERROR   | [x] End of line character is invalid; expected "\n"            
    |         |     but found "\r\n"                                           
 25 | WARNING | [ ] Do not pass empty strings to t()                           
 26 | ERROR   | [x] Use null coalesce operator instead of ternary              
    |         |     operator.                                                  
 52 | ERROR   | [x] Expected one space after the comma, 0 found                
 52 | ERROR   | [x] Expected one space after the comma, 0 found                
----------------------------------------------------------------------         
                                                                               
                                                                               
FILE: .../modules/contrib/trumba/src/Plugin/Block/TrumbaOpenSpudBlock.php      
----------------------------------------------------------------------         
FOUND 5 ERRORS AND 2 WARNINGS AFFECTING 6 LINES                                
----------------------------------------------------------------------         
  1 | ERROR   | [x] End of line character is invalid; expected "\n"            
    |         |     but found "\r\n"                                           
 22 | WARNING | [ ] Translatable strings must not begin or end with            
    |         |     white spaces, use placeholders with t() for                
    |         |     variables                                                  
 29 | ERROR   | [x] Use null coalesce operator instead of ternary              
    |         |     operator.                                                  
 33 | WARNING | [x] A comma should follow the last multiline array             
    |         |     item. Found: TRUE                                          
 39 | ERROR   | [x] Use null coalesce operator instead of ternary              
    |         |     operator.                                                  
 69 | ERROR   | [x] Expected one space after the comma, 0 found                
 69 | ERROR   | [x] Expected one space after the comma, 0 found                
----------------------------------------------------------------------
                                                                               
FILE: .../contrib/trumba/src/Plugin/Block/TrumbaPromoControlSpudBlock.php      
----------------------------------------------------------------------         
FOUND 8 ERRORS AND 4 WARNINGS AFFECTING 9 LINES                                
----------------------------------------------------------------------         
  1 | ERROR   | [x] End of line character is invalid; expected "\n"            
    |         |     but found "\r\n"                                           
 23 | WARNING | [ ] Translatable strings must not begin or end with            
    |         |     white spaces, use placeholders with t() for                
    |         |     variables                                                  
 29 | ERROR   | [x] Short array syntax must be used to define arrays           
 29 | ERROR   | [x] The first index in a multi-value array must be on          
    |         |     a new line                                                 
 35 | ERROR   | [x] Closing parenthesis of array declaration must be           
    |         |     on a new line                                              
 36 | ERROR   | [x] Use null coalesce operator instead of ternary              
    |         |     operator.                                                  
 41 | WARNING | [ ] t() calls should be avoided in classes, use                
    |         |     \Drupal\Core\StringTranslation\StringTranslationTrait      
    |         |     and $this->t() instead                                     
 41 | WARNING | [x] A comma should follow the last multiline array             
    |         |     item. Found: )                                             
 47 | ERROR   | [x] Use null coalesce operator instead of ternary              
    |         |     operator.                                                  
 74 | WARNING | [x] A comma should follow the last multiline array             
    |         |     item. Found: ]                                             
 76 | ERROR   | [x] Expected one space after the comma, 0 found                
 76 | ERROR   | [x] Expected one space after the comma, 0 found                
----------------------------------------------------------------------         
                                                                               
Time: 2.97 secs; Memory: 12MB                                                  
📌 Task
Status

RTBC

Version

2.0

Component

Code

Created by

🇮🇳India Ujjval Kumar Jha

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

Comments & Activities

  • Issue created by @Ujjval Kumar Jha
  • 🇮🇳India Ujjval Kumar Jha

    Coding standards fixed in attached patch.

  • Status changed to Needs review over 1 year ago
  • Status changed to Needs work over 1 year ago
  • 🇮🇳India akshay.singh Noida

    after applying the patch, still there are some left over issues.
    PFA

    I am working on those and will raise a MR with changes.

    FILE: trumba/trumba.module
    --------------------------------------------------------------------------------------------------------------------------------
    FOUND 4 ERRORS AND 1 WARNING AFFECTING 5 LINES
    --------------------------------------------------------------------------------------------------------------------------------
      9 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Cache\CacheableMetadata.
     31 | ERROR   | [x] Parameter comment indentation must be 3 spaces, found 4 spaces
     33 | ERROR   | [x] Parameter comment indentation must be 3 spaces, found 4 spaces
     58 | ERROR   | [x] Short array syntax must be used to define arrays
     62 | WARNING | [x] A comma should follow the last multiline array item. Found: ''
    --------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: trumba/trumba.links.menu.yml
    -------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -------------------------------------------------------------------------------
     6 | ERROR | [x] Expected 1 newline at end of file; 2 found
    -------------------------------------------------------------------------------
    
    
    FILE: trumba/trumba.routing.yml
    ----------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------
     9 | ERROR | [x] Expected 1 newline at end of file; 2 found
    ----------------------------------------------------------------------------
    
    
    FILE: trumba/src/Plugin/Block/TrumbaBlockBase.php
    ---------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ---------------------------------------------------------------------------------------------------------------------
     6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Block\BlockBase.
    ---------------------------------------------------------------------------------------------------------------------
    
  • @akshaysingh opened merge request.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India akshay.singh Noida

    Please review.
    Changes are done and MR has been created.

    Thanks

  • Status changed to Needs work over 1 year ago
  • 🇵🇭Philippines roberttabigue

    Hi @akshay.singh,

    After applying the latest MR !3 to the Trumba module against 2.0.1 on Drupal 9.5.10, not all of the PHPCS errors were resolved.

    I ran this command on the module:
    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml trumba/

    Please see the attached file.

    Moving this now to Needs work for now.

    Thank you.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India aayushDrupal

    I have created a patch for the remaining errors.
    Please review.

  • Status changed to RTBC over 1 year ago
  • 🇮🇳India Nitinkumar_7

    Hi @aayushDrupal ,
    i have applied merge request !3
    These are the steps I followed:
    1. Took clone from git version 2.0.1 in drupal 9.5.10
    2. Ran this command:
    ./vendor/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig modules/contrib/trumba
    3. Applied this MR !3 and again ran phpcs command.
    I found no error. Moving it to RTBC.

Production build 0.71.5 2024