Drupal Coding Standards Issues | phpcs

Created on 30 January 2023, almost 2 years ago
Updated 15 August 2024, 3 months ago

Problem/Motivation

Getting following error/warnings

FILE: /var/www/html/modules/contrib/twitter_feed/twitter_feed.module
---------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------------------------------------------------------------------
140 | ERROR | The array declaration extends to column 140 (the limit is 80). The array content should be split up over multiple lines
---------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/twitter_feed/src/Form/TwitterFeedConfigForm.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------------------------
14 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
83 | WARNING | Possible useless method overriding detected
-----------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/twitter_feed/src/Plugin/Block/TwitterFeedBlock.php
----------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 3 WARNINGS AFFECTING 4 LINES
----------------------------------------------------------------------------------------------------------
29 | ERROR | [ ] Parameter $http_client is not described in comment
120 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
175 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
194 | WARNING | [x] 'TODO set per-block cache time.' should match the format '@todo Fix problem X here.'
----------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------

Time: 483ms; 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/twitter_feed/

Proposed resolution

Above error/warnings need to be fixed.

šŸ“Œ Task
Status

Needs work

Version

2.0

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
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • šŸ‡®šŸ‡³India samit.310@gmail.com

    Above error/warnings are fixed.

  • Assigned to Charchil Khandelwal
  • šŸ‡®šŸ‡³India Charchil Khandelwal

    I will review this.

  • @charchil-khandelwal opened merge request.
  • Issue was unassigned.
  • šŸ‡®šŸ‡³India Charchil Khandelwal

    Patch #2 applied cleanly, all the errors and warnings are fixed now.
    Created MR for this, please review.

    Thank You.

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

    Hi,

    I applied patch #2, it was not applied cleanly and did not fix all the phpcs issues.

    āžœ  twitter_feed git:(2.0.1) curl https://www.drupal.org/files/issues/2023-01-30/3337441-2.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  5007  100  5007    0     0  19274      0 --:--:-- --:--:-- --:--:-- 19257
    patching file src/Form/TwitterFeedConfigForm.php
    Hunk #1 succeeded at 9 with fuzz 1 (offset 1 line).
    Hunk #2 succeeded at 95 (offset 18 lines).
    patching file src/Plugin/Block/TwitterFeedBlock.php
    patching file twitter_feed.module
    āžœ  twitter_feed git:(2.0.1) āœ— ..
    āžœ  contrib phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml twitter_feed
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/twitter_feed/src/Form/TwitterFeedConfigForm.php
    ------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------
     9 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Render\RendererInterface.
    ------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/twitter_feed/src/Plugin/Block/TwitterFeedBlock.php
    ------------------------------------------------------------------------------------------------------------------------------------
    FOUND 7 ERRORS AFFECTING 6 LINES
    ------------------------------------------------------------------------------------------------------------------------------------
     11 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Config\ConfigFactoryInterface.
     52 | ERROR | [x] Multi-line function declaration not indented correctly; expected 4 spaces but found 8
     53 | ERROR | [x] Multi-line function declaration not indented correctly; expected 4 spaces but found 8
     54 | ERROR | [x] Multi-line function declaration not indented correctly; expected 4 spaces but found 8
     55 | ERROR | [x] Multi-line function declaration not indented correctly; expected 4 spaces but found 8
     56 | ERROR | [x] Multi-line function declaration not indented correctly; expected 4 spaces but found 8
     56 | ERROR | [x] Multi-line function declarations must have a trailing comma after the last parameter
    ------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------------------
    
    Time: 202ms; Memory: 10MB
    
    āžœ  contrib

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

    These are the issues remaining after I ran phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml:

    āžœ  twitter_feed git:(2.0.1) curl https://git.drupalcode.org/project/twitter_feed/-/merge_requests/2.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  5145    0  5145    0     0  10709      0 --:--:-- --:--:-- --:--:-- 10718
    patching file src/Form/TwitterFeedConfigForm.php
    patching file src/Plugin/Block/TwitterFeedBlock.php
    patching file twitter_feed.module
    āžœ  twitter_feed git:(2.0.1) āœ— ..
    āžœ  contrib phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml twitter_feed
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/twitter_feed/src/Form/TwitterFeedConfigForm.php
    ------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------
     9 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Render\RendererInterface.
    ------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/twitter_feed/src/Plugin/Block/TwitterFeedBlock.php
    -----------------------------------------------------------------------------------------------------------------------
    FOUND 7 ERRORS AFFECTING 6 LINES
    -----------------------------------------------------------------------------------------------------------------------
     10 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is GuzzleHttp\ClientInterface.
     52 | ERROR | [x] Multi-line function declaration not indented correctly; expected 4 spaces but found 8
     53 | ERROR | [x] Multi-line function declaration not indented correctly; expected 4 spaces but found 8
     54 | ERROR | [x] Multi-line function declaration not indented correctly; expected 4 spaces but found 8
     55 | ERROR | [x] Multi-line function declaration not indented correctly; expected 4 spaces but found 8
     56 | ERROR | [x] Multi-line function declaration not indented correctly; expected 4 spaces but found 8
     56 | ERROR | [x] Multi-line function declarations must have a trailing comma after the last parameter
    -----------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------------------
    
    Time: 215ms; Memory: 10MB
    
    āžœ  contrib

    Thank you.

Production build 0.71.5 2024