Fix the issues reported by phpcs

Created on 13 April 2023, over 1 year ago
Updated 19 July 2024, 5 months ago

Problem/Motivation

Getting following error/warnings.

FILE: /var/www/html/modules/contrib/delete_book/delete_book.info.yml
----------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------
7 | WARNING | All dependencies must be prefixed with the project name, for example "drupal:"
----------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/delete_book/src/Form/BookDeleteConfirmationForm.php
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 10 ERRORS AND 2 WARNINGS AFFECTING 11 LINES
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
13 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
103 | WARNING | [ ] Avoid backslash escaping in translatable strings when possible, use "" quotes instead
135 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 0
135 | ERROR | [x] 4 spaces found before inline comment; expected "// $mainBook = $storage->load($this->bookId);" but found "// $mainBook = $storage->load($this->bookId);"
136 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 0
141 | ERROR | [ ] Missing short description in doc comment
142 | ERROR | [ ] Missing parameter comment
144 | ERROR | [ ] Description for the @return value is missing
146 | ERROR | [x] Expected 1 space before opening brace; found 0
147 | ERROR | [x] Expected one space after the comma, 0 found
148 | ERROR | [x] Expected one space after the comma, 0 found
150 | ERROR | [x] Expected one space after the comma, 0 found
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 7 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/delete_book/src/Controller/BookController.php
----------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 8 WARNINGS AFFECTING 7 LINES
----------------------------------------------------------------------------------------------------------------------------------------------
11 | WARNING | [x] Unused use statement
12 | WARNING | [x] Unused use statement
14 | WARNING | [x] Unused use statement
15 | WARNING | [x] Unused use statement
77 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
77 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
90 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
105 | WARNING | [ ] t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
----------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------------------------------

Time: 1.73 secs; 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/delete_book/

Proposed resolution

Above error/warnings need to be fixed.

๐Ÿ“Œ Task
Status

RTBC

Version

1.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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @samit.310@gmail.com
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

    Above errors/warnings has been fixed.

  • Status changed to RTBC about 1 year ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany yuseferi

    Hey Akram,
    Thank you for revewing, could you please create a Merge Request?

    Best

  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Andrii Momotov

    Andrii Momotov โ†’ made their first commit to this issueโ€™s fork.

  • Assigned to Andrii Momotov
  • Status changed to Needs work 9 months ago
  • Issue was unassigned.
  • Status changed to Needs review 9 months ago
  • ๐Ÿ‡บ๐Ÿ‡ฆUkraine Andrii Momotov

    Created the MR with fixed phpcs errors. Please review.
    Thanks!

  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines cleavinjosh

    Hi @Andrii Momotov,

    I applied MR!1 and it applied cleanly.

    However, when I ran phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml I encountered an issue:

    โžœ  delete_book git:(main) โœ— curl https://git.drupalcode.org/project/delete_book/-/merge_requests/1.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  4207    0  4207    0     0  11087      0 --:--:-- --:--:-- --:--:-- 11100
    patching file delete_book.info.yml
    Hunk #1 FAILED at 4.
    1 out of 1 hunk FAILED -- saving rejects to file delete_book.info.yml.rej
    patching file src/Controller/BookController.php
    patching file src/Form/BookDeleteConfirmationForm.php
    โžœ  delete_book git:(main) โœ— ..
    โžœ  contrib git:(main) โœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml delete_book
    
    FILE: /Users/interns/Demo-site/drupal-orgissue/web/modules/contrib/delete_book/delete_book.info.yml
    -------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 2 LINES
    -------------------------------------------------------------------------------------------------------------
     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
     7 | WARNING | All dependencies must be prefixed with the project name, for example "drupal:"
    -------------------------------------------------------------------------------------------------------------
    
    Time: 136ms; Memory: 10MB
    
    โžœ  contrib git:(main) โœ—

    I will retain the status to Needs review so others can confirm as well.

    Thank you.

  • Status changed to Needs work 7 months ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines cleavinjosh
  • Status changed to RTBC 5 months ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines cleavinjosh

    Hi @Andrii Momotov,

    I apologize for my previous testing. I discovered that the warnings I encountered were because I installed the module via composer.

    I retested MR!1 and it was applied smoothly and fixed the phpcs issues.

    โžœ  delete_book git:(1.0.x) curl https://git.drupalcode.org/project/delete_book/-/merge_requests/1.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  4207    0  4207    0     0   6190      0 --:--:-- --:--:-- --:--:--  6186
    patching file delete_book.info.yml
    patching file src/Controller/BookController.php
    patching file src/Form/BookDeleteConfirmationForm.php
    โžœ  delete_book git:(1.0.x) โœ— ..
    โžœ  contrib phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml delete_book
    โžœ  contrib

    Thank you.

Production build 0.71.5 2024