Fix the issues reported by phpcs

Created on 7 April 2023, about 1 year ago
Updated 20 May 2023, about 1 year ago

Problem/Motivation

Getting following error/warnings.

FILE: /var/www/html/modules/contrib/keyboard_shortcuts/README.md
----------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------
3 | WARNING | Line exceeds 80 characters; contains 107 characters
17 | WARNING | Line exceeds 80 characters; contains 94 characters
----------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/keyboard_shortcuts/keyboard_shortcuts.module
----------------------------------------------------------------------------------------------------------------------------------
FOUND 8 ERRORS AND 3 WARNINGS AFFECTING 8 LINES
----------------------------------------------------------------------------------------------------------------------------------
4 | ERROR | [x] The second line in the file doc comment must be "@file"
20 | ERROR | [x] Expected 1 space before "="; 0 found
20 | ERROR | [x] Expected 1 space after "="; 0 found
44 | WARNING | [ ] Only string literals should be passed to t() where possible
46 | WARNING | [x] A comma should follow the last multiline array item. Found: '/admin/config/user-interface/keyboard-shortcuts'
54 | WARNING | [ ] Hook implementations should not duplicate @param documentation
54 | ERROR | [ ] Missing parameter comment
54 | ERROR | [ ] Missing parameter type
66 | ERROR | [x] There should be no white space after an opening "("
75 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
77 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
----------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/keyboard_shortcuts/src/Form/KeyboardShortcutsSettingsForm.php
-------------------------------------------------------------------------------------------------------------------------------
FOUND 42 ERRORS AND 13 WARNINGS AFFECTING 45 LINES
-------------------------------------------------------------------------------------------------------------------------------
9 | ERROR | [x] Missing class doc comment
30 | ERROR | [ ] Description for the @return value is missing
62 | WARNING | [ ] Role::loadMultiple calls should be avoided in classes, use dependency injection instead
63 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
68 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
89 | ERROR | [x] Short array syntax must be used to define arrays
93 | WARNING | [x] A comma should follow the last multiline array item. Found: )
96 | ERROR | [x] Short array syntax must be used to define arrays
101 | WARNING | [x] A comma should follow the last multiline array item. Found: true
101 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
104 | ERROR | [x] Short array syntax must be used to define arrays
109 | WARNING | [x] A comma should follow the last multiline array item. Found: true
109 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
112 | ERROR | [x] Short array syntax must be used to define arrays
121 | ERROR | [x] Short array syntax must be used to define arrays
129 | ERROR | [x] Short array syntax must be used to define arrays
136 | ERROR | [x] Short array syntax must be used to define arrays
143 | ERROR | [x] Short array syntax must be used to define arrays
149 | WARNING | [x] A comma should follow the last multiline array item. Found: true
149 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "true"
152 | ERROR | [x] Short array syntax must be used to define arrays
156 | WARNING | [x] A comma should follow the last multiline array item. Found: )
161 | ERROR | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
162 | ERROR | [x] Short array syntax must be used to define arrays
166 | ERROR | [x] Short array syntax must be used to define arrays
167 | WARNING | [ ] #options values usually have to run through t() for translation
168 | WARNING | [ ] #options values usually have to run through t() for translation
169 | WARNING | [ ] #options values usually have to run through t() for translation
173 | ERROR | [x] Concat operator must be surrounded by a single space
173 | ERROR | [x] Concat operator must be surrounded by a single space
177 | ERROR | [x] Short array syntax must be used to define arrays
184 | ERROR | [x] Concat operator must be surrounded by a single space
184 | ERROR | [x] Concat operator must be surrounded by a single space
190 | ERROR | [x] Short array syntax must be used to define arrays
197 | ERROR | [x] Concat operator must be surrounded by a single space
197 | ERROR | [x] Concat operator must be surrounded by a single space
199 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
206 | ERROR | [x] Short array syntax must be used to define arrays
213 | ERROR | [x] Concat operator must be surrounded by a single space
213 | ERROR | [x] Concat operator must be surrounded by a single space
226 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
244 | WARNING | [ ] Only string literals should be passed to t() where possible
244 | WARNING | [x] A comma should follow the last multiline array item. Found: )
259 | ERROR | [x] There should be no white space before a closing ")"
259 | ERROR | [x] Expected 0 spaces before closing parenthesis; 1 found
267 | ERROR | [x] Expected 1 space after FUNCTION keyword; 0 found
275 | ERROR | [x] Expected 1 space after FOREACH keyword; 0 found
282 | ERROR | [x] Expected 1 space after comma in argument list; 2 found
282 | ERROR | [x] Expected one space after the comma, 2 found
298 | ERROR | [x] Missing function doc comment
306 | ERROR | [x] Missing function doc comment
310 | ERROR | [x] Missing function doc comment
320 | ERROR | [x] Missing function doc comment
335 | ERROR | [x] Expected 1 blank line after function; 0 found
336 | ERROR | [x] The closing brace for the class must have an empty line before it
-------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 49 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------

Time: 2.2 secs; Memory: 6MB

Steps to reproduce

Run following command

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

Proposed resolution

Above error/warnings need to be fixed.

๐Ÿ“Œ Task
Status

Needs review

Version

1.1

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

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 @samit.310@gmail.com
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

    Above errors/warnings has been fixed.

  • Issue was unassigned.
  • Status changed to RTBC about 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines kenyoOwen

    Hi samit.310@gmail.com

    I applied patch #2 to the โ€œKeyboard shortcutsโ€ module against Version 1.1.x-dev and confirmed that the errors and warnings are resolved. Please see the screenshots attached.

    For your review.
    Thank you.

  • Status changed to Needs work about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    +/**
    + * Admin config form for Keyboard shortcuts module.
    + */
     class KeyboardShortcutsSettingsForm extends ConfigFormBase {/

    Description for classes must not say which module implements them.

    +  /**
    +   * Constructs a KeyboardShortcutsSettingsForm object.
    +   *
    +   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
    +   *   The factory for configuration objects.
    +   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
    +   *   The entityTypeManager.
    +   */
    +  public function __construct(ConfigFactoryInterface $config_factory,
    +                              EntityTypeManagerInterface $entityTypeManager) {

    The description for a constructor must start with Constructs a new followed by the class name (including its namespace), and end with object.
    Method declarations go on a single line.

        * @return \Drupal\Core\StringTranslation\TranslatableMarkup
    +   *   Description text.
        */
       protected function getDescription() {

    I am not sure that description is sufficient, but it misses a definite article.

    +  /**
    +   * Add callback.
    +   */
       public function addCallback(array &$form, FormStateInterface $form_state) {

    The parameter descriptions are missing.

    +  /**
    +   * Ajex Callback.
    +   */

    There is a typo and a work that must be spelled in lowercase letters.

    +  /**
    +   * Get the new shortcut.
    +   */
       protected function getNewShortcut() {

    The return value is not described.

  • Assigned to imustakim
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia imustakim Ahmedabad
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia imustakim Ahmedabad

    Patch updated and interdiff attached.
    Only one warning showing up because of the contructor description including namespace of the class, assuming this can be ignored.

    Please review.

    โฏ phpcs --standard="Drupal,DrupalPractice" --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml,css,js .
    
    
    FILE: /Users/specbee/Sites/Projects/keyboard_shortcuts/src/Form/KeyboardShortcutsSettingsForm.php
    -------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------
     24 | WARNING | Line exceeds 80 characters; contains 91 characters
    -------------------------------------------------------------------------------------------------
    
    Time: 197ms; Memory: 12MB
    
Production build 0.69.0 2024