Fix issues reported by PHPCS

Created on 19 March 2025, 6 months ago

Running PHPCS shows the warnings/errors in attached file, which should be fixed.

📌 Task
Status

Active

Version

5.0

Component

Code

Created by

🇮🇳India ggh

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

Merge Requests

Comments & Activities

  • Issue created by @ggh
  • 🇮🇳India ggh

    MR Raised

  • Pipeline finished with Success
    6 months ago
    Total: 286s
    #451908
  • 🇮🇳India Bhupesh_upadhyay

    It looks like there are few issues that needs to be fixed.

    FILE: /var/www/html/drupal10_contro/web/modules/contrib/chosen/src/ChosenFormRender.php
    ---------------------------------------------------------------------------------------
    FOUND 3 ERRORS AFFECTING 3 LINES
    ---------------------------------------------------------------------------------------
    38 | ERROR | Type hint "array" missing for $element
    125 | ERROR | Type hint "array" missing for $element
    143 | ERROR | Type hint "array" missing for $element
    ---------------------------------------------------------------------------------------

    FILE: /var/www/html/drupal10_contro/web/modules/contrib/chosen/modules/chosen_field/src/Plugin/Field/FieldWidget/ChosenFieldWidget.php
    --------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------------------------------------
    25 | ERROR | [x] Missing class doc comment
    --------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------------------------------------

    FILE: /var/www/html/drupal10_contro/web/modules/contrib/chosen/modules/chosen_field/tests/src/Functional/ChosenFieldWidgetsTest.php
    --------------------------------------------------------------------------------------------------------------------------------------
    FOUND 3 ERRORS AFFECTING 3 LINES
    --------------------------------------------------------------------------------------------------------------------------------------
    40 | ERROR | Class property $card_1 should use lowerCamel naming without underscores
    47 | ERROR | Class property $card_2 should use lowerCamel naming without underscores
    94 | ERROR | The array declaration extends to column 101 (the limit is 80). The array content should be split up over multiple lines
    --------------------------------------------------------------------------------------------------------------------------------------

    FILE: /var/www/html/drupal10_contro/web/modules/contrib/chosen/modules/chosen_lib/src/Commands/ChosenLibCommands.php
    --------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------------------------------------
    151 | ERROR | The array declaration extends to column 91 (the limit is 80). The array content should be split up over multiple lines
    --------------------------------------------------------------------------------------------------------------------------------------

    FILE: /var/www/html/drupal10_contro/web/modules/contrib/chosen/chosen.module
    -------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
    -------------------------------------------------------------------------------------
    19 | WARNING | Global constants should not be used, move it to a class or interface
    20 | WARNING | Global constants should not be used, move it to a class or interface
    21 | WARNING | Global constants should not be used, move it to a class or interface
    22 | WARNING | Global constants should not be used, move it to a class or interface
    -------------------------------------------------------------------------------------

  • Assigned to Bhupesh_upadhyay
  • Status changed to Needs work 29 days ago
  • First commit to issue fork.
  • Pipeline finished with Failed
    29 days ago
    Total: 158s
    #578575
  • 🇬🇧United Kingdom schillerm

    Hi, I reviewed !MR18 and got some warnings and errors.. see below..

    phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml web/modules/contrib/chosen

    FILE: ...-11-3513892/web/modules/contrib/chosen/modules/chosen_field/tests/src/Functional/ChosenFieldWidgetsTest.php
    -----------------------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    -----------------------------------------------------------------------------------------------------------------
    40 | ERROR | Class property $card_1 should use lowerCamel naming without underscores
    47 | ERROR | Class property $card_2 should use lowerCamel naming without underscores
    -----------------------------------------------------------------------------------------------------------------

    FILE: /home/laptopuser/Documents/Test2/Dev-11-3513892/web/modules/contrib/chosen/chosen.module
    ----------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
    ----------------------------------------------------------------------------------------------
    19 | WARNING | Global constants should not be used, move it to a class or interface
    20 | WARNING | Global constants should not be used, move it to a class or interface
    21 | WARNING | Global constants should not be used, move it to a class or interface
    22 | WARNING | Global constants should not be used, move it to a class or interface
    ----------------------------------------------------------------------------------------------

    So I fixed these errors locally and retested, no phpcs issues.

    To fix these errors I created a new simple class for the constants called ChosenConstants.php and moved the constants in there. Also renamed the $card_1 and $card_2 variables.

    It looked like The source branch (3513892-fix-issues-reported) was 4 commits behind the target branch (5.0.x). So I did a git rebase 5.0.x on my local branch to bring those commits in.

    I then retested and also ran the phpunit tests. The phpunit test ChosenFieldWidgetsTest.php was failing due to me changing the $card_1 and $card_2 variables. I fixed this but it is also failing due to other things, like when it gets to these lines ..

    $this->card1->setSetting('allowed_values', []);
    $this->card1->setSetting('allowed_values_function', 'options_test_allowed_values_callback');

    What is the etiquette with this .. should I fix phpunit tests as well?

  • 🇭🇺Hungary nagy.balint

    Hi!

    If you can fix phpunit in a separate issue that would be awesome!

    I can commit it quickly and then we can return to this.

Production build 0.71.5 2024