Fix the issues reported by phpcs

Created on 11 August 2023, over 1 year ago
Updated 18 July 2024, 4 months ago

Problem/Motivation

Missing coding standards

Steps to reproduce

Run the command:

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

Proposed resolution

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

FILE: /var/www/html/drupal_cms/drupal9/web/modules/contrib/fast_404/tests/src/Unit/Fast404EventSubscriberTest.php
------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------------------
 42 | WARNING | [ ] There must be no blank line following an inline comment
 42 | ERROR   | [ ] Inline comments must start with a capital letter
 42 | ERROR   | [ ] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
------------------------------------------------------------------------------------------------------------------------------


FILE: /var/www/html/drupal_cms/drupal9/web/modules/contrib/fast_404/tests/src/Unit/Fast404Test.php
------------------------------------------------------------------------------------------------------------------------------
FOUND 9 ERRORS AND 4 WARNINGS AFFECTING 6 LINES
------------------------------------------------------------------------------------------------------------------------------
 60 | ERROR   | [ ] Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead
 65 | WARNING | [ ] There must be no blank line following an inline comment
 65 | ERROR   | [ ] Inline comments must start with a capital letter
 65 | ERROR   | [ ] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 67 | ERROR   | [ ] Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead
 72 | WARNING | [ ] There must be no blank line following an inline comment
 72 | ERROR   | [ ] Inline comments must start with a capital letter
 72 | ERROR   | [ ] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
 74 | ERROR   | [ ] Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead
 79 | WARNING | [ ] There must be no blank line following an inline comment
 79 | WARNING | [ ] There must be no blank line following an inline comment
 79 | ERROR   | [ ] Inline comments must start with a capital letter
 79 | ERROR   | [ ] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/drupal_cms/drupal9/web/modules/contrib/fast_404/src/EventSubscriber/Fast404EventSubscriber.php
------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
------------------------------------------------------------------------------------------------------------------
 18 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
------------------------------------------------------------------------------------------------------------------
šŸ“Œ Task
Status

Needs work

Version

3.0

Component

Code

Created by

šŸ‡®šŸ‡³India Rohit Rana

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 @Rohit Rana
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins ā†’ Open on Drupal.org ā†’
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    6 pass
  • Assigned to akshay.singh
  • Open in Jenkins ā†’ Open on Drupal.org ā†’
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    6 pass
  • @akshaysingh opened merge request.
  • Issue was unassigned.
  • šŸ‡®šŸ‡³India akshay.singh Noida

    After applying the above patch, I still got some leftover issues which i have fixed and provided an interdiff as well.

    Raised MR for all the fixes, except the readme 84 | WARNING | Line exceeds 80 characters; contains 116 characters I think which we can ignore.

    Please review.
    Thanks

    FILE: /Users/akshaysingh/projects/dcontri/fast_404-3380617/tests/src/Unit/Fast404EventSubscriberTest.php
    -----------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------------------------------
     6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\fast404\EventSubscriber\Fast404EventSubscriber.
    -----------------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/akshaysingh/projects/dcontri/fast_404-3380617/README.txt
    ----------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    ----------------------------------------------------------------------
      84 | WARNING | Line exceeds 80 characters; contains 116 characters
     116 | WARNING | Line exceeds 80 characters; contains 81 characters
    ----------------------------------------------------------------------
    
    
    FILE: /Users/akshaysingh/projects/dcontri/fast_404-3380617/src/Fast404.php
    -------------------------------------------------------------------------------------------------------------------------
    FOUND 3 ERRORS AFFECTING 3 LINES
    -------------------------------------------------------------------------------------------------------------------------
       6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Database\Database.
     293 | ERROR | [x] Expected 1 blank line after function; 0 found
     294 | 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: /Users/akshaysingh/projects/dcontri/fast_404-3380617/src/EventSubscriber/Fast404EventSubscriber.php
    ----------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 6 ERRORS AND 3 WARNINGS AFFECTING 7 LINES
    ----------------------------------------------------------------------------------------------------------------------------------------------
      6 | ERROR   | [x] Use statements should be sorted alphabetically. The first wrong one is Symfony\Component\HttpKernel\Event\ExceptionEvent.
     30 | ERROR   | [x] Expected 3 space(s) before asterisk; 2 found
     31 | ERROR   | [x] Expected 3 space(s) before asterisk; 2 found
     32 | ERROR   | [x] Expected 3 space(s) before asterisk; 2 found
     33 | ERROR   | [x] Expected 3 space(s) before asterisk; 2 found
     41 | ERROR   | [ ] Missing parameter comment
     53 | WARNING | [x] Inline @var declarations should use the /** */ delimiters
     53 | WARNING | [x] There must be no blank line following an inline comment
     53 | WARNING | [ ] There must be no blank line following an inline comment
    ----------------------------------------------------------------------------------------------------------------------------------------------
    
  • Status changed to Needs work over 1 year ago
  • šŸ‡®šŸ‡³India aayushDrupal

    Hi @Rohit Rana,

    The steps I followed for testing are as follows.

    1) git clone --branch '8.x-3.x' https://git.drupalcode.org/project/fast_404.git
    2) cd fast_404
    3) git remote add fast_404-3380617 git@git.drupal.org:issue/fast_404-3380617.git (MR !8)
    4) git fetch fast_404-3380617
    5) git checkout -b '3380617-drupal-coding-standard' --track fast_404-3380617/'3380617-drupal-coding-standard'
    6) Ran phpcs command.

    I came across an error message that says "Line exceeds 80 characters; contains 116 characters" (line 84). So changing status to need work for now . I have attached a screenshot for your reference.

  • šŸ‡®šŸ‡³India aayushDrupal

    Solution patch for Line exceeds 80 characters; contains 116 characters" (line 84)

  • Status changed to Needs review over 1 year ago
  • Open in Jenkins ā†’ Open on Drupal.org ā†’
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 8
    last update over 1 year ago
    6 pass
  • Status changed to Needs work 4 months ago
  • Hi @aayushmankotia @akshay.singh,

    The MR!8, was applied no-really successfully, reported multiple errors. Please see below:

    fast_404 git:(8.x-3.3) curl https://git.drupalcode.org/project/fast_404/-/merge_requests/8.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  5614    0  5614    0     0  18196      0 --:--:-- --:--:-- --:--:-- 18651
    patching file README.txt
    patching file src/EventSubscriber/Fast404EventSubscriber.php
    Hunk #1 FAILED at 2.
    Hunk #2 FAILED at 27.
    Hunk #3 FAILED at 39.
    Hunk #4 FAILED at 51.
    4 out of 4 hunks FAILED -- saving rejects to file src/EventSubscriber/Fast404EventSubscriber.php.rej
    patching file src/Fast404.php
    Hunk #1 FAILED at 2.
    Hunk #2 FAILED at 291.
    2 out of 2 hunks FAILED -- saving rejects to file src/Fast404.php.rej
    patching file tests/src/Unit/Fast404EventSubscriberTest.php
    patching file tests/src/Unit/Fast404Test.php
    āžœ  fast_404 git:(8.x-3.3) āœ— cd ..
    āžœ  contrib git:(main) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig fast_404
    
    FILE: ...tInterns/Demo-site/drupal-orgissue/web/modules/contrib/fast_404/README.txt
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     84 | WARNING | Line exceeds 80 characters; contains 116 characters
    --------------------------------------------------------------------------------
    
    
    FILE: ...rns/Demo-site/drupal-orgissue/web/modules/contrib/fast_404/src/Fast404.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     115 | ERROR | [x] Inline comments must end in full-stops, exclamation marks,
         |       |     question marks, colons, or closing parentheses
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    
    FILE: ...eb/modules/contrib/fast_404/src/EventSubscriber/Fast404EventSubscriber.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
    --------------------------------------------------------------------------------
      6 | ERROR   | [x] Use statements should be sorted alphabetically. The first
        |         |     wrong one is
        |         |     Symfony\Component\HttpKernel\Event\ExceptionEvent.
     13 | WARNING | [x] Unused use statement
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    Time: 343ms; Memory: 12MB

    I also applied the patch #7 after applying the MR, it was applied successfully, but the unaddressed errors left by the MR were still reported. Please see below:

    fast_404 git:(8.x-3.3) āœ— curl https://www.drupal.org/files/issues/2023-08-12/exceeds_char-15190213-7.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100   560  100   560    0     0   2050      0 --:--:-- --:--:-- --:--:--  2129
    patching file README.txt
    āžœ  fast_404 git:(8.x-3.3) āœ— cd ..
    āžœ  contrib git:(main) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig fast_404
    
    FILE: ...rns/Demo-site/drupal-orgissue/web/modules/contrib/fast_404/src/Fast404.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     115 | ERROR | [x] Inline comments must end in full-stops, exclamation marks,
         |       |     question marks, colons, or closing parentheses
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    
    FILE: ...eb/modules/contrib/fast_404/src/EventSubscriber/Fast404EventSubscriber.php
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
    --------------------------------------------------------------------------------
      6 | ERROR   | [x] Use statements should be sorted alphabetically. The first
        |         |     wrong one is
        |         |     Symfony\Component\HttpKernel\Event\ExceptionEvent.
     13 | WARNING | [x] Unused use statement
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    Time: 327ms; Memory: 12MB

    I recommend to append your changes to the MR/patch you applied so that the reviewer will only have to apply one MR/patch.

    Thanks,
    Jake

Production build 0.71.5 2024