Fix the issues reported by PHP_CodeSniffer

Created on 26 September 2024, about 2 months ago

Problem/Motivation

FILE: modules\follow_me\example_result.php
-----------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AND 3 WARNINGS AFFECTING 6 LINES
-----------------------------------------------------------------------------------------------------
1 | ERROR | [x] Missing file doc comment
4 | ERROR | [x] Array indentation error, expected 2 spaces but found 4
5 | ERROR | [x] Expected 1 space after "=>"; 0 found
9 | WARNING | [x] A comma should follow the last multiline array item. Found: 'node_load'
14 | WARNING | [x] A comma should follow the last multiline array item. Found: 'taxonomy_term_load'
20 | WARNING | [x] A comma should follow the last multiline array item. Found: 'views_get_view'
-----------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------

FILE: modules\follow_me\follow_me.module
------------------------------------------------------------------------------------------------------------------------------------
FOUND 10 ERRORS AND 1 WARNING AFFECTING 9 LINES
------------------------------------------------------------------------------------------------------------------------------------
1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
4 | ERROR | [x] Function comment short description must start with exactly one space
11 | WARNING | [x] Unused use statement
12 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Routing\RouteMatchInterface.
12 | ERROR | [x] There must be one blank line after the last USE statement; 2 found;
18 | ERROR | [x] Expected 1 blank line before function; 2 found
43 | ERROR | [x] Expected 1 blank line after function; 2 found
49 | ERROR | [x] Inline comments must start with a capital letter
49 | ERROR | [x] Whitespace found at end of line
50 | ERROR | [ ] Comment indentation error, expected only 1 spaces
51 | ERROR | [ ] Comment indentation error, expected only 3 spaces
------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 9 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------

FILE: modules\follow_me\src\ComponentBuilder.php
------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 15 ERRORS AND 5 WARNINGS AFFECTING 16 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------
3 | ERROR | [x] Namespaced classes, interfaces and traits should not begin with a file doc comment
5 | ERROR | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph
10 | ERROR | [x] Missing class doc comment
12 | ERROR | [ ] Missing member variable doc comment
21 | ERROR | [ ] Description for the @return value is missing
28 | ERROR | [x] Namespaced classes/interfaces/traits should be referenced with use statements
34 | WARNING | [x] A comma should follow the last multiline array item. Found: $bundle
44 | ERROR | [ ] Description for the @return value is missing
51 | ERROR | [x] Expected 1 space after IF keyword; 0 found
51 | ERROR | [x] Namespaced classes/interfaces/traits should be referenced with use statements
57 | WARNING | [x] A comma should follow the last multiline array item. Found: $bundle
66 | ERROR | [ ] Description for the @return value is missing
72 | WARNING | [x] '@TODO Clean up - add validation.' should match the format '@todo Fix problem X here.'
72 | ERROR | [x] No space found before comment text; expected "// @TODO Clean up - add validation." but found "//@TODO Clean up - add validation."
77 | WARNING | [x] '@TODO ...' should match the format '@todo Fix problem X here.'
77 | ERROR | [x] No space found before comment text; expected "// @TODO ..." but found "//@TODO ..."
77 | ERROR | [x] Comments may not appear after statements
78 | WARNING | [x] A comma should follow the last multiline array item. Found: 'views_get_view'
80 | ERROR | [x] Functions must not contain multiple empty lines in a row; found 2 empty lines
85 | ERROR | [x] Expected 1 newline at end of file; 0 found
------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 15 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------------------

FILE: modules\follow_me\src\Constants.php
----------------------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AFFECTING 4 LINES
----------------------------------------------------------------------------------------------------------------------
7 | ERROR | [ ] Doc comment short description must be on a single line, further text should be a separate paragraph
8 | ERROR | [x] There must be exactly one newline after the class comment
12 | ERROR | [ ] Doc comment is empty
18 | ERROR | [ ] Doc comment is empty
----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------------------------------------------

FILE: modules\follow_me\src\Controller\FollowMeController.php
-------------------------------------------------------------------------------------------------------
FOUND 4 ERRORS AND 1 WARNING AFFECTING 5 LINES
-------------------------------------------------------------------------------------------------------
3 | ERROR | [x] Namespaced classes, interfaces and traits should not begin with a file doc comment
11 | ERROR | [x] Missing class doc comment
13 | ERROR | [x] Missing function doc comment
17 | WARNING | [x] A comma should follow the last multiline array item. Found: )
22 | ERROR | [x] Expected 1 newline at end of file; 0 found
-------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------

FILE: modules\follow_me\src\CurrentTrailService.php
--------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 53 ERRORS AND 13 WARNINGS AFFECTING 57 LINES
--------------------------------------------------------------------------------------------------------------------------------------------------------
5 | WARNING | [x] Unused use statement
6 | WARNING | [x] Unused use statement
7 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\PathProcessor\OutboundPathProcessorInterface.
10 | WARNING | [x] Unused use statement
11 | WARNING | [x] Unused use statement
12 | WARNING | [x] Unused use statement
12 | ERROR | [x] There must be one blank line after the last USE statement; 2 found;
17 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
20 | ERROR | [ ] Missing short description in doc comment
21 | ERROR | [ ] Content missing for @var tag in member variable comment
28 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "NULL" but found "null"
35 | ERROR | [ ] Description for the @return value is missing
38 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "NULL" but found "null"
39 | ERROR | [ ] Inline doc block comments are not allowed; use "/* Comment */" or "// Comment" instead
48 | ERROR | [ ] Missing short description in doc comment
49 | ERROR | [ ] Description for the @return value is missing
53 | WARNING | [x] '@TODO: Clean up (create as method).' should match the format '@todo Fix problem X here.'
55 | ERROR | [x] Concat operator must be surrounded by a single space
64 | ERROR | [ ] Missing short description in doc comment
65 | ERROR | [ ] Description for the @return value is missing
76 | ERROR | [x] Short array syntax must be used to define arrays
82 | ERROR | [ ] Comment indentation error, expected only 1 spaces
83 | ERROR | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
89 | ERROR | [x] Concat operator must be surrounded by a single space
94 | ERROR | [x] There should be no white space after an opening "("
94 | ERROR | [x] There should be no white space before a closing ")"
102 | ERROR | [x] Expected 1 space after "="; 0 found
107 | ERROR | [x] Expected newline after closing brace
116 | ERROR | [x] Expected 1 blank line after function; 2 found
119 | ERROR | [ ] Missing short description in doc comment
120 | ERROR | [ ] Missing parameter comment
122 | ERROR | [ ] Description for the @return value is missing
127 | ERROR | [x] Concat operator must be surrounded by a single space
129 | ERROR | [x] Inline comments must start with a capital letter
129 | ERROR | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
130 | ERROR | [x] Expected 1 space after IF keyword; 0 found
132 | ERROR | [x] Expected newline after closing brace
141 | ERROR | [ ] Missing short description in doc comment
142 | ERROR | [ ] Missing parameter comment
144 | ERROR | [ ] Description for the @return value is missing
150 | ERROR | [x] Expected 1 blank line after function; 3 found
153 | ERROR | [ ] More than 2 empty lines are not allowed
157 | ERROR | [ ] Description for the @return value is missing
163 | ERROR | [x] TRUE, FALSE and NULL must be uppercase; expected "NULL" but found "null"
167 | ERROR | [x] Inline comments must start with a capital letter
171 | ERROR | [x] Inline comments must start with a capital letter
175 | ERROR | [x] Inline comments must start with a capital letter
186 | ERROR | [ ] Description for the @return value is missing
193 | ERROR | [x] Namespaced classes/interfaces/traits should be referenced with use statements
199 | WARNING | [x] A comma should follow the last multiline array item. Found: $bundle
209 | ERROR | [ ] Description for the @return value is missing
216 | ERROR | [x] Expected 1 space after IF keyword; 0 found
216 | ERROR | [x] Namespaced classes/interfaces/traits should be referenced with use statements
222 | WARNING | [x] A comma should follow the last multiline array item. Found: $bundle
231 | ERROR | [ ] Description for the @return value is missing
237 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 0
237 | ERROR | [x] 4 spaces found before inline comment; expected "// $view_id =$route->getDefault('view_id');" but found "// $view_id =$route->getDefault('view_id');"
238 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 0
239 | WARNING | [x] There must be no blank line following an inline comment
239 | ERROR | [x] Line indented incorrectly; expected 4 spaces, found 0
241 | WARNING | [x] '@TODO Clean up - add validation.' should match the format '@todo Fix problem X here.'
241 | ERROR | [x] No space found before comment text; expected "// @TODO Clean up - add validation." but found "//@TODO Clean up - add validation."
246 | WARNING | [x] '@TODO ...' should match the format '@todo Fix problem X here.'
246 | ERROR | [x] No space found before comment text; expected "// @TODO ..." but found "//@TODO ..."
246 | ERROR | [x] Comments may not appear after statements
247 | WARNING | [x] A comma should follow the last multiline array item. Found: 'views_get_view'
--------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 45 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------------------------------------

FILE: modules\follow_me\src\EventSubscriber\FollowMeSubscriber.php
-------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 9 ERRORS AND 1 WARNING AFFECTING 8 LINES
-------------------------------------------------------------------------------------------------------------------------------------------------------
3 | ERROR | [x] Namespaced classes, interfaces and traits should not begin with a file doc comment
3 | ERROR | [ ] Doc comment is empty
10 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Symfony\Component\EventDispatcher\EventSubscriberInterface.
10 | ERROR | [x] There must be one blank line after the last USE statement; 2 found;
15 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
29 | ERROR | [ ] Public method name "FollowMeSubscriber::getTrailID" is not in lowerCamel format
47 | ERROR | [ ] Description for the @return value is missing
49 | ERROR | [ ] Public method name "FollowMeSubscriber::generateTrailID" is not in lowerCamel format
54 | ERROR | [x] Expected newline after closing brace
62 | ERROR | [x] Expected 1 newline at end of file; 0 found
-------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------------------------------------------------------------

Steps to reproduce

Run phpcs command to get the drupal coding standard issues.

Proposed resolution

Many of the issues can be fixed by running the phpcbf command. For the remaining ones, we will need to manually address and then commit these changes before pushing them.

šŸ“Œ Task
Status

Needs work

Version

1.0

Component

Code

Created by

šŸ‡ŗšŸ‡øUnited States sunil jolapara 3265 Summitrun Drive, Independence, KY, 41051

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

Merge Requests

Comments & Activities

  • Issue created by @sunil jolapara
  • šŸ‡ŗšŸ‡øUnited States sunil jolapara 3265 Summitrun Drive, Independence, KY, 41051
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi @sunil jolapara,

    Thank you for providing an MR. I applied MR!1, it was applied smoothly and 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:

    āžœ  follow_me git:(1.0.x) curl https://git.drupalcode.org/project/follow_me/-/merge_requests/1.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 18031    0 18031    0     0  27170      0 --:--:-- --:--:-- --:--:-- 27155
    patching file example_result.php
    patching file follow_me.module
    patching file src/ComponentBuilder.php
    patching file src/Constants.php
    patching file src/Controller/FollowMeController.php
    patching file src/CurrentTrailService.php
    patching file src/EventSubscriber/FollowMeSubscriber.php
    āžœ  follow_me git:(1.0.x) āœ— ..
    āžœ  contrib git:(main) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml follow_me
    
    FILE: /Users/interns/Demo-site/drupal_11_test/install-dir/drupal_11_test_site/web/modules/contrib/follow_me/example_result.php
    ------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ------------------------------------------------------------------------------------------------------------------------------
     8 | WARNING | Unused variable $result.
    ------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal_11_test/install-dir/drupal_11_test_site/web/modules/contrib/follow_me/follow_me.module
    --------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------------------------------------------------------
      9 | WARNING | @author tags are not usually used in Drupal, because over time multiple contributors will touch the code anyway
     51 | WARNING | There must be no blank line following an inline comment
    --------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal_11_test/install-dir/drupal_11_test_site/web/modules/contrib/follow_me/src/ComponentBuilder.php
    ------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
    ------------------------------------------------------------------------------------------------------------------------------------
     30 | WARNING | Unused private method buildNodeComponent()
     54 | WARNING | Unused private method buildTaxonomyComponent()
     77 | WARNING | Unused private method buildViewComponent()
    ------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal_11_test/install-dir/drupal_11_test_site/web/modules/contrib/follow_me/src/CurrentTrailService.php
    ---------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 15 WARNINGS AFFECTING 14 LINES
    ---------------------------------------------------------------------------------------------------------------------------------------
      41 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
      42 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
      60 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
      89 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
      96 | WARNING | Unused variable $cache.
      96 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     102 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     104 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     107 | WARNING | Unused variable $view_id.
     116 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     136 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     174 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     206 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     230 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     257 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    ---------------------------------------------------------------------------------------------------------------------------------------
    
    
    FILE: /Users/interns/Demo-site/drupal_11_test/install-dir/drupal_11_test_site/web/modules/contrib/follow_me/src/EventSubscriber/FollowMeSubscriber.php
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 5 WARNINGS AFFECTING 5 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------------------
     26 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     30 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     34 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     47 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
     52 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    
    Time: 166ms; Memory: 10MB
    
    āžœ  contrib git:(main) āœ—

    Thank you.

  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹

    The issue summary for PHP_CodeSniffer issues should always show the report given from PHP_CodeSniffer and the arguments passed to phpcs.

    Furthermore, since GitLab CI is now enabled for all the projects, GitLab CI should be used to get PHP_CodeSniffer errors/warnings.

  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • šŸ‡µšŸ‡­Philippines cleavinjosh
  • Merge request !2Resolve #3476906 "Fix phpcs issues" ā†’ (Open) created by cleavinjosh
  • Pipeline finished with Success
    9 days ago
    Total: 200s
    #336284
  • šŸ‡µšŸ‡­Philippines cleavinjosh
  • šŸ‡®šŸ‡¹Italy apaderno Brescia, šŸ‡®šŸ‡¹
  • Pipeline finished with Success
    8 days ago
    Total: 143s
    #337456
  • šŸ‡®šŸ‡³India kulpratap2002

    Fixed all errors, Please review.

  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi @kul.pratap,

    Thank you for updating the MR.

    No more phpcs issues found.

    Moving this to RTBC. Thank you.

Production build 0.71.5 2024