Fix the issues reported by PHPCS

Created on 11 April 2023, almost 2 years ago
Updated 2 May 2023, over 1 year ago

Problem/Motivation

Fix all the issues reported by PHPCS for Drupal and DrupalPractice Coding Standards

Steps to reproduce

Execute the command: phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,js,info,txt,md,yml,twig doi_search/

Proposed resolution

Fixing all issues mentioned:

FILE: ...tml/contribution/drupal10/web/modules/contrib/doi_search/doi_search.module
--------------------------------------------------------------------------------
FOUND 10 ERRORS AND 7 WARNINGS AFFECTING 15 LINES
--------------------------------------------------------------------------------
7 | ERROR | [ ] Wrong function doc comment end; expected "*/", found "**/"
7 | ERROR | [x] Additional blank lines found at end of doc comment
7 | ERROR | [x] Expected 1 space(s) before asterisk; 0 found
16 | ERROR | [x] Expected 1 space after "=>"; 0 found
17 | ERROR | [x] Expected 1 space after "=>"; 0 found
18 | WARNING | [x] A comma should follow the last multiline array item. Found:
| | NULL
20 | WARNING | [x] A comma should follow the last multiline array item. Found:
| | 'doi-search-page'
22 | ERROR | [x] Expected 1 space after "=>"; 0 found
23 | ERROR | [x] Expected 1 space after "=>"; 0 found
24 | WARNING | [x] A comma should follow the last multiline array item. Found:
| | NULL
26 | WARNING | [x] A comma should follow the last multiline array item. Found:
| | 'doi-search-result'
28 | ERROR | [x] Expected 1 space after "=>"; 0 found
29 | ERROR | [x] Expected 1 space after "=>"; 0 found
30 | WARNING | [x] A comma should follow the last multiline array item. Found:
| | NULL
32 | WARNING | [x] A comma should follow the last multiline array item. Found:
| | 'doi-search-reference'
33 | WARNING | [x] A comma should follow the last multiline array item. Found:
| | ]
61 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 16 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...tribution/drupal10/web/modules/contrib/doi_search/src/DoiSearchManager.php
--------------------------------------------------------------------------------
FOUND 22 ERRORS AND 3 WARNINGS AFFECTING 19 LINES
--------------------------------------------------------------------------------
10 | WARNING | [ ] The class short comment should describe what the class does
| | and not simply repeat the class name
20 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 3
21 | ERROR | [x] Expected 4 space(s) before asterisk; 3 found
22 | ERROR | [x] Expected 4 space(s) before asterisk; 3 found
23 | ERROR | [x] Expected 4 space(s) before asterisk; 3 found
24 | ERROR | [x] Expected 4 space(s) before asterisk; 3 found
27 | ERROR | [ ] Parameter $http_client is not described in comment
33 | ERROR | [x] Expected 1 space between comma and type hint
| | "ClientInterface"; 0 found
33 | ERROR | [x] Expected one space after the comma, 0 found
36 | ERROR | [x] Expected 1 blank line after function; 2 found
38 | ERROR | [x] Whitespace found at end of line
40 | WARNING | [ ] Line exceeds 80 characters; contains 103 characters
41 | ERROR | [ ] Doc comment short description must end with a full stop
41 | ERROR | [ ] Doc comment short description must be on a single line,
| | further text should be a separate paragraph
42 | ERROR | [x] Whitespace found at end of line
43 | ERROR | [ ] Missing parameter comment
43 | ERROR | [ ] Missing parameter name
44 | ERROR | [x] Whitespace found at end of line
45 | ERROR | [ ] Description for the @return value must be on the next line
50 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE"
| | but found "false"
52 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
52 | ERROR | [x] Whitespace found at end of line
60 | ERROR | [x] Expected 1 space before "-"; 0 found
60 | ERROR | [x] Expected 1 space after "-"; 0 found
60 | WARNING | [ ] t() calls should be avoided in classes, use
| | \Drupal\Core\StringTranslation\StringTranslationTrait and
| | $this->t() instead
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 16 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...al10/web/modules/contrib/doi_search/src/Controller/DoiSearchController.php
--------------------------------------------------------------------------------
FOUND 72 ERRORS AND 6 WARNINGS AFFECTING 63 LINES
--------------------------------------------------------------------------------
37 | ERROR | [ ] Parameter $request is not described in comment
37 | ERROR | [ ] Parameter $doiSearchManager is not described in comment
43 | ERROR | [x] Expected 1 space between comma and type hint
| | "RequestStack"; 0 found
43 | ERROR | [x] Expected one space after the comma, 0 found
43 | ERROR | [x] Expected 1 space between comma and type hint
| | "DoiSearchManager"; 0 found
43 | ERROR | [x] Expected one space after the comma, 0 found
67 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
69 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
73 | ERROR | [x] Expected one space after the comma, 0 found
77 | WARNING | [x] A comma should follow the last multiline array item.
| | Found: $data
86 | ERROR | [x] Expected 1 space after "=>"; 2 found
88 | WARNING | [x] A comma should follow the last multiline array item.
| | Found: )
95 | ERROR | [x] Doc comment short description must end with a full stop
96 | ERROR | [x] Whitespace found at end of line
97 | ERROR | [ ] Missing parameter comment
97 | ERROR | [ ] Missing parameter name
98 | ERROR | [x] Whitespace found at end of line
99 | ERROR | [ ] Description for the @return value must be on the next line
101 | ERROR | [x] Expected 1 space before opening brace; found 0
102 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
104 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
109 | ERROR | [x] Expected one space after the comma, 0 found
111 | WARNING | [x] A comma should follow the last multiline array item.
| | Found: ''
119 | ERROR | [x] Doc comment short description must end with a full stop
120 | ERROR | [x] Whitespace found at end of line
121 | ERROR | [ ] Missing parameter comment
121 | ERROR | [ ] Missing parameter name
122 | ERROR | [x] Whitespace found at end of line
123 | ERROR | [ ] Description for the @return value must be on the next line
125 | ERROR | [x] Expected 1 space before opening brace; found 0
127 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
128 | ERROR | [x] Expected 1 space after IF keyword; 0 found
128 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE"
| | but found "false"
128 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "FALSE"
| | but found "false"
128 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
129 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 7
130 | ERROR | [x] Line indented incorrectly; expected 8 spaces, found 7
137 | ERROR | [x] Doc comment short description must end with a full stop
138 | ERROR | [x] Whitespace found at end of line
139 | ERROR | [ ] Missing parameter comment
139 | ERROR | [ ] Missing parameter name
140 | ERROR | [x] Whitespace found at end of line
141 | ERROR | [ ] Description for the @return value must be on the next line
143 | ERROR | [x] Expected 1 space before opening brace; found 0
144 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
145 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
146 | ERROR | [x] Expected 1 space after IF keyword; 0 found
146 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
149 | ERROR | [x] Whitespace found at end of line
156 | WARNING | [ ] Line exceeds 80 characters; contains 82 characters
157 | ERROR | [ ] Doc comment short description must end with a full stop
157 | ERROR | [ ] Doc comment short description must be on a single line,
| | further text should be a separate paragraph
158 | ERROR | [x] Whitespace found at end of line
159 | ERROR | [ ] Missing parameter comment
159 | ERROR | [ ] Missing parameter name
160 | ERROR | [x] Whitespace found at end of line
161 | ERROR | [ ] Description for the @return value must be on the next line
163 | ERROR | [x] Expected 1 space before opening brace; found 0
165 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
166 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
168 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
177 | WARNING | [x] A comma should follow the last multiline array item.
| | Found: ''
182 | WARNING | [x] A comma should follow the last multiline array item.
| | Found: $refData
190 | ERROR | [x] Doc comment short description must end with a full stop
191 | ERROR | [x] Whitespace found at end of line
192 | ERROR | [ ] Missing parameter comment
192 | ERROR | [ ] Missing parameter name
193 | ERROR | [x] Whitespace found at end of line
194 | ERROR | [ ] Description for the @return value must be on the next line
196 | ERROR | [x] Expected 1 space before opening brace; found 0
198 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
199 | ERROR | [x] Concat operator must be surrounded by a single space
200 | ERROR | [x] Expected 1 space after closing parenthesis; found 0
203 | ERROR | [x] Expected 1 space after "="; 2 found
203 | ERROR | [x] Concat operator must be surrounded by a single space
205 | ERROR | [x] Expected one space after the comma, 0 found
206 | ERROR | [x] Expected 1 blank line after function; 0 found
207 | ERROR | [x] The closing brace for the class must have an empty line
| | before it
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 58 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...ntribution/drupal10/web/modules/contrib/doi_search/src/Form/SearchForm.php
--------------------------------------------------------------------------------
FOUND 3 ERRORS AND 1 WARNING AFFECTING 3 LINES
--------------------------------------------------------------------------------
29 | WARNING | [x] A comma should follow the last multiline array item. Found:
| | $doi
47 | ERROR | [x] Whitespace found at end of line
55 | ERROR | [x] Expected one space after the comma, 0 found
55 | ERROR | [x] Expected one space after the comma, 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...r/www/html/contribution/drupal10/web/modules/contrib/doi_search/README.txt
--------------------------------------------------------------------------------
FOUND 1 ERROR AND 3 WARNINGS AFFECTING 3 LINES
--------------------------------------------------------------------------------
10 | WARNING | [ ] Line exceeds 80 characters; contains 99 characters
14 | WARNING | [ ] Line exceeds 80 characters; contains 87 characters
18 | WARNING | [ ] Line exceeds 80 characters; contains 100 characters
18 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...10/web/modules/contrib/doi_search/templates/doi-search-reference.html.twig
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
23 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...pal10/web/modules/contrib/doi_search/templates/doi-search-result.html.twig
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
33 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

FILE: ...rupal10/web/modules/contrib/doi_search/templates/doi-search-page.html.twig
--------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
--------------------------------------------------------------------------------
20 | ERROR | [x] Expected 1 newline at end of file; 0 found
--------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------

Time: 415ms; Memory: 10MB

Remaining tasks

Please review the patch provided with the issue. It fixes all the issues.

šŸ“Œ Task
Status

Needs work

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡³India urvashi_vora Madhya Pradesh, India

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 @urvashi_vora
  • šŸ‡µšŸ‡­Philippines paraderojether

    I reviewed patch coding-standard-fixes.patch, and there are still remaining errors shown below:

    FILE: /Users/studenttrainees/New/drupalorgsite/docroot/modules/contrib/doi_search/src/Controller/DoiSearchController.php
    ------------------------------------------------------------------------------------------------------------------------
    FOUND 9 ERRORS AFFECTING 9 LINES
    ------------------------------------------------------------------------------------------------------------------------
    91 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    110 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    111 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    115 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    146 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    166 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    167 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    168 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    188 | ERROR | [x] Use null coalesce operator instead of ternary operator.
    ------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ------------------------------------------------------------------------------------------------------------------------

    Time: 346ms; Memory: 10MB

    Please check.
    Thank You.

  • šŸ‡®šŸ‡³India Soham Sengupta

    Hi, I have updated the patch with remaining error fixes

  • Status changed to Needs review over 1 year ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • šŸ‡®šŸ‡³India urvashi_vora Madhya Pradesh, India

    Providing interdiff between patch #0 and #3.

    Also, patch #3 looks good to me.

  • Status changed to Needs work over 1 year ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
     /**
      * @file
      * Primary module hooks for DOI Publications module.
    - *
    -**/
    + */

    Since that comment is edited, the description for that module is Hook implementations for the DOI Publications module.

       /**
    -   * It takes a DOI and returns an array of reference data
    -   * 
    -   * @param doi The DOI of the reference you want to retrieve.
    -   * 
    -   * @return An array of reference data.
    +   * It takes a DOI and returns an array of reference data.
        */
    -  private function getReferenceData($doi){
    -    if ($doi){
    +  private function getReferenceData($doi) {

    The documentation comment for a method needs to contain the method short description, the parameters description, and the return value description.

  • Assigned to imustakim
  • šŸ‡ØšŸ‡¦Canada imustakim Canada

    Working on this.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • šŸ‡ØšŸ‡¦Canada imustakim Canada

    Patch added.
    Please review.

  • Status changed to Needs work over 1 year ago
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
    +   * @return string
    +   *   Returns the title of the publication.

    The return value description must not start with Returns.

    +   * @return string
    +   *   the formatted authors.

    The first word must be capitalized.

  • First commit to issue fork.
  • Assigned to arpitk
  • šŸ‡®šŸ‡³India arpitk

    Working on this.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • šŸ‡®šŸ‡³India arpitk

    Providing the patch including patch #9 and suggestions from @apaderno at #10. Please review the patch.

  • šŸ‡®šŸ‡³India Raveen Kumar

    Hello guys,
    I have reviewed the patch #13 and it seems to be resolving the phpcs issues properly.
    And Thank You.

  • Status changed to Needs work 6 months ago
  • Hi @arpitk,

    Applied the patch you provided, it was applied not-so successfully and errors were still reported. Please see below:

    doi_search git:(1.0.x) āœ— curl https://www.drupal.org/files/issues/2023-05-05/Fixed-the-issues-reported-by-phpcs-3353332-13.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 14347  100 14347    0     0   117k      0 --:--:-- --:--:-- --:--:--  129k
    can't find file to patch at input line 5
    Perhaps you used the wrong -p or --strip option?
    The text leading up to this was:
    --------------------------
    |diff --git a/README.txt b/README.txt
    |index 2bb2490..6516625 100644
    |--- a/README.txt
    |+++ b/README.txt
    --------------------------
    File to patch: README.md
    patching file README.md
    Hunk #1 FAILED at 7.
    1 out of 1 hunk FAILED -- saving rejects to file README.md.rej
    patching file doi_search.module
    Hunk #1 FAILED at 2.
    Hunk #2 FAILED at 12.
    Hunk #3 FAILED at 57.
    3 out of 3 hunks FAILED -- saving rejects to file doi_search.module.rej
    patching file src/Controller/DoiSearchController.php
    patching file src/DoiSearchManager.php
    patching file src/Form/SearchForm.php
    āžœ  doi_search git:(1.0.x) āœ— cd ..
    āžœ  contrib git:(master) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig doi_search
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/doi_search/README.md
    ------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
    ------------------------------------------------------------------------------------------------
     10 | WARNING | Line exceeds 80 characters; contains 99 characters
     14 | WARNING | Line exceeds 80 characters; contains 87 characters
     18 | WARNING | Line exceeds 80 characters; contains 100 characters
    ------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/doi_search/templates/doi-search-reference.html.twig
    -------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -------------------------------------------------------------------------------------------------------------------------------
     23 | ERROR | [x] Expected 1 newline at end of file; 0 found
    -------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/doi_search/templates/doi-search-page.html.twig
    --------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------------------------
     20 | ERROR | [x] Expected 1 newline at end of file; 0 found
    --------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/doi_search/templates/doi-search-result.html.twig
    ----------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------------------------------------
     33 | ERROR | [x] Expected 1 newline at end of file; 0 found
    ----------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/doi_search/doi_search.module
    --------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------
     6 | ERROR | Wrong function doc comment end; expected "*/", found "**/"
    --------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue-v9/web/modules/contrib/doi_search/src/Controller/DoiSearchController.php
    -----------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------------
     9 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\doi_search\DoiSearchManager.
    -----------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------------------------
    
    Time: 195ms; Memory: 10MB

    Kindly check

    Thanks,
    Jake

  • Merge request !43353332: Fix phpcs issues ā†’ (Open) created by paraderojether
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    avpaderno ā†’ changed the visibility of the branch 3353332-fix-the-issues to hidden.

  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • šŸ‡µšŸ‡¹Portugal kallado
  • Status changed to Fixed 24 days ago
  • šŸ‡µšŸ‡¹Portugal kallado
  • šŸ‡µšŸ‡¹Portugal kallado
Production build 0.71.5 2024