Coding standards fixes remaining


Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/contrib
$ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,js,yml weight/

FILE: C:\Users\Admin\Desktop\projects\drupal\web\modules\contrib\weight\views\views_handler_weight_selector.inc
-------------------------------------------------------------------------------------------------------------------
FOUND 6 ERRORS AND 1 WARNING AFFECTING 5 LINES
-------------------------------------------------------------------------------------------------------------------
   6 | ERROR   | Class name must begin with a capital letter
   6 | ERROR   | Class name must use UpperCamel naming without underscores
   6 | WARNING | Class name must be prefixed with the project name "Weight"
  28 | ERROR   | Public method name "views_handler_weight_selector::option_definition" is not in lowerCamel format
  46 | ERROR   | Public method name "views_handler_weight_selector::options_form" is not in lowerCamel format
  91 | ERROR   | Public method name "views_handler_weight_selector::views_form" is not in lowerCamel format
 158 | ERROR   | Public method name "views_handler_weight_selector::views_form_submit" is not in lowerCamel format
-------------------------------------------------------------------------------------------------------------------


FILE: C:\Users\Admin\Desktop\projects\drupal\web\modules\contrib\weight\weight.module
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 153 | WARNING | Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for
     |         | xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block templates."
 192 | WARNING | Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for
     |         | xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block templates."
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 357ms; Memory: 10MB

Steps to reproduce
phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml weight/

CommentFileSizeAuthor
#6 phpcs issue remaining.png33.18 KBannmarysruthy

Issue fork weight-3343609

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

VladimirAus created an issue. See original summary.

vladimiraus’s picture

Issue summary: View changes
Status: Active » Needs work

_pratik_ made their first commit to this issue’s fork.

annmarysruthy made their first commit to this issue’s fork.

annmarysruthy’s picture

StatusFileSize
new33.18 KB

Made commit to fix some more issues in phpcs. However 1 warning is remaining which cannot be solved.

FILE: /var/www/html/web/modules/contrib/weight-3343609/weight.views.inc
-----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------
17 | WARNING | Unused variable $table_name.
-----------------------------------------------------------------------

we cannot remove the $table_name variable from the foreach loop because it is used as a key in the $data array. Removing it would cause an error in the loop, as it would not be possible to access the data in the $data array without the key.

annmarysruthy’s picture

Status: Needs work » Needs review
vladimiraus’s picture

Status: Needs review » Needs work

Thanks for commit. phpcs return other errors

FILE: /Users/tesboss/_PROJECTS/drupal/weight/weight.module
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
 153 | WARNING | Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for
     |         | xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block templates."
 192 | WARNING | Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for
     |         | xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block templates."
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: /Users/tesboss/_PROJECTS/drupal/weight/weight.install
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 78 | ERROR | Doc comment is empty
----------------------------------------------------------------------


FILE: /Users/tesboss/_PROJECTS/drupal/weight/views/views_handler_weight_selector.inc
-------------------------------------------------------------------------------------------------------------------
FOUND 14 ERRORS AND 2 WARNINGS AFFECTING 14 LINES
-------------------------------------------------------------------------------------------------------------------
   3 | ERROR   | Doc comment is empty
   6 | ERROR   | Class name must begin with a capital letter
   6 | ERROR   | Class name must use UpperCamel naming without underscores
   6 | WARNING | Class name must be prefixed with the project name "Weight"
   8 | ERROR   | Doc comment is empty
  17 | ERROR   | Doc comment is empty
  20 | ERROR   | Public method name "views_handler_weight_selector::option_definition" is not in lowerCamel format
  30 | ERROR   | Doc comment is empty
  33 | ERROR   | Public method name "views_handler_weight_selector::options_form" is not in lowerCamel format
  47 | ERROR   | Doc comment is empty
  54 | ERROR   | Doc comment is empty
  61 | ERROR   | Doc comment is empty
  64 | ERROR   | Public method name "views_handler_weight_selector::views_form" is not in lowerCamel format
  91 | WARNING | Line exceeds 80 characters; contains 83 characters
 123 | ERROR   | Doc comment is empty
 126 | ERROR   | Public method name "views_handler_weight_selector::views_form_submit" is not in lowerCamel format
-------------------------------------------------------------------------------------------------------------------

nmorin’s picture

Getting Error when attempting to update weight module... Is this related to the errors in the previous comments?

PHP Parse error:  syntax error, unexpected '?', expecting ')' in /var/www/drupalbase/sites/all/modules/weight/weight.install on line 39
Drush command terminated abnormally due to an unrecoverable error.                                                                           [error]
Error: syntax error, unexpected '?', expecting ')' in /var/www/drupalbase/sites/all/modules/weight/weight.install, line 39

^^ This was after "drush up" command was issued...

#drush up
Update information last refreshed: Mon, 02/27/2023 - 14:38
 Name             Installed Version  Proposed version  Message          
 Weight (weight)  7.x-3.1            7.x-3.2           Update available 


Code updates will be made to the following projects: Weight [weight-7.x-3.2]
dhigby’s picture

I got the same "unexpected '?'" error, reported here: https://www.drupal.org/project/weight/issues/3344820

vladimiraus’s picture

Patch was pushed for testing for #3344820: Apache 500 error with 7.x-3.2.
Please test.

avpaderno’s picture

Title: 7.x phpcs coding standards » Fix the issues reported by phpcs
Category: Feature request » Task
Issue tags: +Coding standards
sourabhjain’s picture

Issue summary: View changes

Shank115 made their first commit to this issue’s fork.

Yashaswi18 made their first commit to this issue’s fork.

zkhan.aamir’s picture

Hi,

MR #15 applied successfully.

Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/contrib/weight (7.x-3.x)
$ curl https://git.drupalcode.org/project/weight/-/merge_requests/10.diff | patch -p1
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 16773    0 16773    0     0  17530      0 --:--:-- --:--:-- --:--:-- 17544
patching file .gitlab-ci.yml
patching file README.md (renamed from README.txt)
patching file views/views_handler_weight_selector.inc
patching file views/weight.views.inc
patching file weight.install
patching file weight.module

Remaining issues

Admin@DESKTOP-252TO6V MINGW64 ~/Desktop/projects/drupal/web/modules/contrib
$ phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,js,yml weight/

FILE: C:\Users\Admin\Desktop\projects\drupal\web\modules\contrib\weight\views\views_handler_weight_selector.inc
-------------------------------------------------------------------------------------------------------------------
FOUND 6 ERRORS AND 1 WARNING AFFECTING 5 LINES
-------------------------------------------------------------------------------------------------------------------
   6 | ERROR   | Class name must begin with a capital letter
   6 | ERROR   | Class name must use UpperCamel naming without underscores
   6 | WARNING | Class name must be prefixed with the project name "Weight"
  28 | ERROR   | Public method name "views_handler_weight_selector::option_definition" is not in lowerCamel format
  46 | ERROR   | Public method name "views_handler_weight_selector::options_form" is not in lowerCamel format
  91 | ERROR   | Public method name "views_handler_weight_selector::views_form" is not in lowerCamel format
 158 | ERROR   | Public method name "views_handler_weight_selector::views_form_submit" is not in lowerCamel format
-------------------------------------------------------------------------------------------------------------------


FILE: C:\Users\Admin\Desktop\projects\drupal\web\modules\contrib\weight\weight.module
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 153 | WARNING | Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for
     |         | xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block templates."
 192 | WARNING | Format should be "* Implements hook_foo().", "* Implements hook_foo_BAR_ID_bar() for xyz_bar().",, "* Implements hook_foo_BAR_ID_bar() for
     |         | xyz-bar.html.twig.", "* Implements hook_foo_BAR_ID_bar() for xyz-bar.tpl.php.", or "* Implements hook_foo_BAR_ID_bar() for block templates."
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 357ms; Memory: 10MB
zkhan.aamir’s picture

Issue summary: View changes

Issue summary updated.

pray_12 made their first commit to this issue’s fork.

yashaswi18’s picture

Hello, after checking out to the branch '3343609-7.x-phpcs-coding', found these errors remaining :

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,js,yml weight/

FILE: /home/yashaswi/contribs/weight/views/views_handler_weight_selector.inc
-------------------------------------------------------------------------------------------------------------------
FOUND 6 ERRORS AND 1 WARNING AFFECTING 5 LINES
-------------------------------------------------------------------------------------------------------------------
   6 | ERROR   | Class name must begin with a capital letter
   6 | ERROR   | Class name must use UpperCamel naming without underscores
   6 | WARNING | Class name must be prefixed with the project name "Weight"
  28 | ERROR   | Public method name "views_handler_weight_selector::option_definition" is not in lowerCamel format
  46 | ERROR   | Public method name "views_handler_weight_selector::options_form" is not in lowerCamel format
  91 | ERROR   | Public method name "views_handler_weight_selector::views_form" is not in lowerCamel format
 158 | ERROR   | Public method name "views_handler_weight_selector::views_form_submit" is not in lowerCamel format
-------------------------------------------------------------------------------------------------------------------

Chandansha made their first commit to this issue’s fork.

chandansha’s picture

Status: Needs work » Needs review
roberttabigue’s picture

Status: Needs review » Needs work

Hi @avpaderno,

After reviewing and applied the MR!10 to the Weight module against 7.x-3.x-dev on Drupal 10, I still see 1 PHPCS warning.
See below:

FILE: /Users/roberttabigue/Project/DrupalOrg/drupalorgissues/web/modules/contrib/weight/views/views_handler_weight_selector.inc
-------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------
 8 | WARNING | Class name must be prefixed with the project name "Weight"
-------------------------------------------------------------------------------------------------------------------------------

I ran this command on the module:
phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml,css,js weight/

I'm moving this to ‘Needs work’ for now.

Thank you!

avpaderno’s picture

Status: Needs work » Needs review

GitLab CI does not report any PHP_CodeSniffer error/warning. phpcs --standard=Drupal,DrupalPractice does not applies the same PHP_CodeSniffer rules GitLab CI applies, which means it can give different errors/warnings, but that is irrelevant, since GitLab CI is used to test the project.

vladimiraus’s picture

Status: Needs review » Reviewed & tested by the community
anybody’s picture

Here's the fix for modern Drupal: #3481730: Fix phpcs, cspell and phpunit could both be merged perhaps?

vladimiraus changed the visibility of the branch 8.x-3.x to hidden.

  • vladimiraus committed a2d5ad0a on 7.x-3.x
    Issue #3343609 by vladimiraus, annmarysruthy, _pratik_: Fix the issues...
vladimiraus’s picture

Status: Reviewed & tested by the community » Fixed

Thanks, everyone! 🧁
Committed!

vladimiraus’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.