Fix the errors/warnings reported by PHP_CodeSniffer

Created on 18 March 2024, 3 months ago
Updated 23 March 2024, 3 months ago

Problem/Motivation

The module must follow the correct Drupal coding standards. So, when developing it, make sure to run phpcs --standard=Drupal,DrupalPractice on the project. This will fix most issues that reviewers might find.

Steps to reproduce

Run the following command:

  1. phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml
FILE: ...ac/contribution/Drupal-site/web/modules/contrib/image_comparator/README.md
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
--------------------------------------------------------------------------------
 3 | WARNING | Line exceeds 80 characters; contains 111 characters
--------------------------------------------------------------------------------


FILE: ...Drupal-site/web/modules/contrib/image_comparator/image_comparator.info.yml
--------------------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 1 LINE
--------------------------------------------------------------------------------
 1 | WARNING | Remove "project" from the info file, it will be added by
   |         | drupal.org packaging automatically
 1 | WARNING | Remove "datestamp" from the info file, it will be added by
   |         | drupal.org packaging automatically
 1 | WARNING | Remove "version" from the info file, it will be added by
   |         | drupal.org packaging automatically
--------------------------------------------------------------------------------


FILE: .../contrib/image_comparator/src/Services/ImageComparatorServiceInterface.php
--------------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 2 LINES
--------------------------------------------------------------------------------
 3 | ERROR | [x] Missing interface doc comment
 4 | ERROR | [x] Missing function doc comment
 4 | ERROR | [x] Expected 1 blank line before function; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------


FILE: ...b/modules/contrib/image_comparator/src/Services/ImageComparatorService.php
--------------------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
--------------------------------------------------------------------------------
  5 | ERROR | [x] Missing class doc comment
  7 | ERROR | [ ] Missing member variable doc comment
  9 | ERROR | [x] Missing function doc comment
 13 | ERROR | [x] Missing function doc comment
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 65ms; Memory: 8MB
๐Ÿ“Œ Task
Status

Needs review

Version

1.0

Component

Code

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @sunil_lnwebworks
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Mohd Sahzad

    Mohd Sahzad โ†’ made their first commit to this issueโ€™s fork.

  • Status changed to Needs review 3 months ago
  • I had attached the patch file for the above Phpcs issues.

  • Merge request !2fixed PHPCS Issues โ†’ (Open) created by Mohd Sahzad
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Preethy_ray

    Hi,
    I applied the patch, but it is throwing the following errors.

    git apply -v 3431293-phpcs-issue-fixed.patch
    3431293-phpcs-issue-fixed.patch:9: trailing whitespace.
    This module uses sapientpro/image-comparator library
    Checking patch README.md...
    error: README.md: No such file or directory
    Checking patch src/Services/ImageComparatorService.php...
    error: src/Services/ImageComparatorService.php: No such file or directory
    Checking patch src/Services/ImageComparatorServiceInterface.php...
    error: src/Services/ImageComparatorServiceInterface.php: No such file or directory
    

    Thank You!!

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • Pipeline finished with Success
    3 months ago
    Total: 168s
    #126896
  • Pipeline finished with Success
    3 months ago
    Total: 138s
    #126915
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines clarkssquared

    Hi

    I applied MR !2 and I confirmed it fixes most of the PHPCS but there is line exceeding character warning.

    โžœ  image_comparator git:(1.0.x) curl https://git.drupalcode.org/project/image_comparator/-/merge_requests/2.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  9185    0  9185    0     0  13861      0 --:--:-- --:--:-- --:--:-- 13980
    patching file .gitlab-ci.yml
    patching file image_comparator.info.yml
    patching file 'src/Services/ImageComparatorService.php'
    patching file 'src/Services/ImageComparatorServiceInterface.php'
    โžœ  image_comparator git:(1.0.x) โœ— ..
    โžœ  contrib git:(master) โœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml image_comparator 
    
    FILE: ...subing/Projects/d9/d9-local/web/modules/contrib/image_comparator/README.md
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     3 | WARNING | Line exceeds 80 characters; contains 111 characters
    --------------------------------------------------------------------------------
    
    Time: 201ms; Memory: 10MB
    
    โžœ  contrib git:(master) โœ— 

    I will retain the status to needs review so that others can test it, and also to hear from the maintainer if this warning is intentional or intended for some purposes.

Production build 0.69.0 2024