Fix the issues reported by phpcs

Created on 5 April 2023, over 1 year ago
Updated 4 April 2024, 8 months ago

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 ๐Ÿ“Œ t() should not be used in test classes Needs review .

๐Ÿ“Œ Task
Status

RTBC

Version

2.0

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia Raghavendra A M

Live updates comments and jobs are added and updated live.
  • Coding standards

    It involves compliance with, or the content of coding standards. Requires broad community agreement.

Sign in to follow issues

Comments & Activities

  • Issue created by @Raghavendra A M
  • Assigned to omkar_yewale
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar_yewale Mumbai
  • @omkar_yewale opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar_yewale Mumbai

    !12 MR created, Please Review.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Akram Khan Cuttack, Odisha

    checked above MR it fixed the PHPCS issue

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    -    // 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.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sumit-k

    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 ๐Ÿ“Œ t() should not be used in test classes Needs review

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

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

    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.

  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น

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

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia keshavv India

    keshav.k โ†’ made their first commit to this issueโ€™s fork.

  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 8
    last update over 1 year ago
    CI error
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia keshavv India

    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.

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ต๐Ÿ‡ญPhilippines roberttabigue

    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!

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • Assigned to nitin_lama
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nitin_lama India
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 8
    last update over 1 year ago
    4 pass
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nitin_lama India
  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
  • Assigned to nitin_lama
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nitin_lama India
  • Open in Jenkins โ†’ Open on Drupal.org โ†’
    Core: 9.5.x + Environment: PHP 7.3 & MySQL 8
    last update over 1 year ago
    4 pass
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nitin_lama India
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Yashaswi18

    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
    -------------------------------------------------------------------------------------------------------------------------------------------
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Nitinkumar_7

    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

  • Status changed to RTBC 8 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Nitinkumar_7

    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

    Moving this to RTBC

Production build 0.71.5 2024