Fix the issue reported by phpcs

Created on 27 September 2023, 9 months ago
Updated 29 May 2024, 28 days ago

Problem/Motivation

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

Report:

FILE: /home/contribution/drupal/web/modules/contrib/weather_wave/src/Plugin/Block/WeatherWaveBlock.php
--------------------------------------------------------------------------------------------------------------------------------------
FOUND 29 ERRORS AND 12 WARNINGS AFFECTING 29 LINES
--------------------------------------------------------------------------------------------------------------------------------------
  1 | ERROR   | [x] The PHP open tag must be followed by exactly one blank line
  1 | ERROR   | [x] Whitespace found at end of line
  2 | ERROR   | [x] Namespaced classes, interfaces and traits should not begin with a file doc comment
  7 | ERROR   | [x] Line indented incorrectly; expected 0 spaces, found 1
  9 | ERROR   | [x] Line indented incorrectly; expected 0 spaces, found 1
 10 | WARNING | [x] Unused use statement
 10 | ERROR   | [x] Line indented incorrectly; expected 0 spaces, found 1
 11 | WARNING | [x] Unused use statement
 11 | ERROR   | [x] Line indented incorrectly; expected 0 spaces, found 1
 12 | WARNING | [x] Unused use statement
 12 | ERROR   | [x] Line indented incorrectly; expected 0 spaces, found 1
 13 | WARNING | [x] Unused use statement
 13 | ERROR   | [x] Line indented incorrectly; expected 0 spaces, found 1
 13 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Config\ConfigFactoryInterface.
 14 | WARNING | [x] Unused use statement
 14 | ERROR   | [x] Line indented incorrectly; expected 0 spaces, found 1
 15 | WARNING | [x] Unused use statement
 15 | ERROR   | [x] Line indented incorrectly; expected 0 spaces, found 1
 16 | ERROR   | [x] Whitespace found at end of line
 19 | ERROR   | [x] Whitespace found at end of line
 26 | ERROR   | [x] Expected 1 space before opening brace; found 0
 46 | ERROR   | [x] There must be no blank lines after the function comment
 49 | ERROR   | [x] Line indented incorrectly; expected 4 spaces, found 2
 50 | ERROR   | [x] Whitespace found at end of line
 52 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 53 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 53 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 54 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 57 | ERROR   | [x] Concat operator must be surrounded by a single space
 57 | ERROR   | [x] Concat operator must be surrounded by a single space
 58 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 59 | ERROR   | [x] Expected one space after the comma, 0 found
 59 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "True"
 62 | ERROR   | [x] Expected 1 space after "="; 2 found
 63 | ERROR   | [x] Short array syntax must be used to define arrays
 64 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 65 | ERROR   | [x] Expected 1 space after "="; 2 found
 66 | ERROR   | [x] Whitespace found at end of line
 67 | ERROR   | [x] Whitespace found at end of line
 68 | ERROR   | [x] Expected 1 newline at end of file; 0 found
 68 | ERROR   | [x] The closing brace for the class must have an empty line before it
--------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 35 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/weather_wave/src/Controller/WeatherForecastController.php
----------------------------------------------------------------------------------------------------------------------------------
FOUND 13 ERRORS AND 5 WARNINGS AFFECTING 13 LINES
----------------------------------------------------------------------------------------------------------------------------------
  6 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Controller\ControllerBase.
  7 | WARNING | [x] Unused use statement
  9 | WARNING | [x] Unused use statement
 10 | WARNING | [x] Unused use statement
 11 | WARNING | [x] Unused use statement
 13 | ERROR   | [x] Missing class doc comment
 13 | ERROR   | [x] Expected 1 space before opening brace; found 2
 17 | ERROR   | [x] Expected 1 blank line before function; 0 found
 19 | ERROR   | [x] Expected 1 space before "?"; 0 found
 21 | ERROR   | [x] Expected 1 space after "="; 0 found
 21 | ERROR   | [x] Concat operator must be surrounded by a single space
 21 | ERROR   | [x] Concat operator must be surrounded by a single space
 22 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 24 | ERROR   | [x] Expected one space after the comma, 0 found
 24 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "TRUE" but found "True"
 31 | ERROR   | [x] Whitespace found at end of line
 35 | ERROR   | [x] Expected 1 newline at end of file; 0 found
 35 | ERROR   | [x] The closing brace for the class must have an empty line before it
----------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 17 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/weather_wave/src/Form/WeatherWaveForm.php
---------------------------------------------------------------------------------------------------------------------------------------------
FOUND 37 ERRORS AND 11 WARNINGS AFFECTING 36 LINES
---------------------------------------------------------------------------------------------------------------------------------------------
  7 | WARNING | [x] Unused use statement
  8 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Entity\Element\EntityAutocomplete.
  9 | WARNING | [x] Unused use statement
 12 | ERROR   | [x] Function comment short description must start with exactly one space
 12 | ERROR   | [x] Doc comment short description must end with a full stop
 13 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
 13 | ERROR   | [x] There must be exactly one newline after the Class comment
 15 | ERROR   | [x] PHP keywords must be lowercase; expected "class" but found "Class"
 19 | ERROR   | [x] Expected 1 blank line before function; 0 found
 20 | ERROR   | [x] Opening brace should be on the same line as the declaration
 21 | ERROR   | [x] Language constructs must be followed by a single space; expected "return [" but found "return["
 24 | ERROR   | [x] Expected 1 blank line after function; 0 found
 28 | ERROR   | [x] Expected 1 space before opening brace; found 0
 31 | ERROR   | [x] Whitespace found at end of line
 32 | ERROR   | [x] Expected 1 blank line after function; 0 found
 34 | ERROR   | [x] Whitespace found at end of line
 35 | ERROR   | [x] Whitespace found at end of line
 36 | ERROR   | [x] Expected 1 space before opening brace; found 0
 37 | ERROR   | [x] Whitespace found at end of line
 39 | ERROR   | [x] Expected 1 space before "?"; 0 found
 40 | ERROR   | [x] Expected 1 space before "?"; 0 found
 59 | ERROR   | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE" but found "False"
 59 | ERROR   | [x] Comments may not appear after statements
 65 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
 66 | WARNING | [ ] Line exceeds 80 characters; contains 91 characters
 66 | ERROR   | [x] Comments may not appear after statements
 71 | ERROR   | [x] Whitespace found at end of line
 73 | ERROR   | [x] Expected 1 blank line after function; 0 found
 77 | ERROR   | [x] Expected 1 space before opening brace; found 0
 78 | WARNING | [ ] Unused variable $form_value.
 79 | ERROR   | [x] Expected 1 space before ":"; 0 found
 80 | WARNING | [ ] Unused variable $article_id.
 84 | ERROR   | [x] Object operator not indented correctly; expected 6 spaces but found 9
 84 | ERROR   | [x] Expected one space after the comma, 0 found
 85 | ERROR   | [x] Expected one space after the comma, 0 found
 87 | ERROR   | [x] Expected 1 blank line after function; 0 found
 91 | ERROR   | [x] Visibility must be declared on method "weather_wave_reset_form_submit"
 91 | ERROR   | [ ] Method name "WeatherWaveForm::weather_wave_reset_form_submit" is not in lowerCamel format
 91 | ERROR   | [x] Namespaced classes/interfaces/traits should be referenced with use statements
 92 | WARNING | [x] There must be no blank line following an inline comment
 92 | WARNING | [ ] There must be no blank line following an inline comment
 94 | WARNING | [ ] Unused variable $cityFieldValue.
 94 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
 97 | ERROR   | [x] Line indented incorrectly; expected 6 spaces, found 4
 97 | ERROR   | [x] Object operator not indented correctly; expected 6 spaces but found 4
 97 | ERROR   | [x] Expected one space after the comma, 0 found
 99 | ERROR   | [x] Expected 1 newline at end of file; 0 found
 99 | ERROR   | [x] The closing brace for the Class must have an empty line before it
---------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 39 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/weather_wave/weather_wave.module
------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 8 ERRORS AND 1 WARNING AFFECTING 8 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------------
 10 | ERROR   | [x] There must be no blank lines after the function comment
 12 | ERROR   | [x] Expected 1 space before opening brace; found 0
 13 | ERROR   | [x] Language constructs must be followed by a single space; expected "return [" but found "return["
 20 | ERROR   | [x] Array closing indentation error, expected 6 spaces but found 4
 24 | ERROR   | [x] Expected 1 blank line after function; 0 found
 24 | ERROR   | [x] Whitespace found at end of line
 26 | WARNING | [ ] Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar()
    |         |     for xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block
    |         |     templates."
 28 | ERROR   | [x] Namespaced classes/interfaces/traits should be referenced with use statements
 35 | ERROR   | [x] Expected 1 newline at end of file; 0 found
------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 8 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/weather_wave/weather_wave.routing.yml
----------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
----------------------------------------------------------------------------------------------------------------------
  8 | WARNING | [ ] Open page callback found, please add a comment before the line why there is no access restriction
 16 | ERROR   | [x] Expected 1 newline at end of file; 0 found
----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/weather_wave/weather_wave.libraries.yml
-----------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------
 10 | ERROR | [x] Expected 1 newline at end of file; 2 found
-----------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/weather_wave/weather_wave.links.menu.yml
------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------
 6 | ERROR | [x] Expected 1 newline at end of file; 0 found
------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------


FILE: /home/contribution/drupal/web/modules/contrib/weather_wave/weather_wave.permissions.yml
-------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------
 4 | ERROR | [x] Expected 1 newline at end of file; 0 found
-------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------

Steps to reproduce

Run following command:

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

Proposed resolution

Above error/warnings need to be fixed.

๐Ÿ“Œ Task
Status

Needs work

Version

1.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia arti_parmar

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 @arti_parmar
  • Issue was unassigned.
  • Status changed to Needs review 9 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia arti_parmar

    Kindly review patch.

  • Status changed to Needs work 8 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia mrinalini9 New Delhi

    Hi,

    Patch #2 is no longer applicable, need to reroll this.
    So, moving this to Needs Work.

    Thanks!

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia zkhan.aamir

    zkhan.aamir โ†’ made their first commit to this issueโ€™s fork.

  • Status changed to Needs review 8 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia zkhan.aamir

    Fixed phpcs issue and commit the code. please review

  • Assigned to realsp
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia realsp
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia realsp
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia realsp
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia realsp

    #5 fixes some phpcs issues, The following errors are still showing:

    FILE: /home/contribution/drupal/web/modules/contrib/weather_wave-3390078/src/Plugin/Block/WeatherWaveBlock.php
    ------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 6 WARNINGS AFFECTING 5 LINES
    ------------------------------------------------------------------------------------------------------------
     41 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     42 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     42 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     43 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     47 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     53 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    ------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/contribution/drupal/web/modules/contrib/weather_wave-3390078/src/Controller/WeatherForecastController.php
    -------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------
     22 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    -------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/contribution/drupal/web/modules/contrib/weather_wave-3390078/src/Form/WeatherWaveForm.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 5 WARNINGS AFFECTING 4 LINES
    -----------------------------------------------------------------------------------------------------------------------------------------
     65 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
     80 | WARNING | Unused variable $form_value.
     82 | WARNING | Unused variable $article_id.
     96 | WARNING | Unused variable $cityFieldValue.
     96 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    -----------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /home/contribution/drupal/web/modules/contrib/weather_wave-3390078/weather_wave.routing.yml
    -----------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------
     8 | WARNING | Open page callback found, please add a comment before the line why there is no access restriction
    -----------------------------------------------------------------------------------------------------------------
    
  • Merge request !1Resolve #3390078 "Phpcs issues" โ†’ (Open) created by realsp
  • Issue was unassigned.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia realsp

    The following values can be removed:

    FILE: /home/contribution/drupal/web/modules/contrib/weather_wave/src/Form/WeatherWaveForm.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
    -----------------------------------------------------------------------------------------------------------------------------------------
     108 | WARNING | Unused variable $form_value.
     110 | WARNING | Unused variable $article_id.
     124 | WARNING | Unused variable $cityFieldValue.
     -----------------------------------------------------------------------------------------------------------------------------------------
    

    Except these issues, remaining phpcs issues are fixed, please review the MR.
    Thank you.

  • First commit to issue fork.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sourabhjain

    I have fixed warning mentioned in #11. Please review.

  • Status changed to Needs work 28 days ago
  • Hi @sourabhjain,

    Applied latest MR !1, it applied unsuccessfully

     weather_wave git:(main) โœ— curl https://git.drupalcode.org/project/weather_wave/-/merge_requests/1.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 22842    0 22842    0     0  51998      0 --:--:-- --:--:-- --:--:-- 52752
    patching file README.md
    patching file css/style.css
    patching file src/Controller/WeatherForecastController.php
    patching file src/Form/WeatherWaveForm.php
    patching file src/Plugin/Block/WeatherWaveBlock.php
    patching file weather_wave.info.yml
    Hunk #1 FAILED at 5.
    1 out of 1 hunk FAILED -- saving rejects to file weather_wave.info.yml.rej
    patching file weather_wave.libraries.yml
    patching file weather_wave.links.menu.yml
    patching file weather_wave.module
    patching file weather_wave.permissions.yml
    patching file weather_wave.routing.yml

    Kindly check

    Thank,
    Jake

Production build 0.69.0 2024