Fix the errors/warnings reported by PHP_CodeSniffer

Created on 15 January 2024, 10 months ago
Updated 12 September 2024, 2 months ago

Problem/Motivation

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

Steps to reproduce

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

Report:

FILE: /home/contribution/drupal/web/modules/contrib/seo_pager/src/SeoPagerService.php
----------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 6 WARNINGS AFFECTING 6 LINES
----------------------------------------------------------------------------------------------
  59 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
  64 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
  65 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
  69 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
  70 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
 103 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
----------------------------------------------------------------------------------------------
šŸ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡³India realsp

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 @realsp
  • Merge request !1Fixed phpcs issues in files ā†’ (Open) created by realsp
  • Issue was unassigned.
  • Status changed to Needs review 10 months ago
  • šŸ‡®šŸ‡³India realsp

    I've fixed the phpcs issues, Please review the MR.
    Thank you.

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

    Hi @realsp,

    I applied MR!1, it not applied smoothly but fixed most of the phpcs issues.

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

    āžœ  seo_pager git:(1.0.3) curl https://git.drupalcode.org/project/seo_pager/-/merge_requests/1.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  8840    0  8840    0     0  20136      0 --:--:-- --:--:-- --:--:-- 20136
    patching file README.md
    patching file seo_pager.info.yml
    patching file seo_pager.module
    Hunk #2 FAILED at 36.
    1 out of 2 hunks FAILED -- saving rejects to file seo_pager.module.rej
    patching file seo_pager.services.yml
    patching file src/SeoPagerService.php
    āžœ  seo_pager git:(1.0.3) āœ— ..
    āžœ  contrib phpcs --standard="Drupal,DrupalPractice" --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml,css,js seo_pager
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/seo_pager/seo_pager.tokens.inc
    -------------------------------------------------------------------------------------------------------------------------
    FOUND 7 ERRORS AFFECTING 5 LINES
    -------------------------------------------------------------------------------------------------------------------------
     26 | ERROR | [x] The first parameter of a multi-line function declaration must be on the line after the opening bracket
     27 | ERROR | [x] Multi-line function declaration not indented correctly; expected 2 spaces but found 26
     28 | ERROR | [x] Multi-line function declaration not indented correctly; expected 2 spaces but found 26
     29 | ERROR | [x] Multi-line function declaration not indented correctly; expected 2 spaces but found 26
     30 | ERROR | [x] Multi-line function declaration not indented correctly; expected 2 spaces but found 26
     30 | ERROR | [x] Multi-line function declarations must have a trailing comma after the last parameter
     30 | ERROR | [x] The closing parenthesis of a multi-line function declaration must be on a new line
    -------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/seo_pager/seo_pager.module
    -----------------------------------------------------------------------------------------------
    FOUND 15 ERRORS AFFECTING 14 LINES
    -----------------------------------------------------------------------------------------------
     46 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     47 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     48 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 6
     49 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     50 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     51 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     52 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 6
     53 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     54 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     55 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     56 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 6
     57 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
     61 | ERROR | [x] You must use "/**" style comments for a function comment
     61 | ERROR | [x] Expected 1 space before opening brace; found 0
     63 | ERROR | [x] Expected 1 newline at end of file; 2 found
    -----------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 15 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal-org-issues/web/modules/contrib/seo_pager/src/SeoPagerService.php
    --------------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    --------------------------------------------------------------------------------------------------------
     96 | ERROR | [x] Multi-line function declarations must have a trailing comma after the last parameter
     97 | ERROR | [x] Multi-line function declaration not indented correctly; expected 2 spaces but found 4
    --------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------
    
    Time: 164ms; Memory: 10MB
    
    āžœ  contrib

    Thank you.

  • Status changed to Needs review 2 months ago
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi,

    Pleae review MR!1. Thank you.

Production build 0.71.5 2024