Fix the errors/warnings reported by PHP_CodeSniffer

Created on 10 March 2024, 9 months ago
Updated 10 July 2024, 5 months ago

Problem/Motivation

Running phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml shows the following errors/warnings which should be fixed.


FILE: web/modules/contrib/taxonomy_protect/taxonomy_protect.module
-------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------
 1 | ERROR | [x] Missing file doc comment
-------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------------------------------


FILE: web/modules/contrib/taxonomy_protect/taxonomy_protect.install
--------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
--------------------------------------------------------------------------------------------------
  1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
 11 | ERROR | [x] Short array syntax must be used to define arrays
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------


FILE: web/modules/contrib/taxonomy_protect/src/Form/TaxonomyProtectAdminSettingsForm.php
-----------------------------------------------------------------------------------------------------------------------
FOUND 3 ERRORS AND 2 WARNINGS AFFECTING 5 LINES
-----------------------------------------------------------------------------------------------------------------------
  3 | ERROR   | [x] Namespaced classes, interfaces and traits should not begin with a file doc comment
 14 | ERROR   | [x] Missing class doc comment
 30 | ERROR   | [x] Missing function doc comment
 31 | WARNING | [ ] Vocabulary::loadMultiple calls should be avoided in classes, use dependency injection instead
 44 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
-----------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 3 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------------------------------------------------

šŸ› Bug report
Status

Needs work

Version

2.1

Component

Code

Created by

šŸ‡ŗšŸ‡¦Ukraine Andrii Momotov

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

Merge Requests

Comments & Activities

  • Issue created by @Andrii Momotov
  • Assigned to Andrii Momotov
  • Issue was unassigned.
  • Status changed to Needs review 9 months ago
  • šŸ‡ŗšŸ‡¦Ukraine Andrii Momotov

    Fixed the errors/warnings reported by PHP_CodeSniffer.
    Please review. Thanks!

  • Status changed to Needs work 9 months ago
  • šŸ‡µšŸ‡­Philippines clarkssquared

    Hi

    I applied MR !3 but there are still many PHPCS issues that needs to be resolved.

    āžœ  contrib git:(master) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml taxonomy_protect 
    
    FILE: ...s/d9/d9-local/web/modules/contrib/taxonomy_protect/taxonomy_protect.module
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     1 | ERROR | [x] Missing file doc comment
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    
    FILE: ...d9/d9-local/web/modules/contrib/taxonomy_protect/taxonomy_protect.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: .../d9/d9-local/web/modules/contrib/taxonomy_protect/taxonomy_protect.install
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     1 | ERROR | [x] The PHP open tag must be followed by exactly one blank line
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    
    FILE: ...les/contrib/taxonomy_protect/src/Form/TaxonomyProtectAdminSettingsForm.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    --------------------------------------------------------------------------------
     32 | WARNING | Vocabulary::loadMultiple calls should be avoided in classes,
        |         | use dependency injection instead
     45 | WARNING | \Drupal calls should be avoided in classes, use dependency
        |         | injection instead
    --------------------------------------------------------------------------------
    
    Time: 236ms; Memory: 10MB
    
    āžœ  contrib git:(master) āœ— cd taxonomy_protect 
    āžœ  taxonomy_protect git:(master) āœ— curl https://git.drupalcode.org/project/taxonomy_protect/-/merge_requests/3.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  4166    0  4166    0     0   4991      0 --:--:-- --:--:-- --:--:--  5025
    patching file 'src/Form/TaxonomyProtectAdminSettingsForm.php'
    2 out of 3 hunks failed--saving rejects to 'src/Form/TaxonomyProtectAdminSettingsForm.php.rej'
    patching file taxonomy_protect.install
    patching file taxonomy_protect.module
    āžœ  taxonomy_protect git:(master) āœ— ..
    āžœ  contrib git:(master) āœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml taxonomy_protect
    
    FILE: ...s/d9/d9-local/web/modules/contrib/taxonomy_protect/taxonomy_protect.module
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     1 | ERROR | [x] Missing file doc comment
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    
    
    FILE: ...d9/d9-local/web/modules/contrib/taxonomy_protect/taxonomy_protect.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: ...les/contrib/taxonomy_protect/src/Form/TaxonomyProtectAdminSettingsForm.php
    --------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     32 | WARNING | Vocabulary::loadMultiple calls should be avoided in classes,
        |         | use dependency injection instead
    --------------------------------------------------------------------------------
    
    Time: 95ms; Memory: 10MB
    
    āžœ  contrib git:(master) āœ— 
  • šŸ‡ŗšŸ‡¦Ukraine Andrii Momotov

    Hi @clarkssquared
    You are doing something wrong. I've checked several times and it doesn't show any more warnings or errors.

    For example, in your message, the first error says:

    FILE: ...s/d9/d9-local/web/modules/contrib/taxonomy_protect/taxonomy_protect.module
    --------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------
     1 | ERROR | [x] Missing file doc comment
    --------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------
    

    Please look at my MR:
    https://git.drupalcode.org/project/taxonomy_protect/-/merge_requests/3/d...

    So you'll see, I added a doc comment to the taxonomy_protect.module file.
    Thanks!

  • šŸ‡®šŸ‡³India Jasjeet Kaur Brar

    Hiiee Andrii, These issues are already been taken care of in another ticket by me which was added by you for GitLab CI.
    Can you please confirm from that ticket? And Thanks.

  • Status changed to Needs review 9 months ago
  • šŸ‡®šŸ‡³India riddhi.addweb

    I tried to apply the patch [MR3], but it failed when applied. Attaching a screenshot for the same.

  • Status changed to Needs work 5 months ago
Production build 0.71.5 2024