Running phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml ./ returns the following warnings/errors, which need to be fixed, if they are not false positives.

FILE: ./realname/realname.module
-------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-------------------------------------------------------------------------
  18 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Render\BubbleableMetadata.
 224 | ERROR | [x] Inline comments must end in full-stops, exclamation marks, question marks, colons, or closing parentheses
-------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------


FILE: ./realname/src/Controller/RealnameAutocompleteController.php
-------------------------------------------------------------------------
FOUND 3 ERRORS AFFECTING 3 LINES
-------------------------------------------------------------------------
  6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Component\Utility\Crypt.
 24 | ERROR | [ ] The array declaration extends to column 92 (the limit is 80). The array content should be split up over multiple
    |       |     lines
 73 | ERROR | [x] Use null coalesce operator instead of ternary operator.
-------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------


FILE: ./realname/src/Plugin/migrate/process/RealnameReplaceToken.php
-------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-------------------------------------------------------------------------
  6 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\migrate\MigrateExecutableInterface.
 23 | ERROR | [x] list(...) is forbidden, use [...] instead.
-------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-------------------------------------------------------------------------

Time: 110ms; Memory: 10MB

I left out the warnings/errors that are going to be fixed in #3359562: t() should not be used in test classes

Issue fork realname-3352347

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

Raghavendra A M created an issue. See original summary.

omkar_yewale’s picture

Title: Coding standards and best practices » Fix the issues reported by phpcs
Assigned: Unassigned » omkar_yewale
Category: Bug report » Task
Issue summary: View changes
Status: Active » Needs work
Issue tags: +Coding standards

omkar_yewale’s picture

Assigned: omkar_yewale » Unassigned
Status: Needs work » Needs review

!12 MR created, Please Review.

akram khan’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new67.1 KB
new32.93 KB

checked above MR it fixed the PHPCS issue

avpaderno’s picture

Status: Reviewed & tested by the community » Needs work
-    // Process TWIG
+    // Process TWIG.
     $twig_service = \Drupal::service('twig');

TWIG is misspelled.
Instead of fixing that comment, it should be better to remove it, as it just describes what is already clear from the code.

-    if ($target_type !== 'user' || !in_array($selection_handler, ['default:user', 'default'], TRUE)) {
+    if ($target_type !== 'user' || !in_array($selection_handler, [
+      'default:user', 'default',
+    ], TRUE)) {
       return parent::handleAutocomplete($request, $target_type, $selection_handler, $selection_settings_key);
     }

The Drupal coding standards say that control structures are written in a single line.
That code is formatted as per PSR12 coding standards, not the coding standards followed by Drupal.

sumit-k’s picture

Thanks for reviewing, recently mentioned issues are fixed in the following patch https://www.drupal.org/files/issues/2023-07-07/t_calls_should_be_avoided-3359562-11.patch. Thread - https://www.drupal.org/project/realname/issues/3359562#comment-15140770

IMO attaching the same patch to this thread would be redundant since it is already available in the mentioned thread.

avpaderno’s picture

It is the other issue that is doing off-topic changes. If I open an issue to avoid calls to t() in classes, I cannot then fix all the coding standards issues reported by a tool, or I would change the topic of the issue.

avpaderno’s picture

Issue summary: View changes
Issue tags: +Needs reroll

I also not get any error about invalid end-of-line characters, when I run PHP_CodeSniffer.

keshav.k made their first commit to this issue’s fork.

keshavv’s picture

Status: Needs work » Needs review

I have scanned the module with the command

../vendor/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml  modules/custom/realname

and fixed all pending issues.

Now we can review and merge it.

Thank you.

roberttabigue’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new395.06 KB
new68.17 KB

Hi,

I applied the latest MR !12 to the Real Name module against 2.x-dev on Drupal 9.5.10 and confirmed all PHPCS errors have been fixed.

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

Please see the attached files for reference.

I'm moving this now to RTBC.

Thank you!

avpaderno’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs reroll
nitin_lama’s picture

Assigned: Unassigned » nitin_lama
nitin_lama’s picture

Assigned: nitin_lama » Unassigned
Status: Needs work » Needs review
avpaderno’s picture

Status: Needs review » Needs work
nitin_lama’s picture

Assigned: Unassigned » nitin_lama
nitin_lama’s picture

Assigned: nitin_lama » Unassigned
Status: Needs work » Needs review
yashaswi18’s picture

Hello, I cloned the repository, checked out to the branch '3352347-fix-the-issues', ran the command phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml. Found one error remaining:

FILE: C:\Users\YASHASWI\OneDrive\Desktop\Contrib\realname\src\Controller\Realnam
-------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-------------------------------------------------------------------------------------------------------------------------------------------
 24 | ERROR | The array declaration extends to column 92 (the limit is 80). The The array content should be split up over multiple lines
-------------------------------------------------------------------------------------------------------------------------------------------
nitinkumar_7’s picture

Hi, @Yashaswi18, can you please provide steps to reproduce these errors you found?

I have also applied the latest MR !12 and checked out to the branch '3352347-fix-the-issues'.
I scanned the module with the command:

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

and confirmed all PHPCS errors have been fixed.

Thank you

nitinkumar_7’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new23.92 KB

Applied the latest MR !12 and checked out to the branch '3352347-fix-the-issues'.
I have scanned module with this command :

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

all PHPCS errors have been fixed.
screenshot is attached for reference
after

Moving this to RTBC

nitinkumar_7’s picture

Issue summary: View changes