Fix the Coding standards reported by phpcs

Created on 5 July 2023, over 1 year ago
Updated 6 July 2023, over 1 year ago

Problem/Motivation

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

FILE: /var/www/html/vb9/web/modules/contrib/index_now/src/Service/IndexNow.php
------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
------------------------------------------------------------------------------
99 | WARNING | Only string literals should be passed to t() where possible
107 | WARNING | Only string literals should be passed to t() where possible
------------------------------------------------------------------------------

FILE: /var/www/html/vb9/web/modules/contrib/index_now/src/Form/ModuleSettingsForm.php
-------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
-------------------------------------------------------------------------------------
248 | WARNING | #options values usually have to run through t() for translation
249 | WARNING | #options values usually have to run through t() for translation
250 | WARNING | #options values usually have to run through t() for translation
251 | WARNING | #options values usually have to run through t() for translation
-------------------------------------------------------------------------------------

FILE: /var/www/html/vb9/web/modules/contrib/index_now/tests/src/Kernel/IndexNowKeyManagerTest.php
--------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
--------------------------------------------------------------------------------------------------
6 | WARNING | [x] Unused use statement
55 | ERROR | [x] Functions must not contain multiple empty lines in a row; found 2 empty lines
--------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------

FILE: /var/www/html/vb9/web/modules/contrib/index_now/index_now.install
-----------------------------------------------------------------------
FOUND 1 ERROR AND 1 WARNING AFFECTING 2 LINES
-----------------------------------------------------------------------
1 | ERROR | [x] Missing file doc comment
15 | WARNING | [ ] Unused variable $api_key.
-----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------

Time: 1.72 secs; Memory: 12MB

Steps to reproduce

RUN:

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

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Fixed

Version

2.0

Component

Code

Created by

🇮🇳India dineshkumarbollu

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 @dineshkumarbollu
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    Waiting for branch to pass
  • Assigned to MacSim
  • Status changed to Needs work over 1 year ago
  • 🇫🇷France MacSim

    Hi @dineshkumarbollu

    First of all, thanks for opening this issue.
    I was wondering if I should have opened a RC release and finally decided to go straight to a 2.0.0 version.
    Pretty bad move since I forgot to run PHPCS and PHPUnit before to do it... 😅

    Tests have been fixed this afternoon now let's talk about PHPCS:

    I won't fix the following warnings:

    FILE: /var/www/html/vb9/web/modules/contrib/index_now/src/Service/IndexNow.php
    ------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
    ------------------------------------------------------------------------------
    99 | WARNING | Only string literals should be passed to t() where possible
    107 | WARNING | Only string literals should be passed to t() where possible
    ------------------------------------------------------------------------------
    

    Because:

    1. I don't want to duplicate the message in the code,
    2. I want the message to be translated when displayed to the user but I want it in english in the logs to keep the debug easier (we can search and find the error message in english in the code ; if it is translated in the logs we won't find it in the code)
    FILE: /var/www/html/vb9/web/modules/contrib/index_now/src/Form/ModuleSettingsForm.php
    -------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 4 LINES
    -------------------------------------------------------------------------------------
    248 | WARNING | #options values usually have to run through t() for translation
    249 | WARNING | #options values usually have to run through t() for translation
    250 | WARNING | #options values usually have to run through t() for translation
    251 | WARNING | #options values usually have to run through t() for translation
    -------------------------------------------------------------------------------------
    

    Because those strings represent trademarks and there's no need to translate a trademark.

    But I am adding to your list some other standards reported by my own PHPCS that need to be fixed as well:

    FILE: /var/www/arvalis/web/modules/contrib/index_now/index_now.module
    ----------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------------
     11 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\index_now\NodeOperations.
    ----------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------------------------
    
    
    FILE: /var/www/arvalis/web/modules/contrib/index_now/tests/src/Unit/NodeOperationsTest.php
    ----------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------------
     12 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Tests\UnitTestCase.
    ----------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------------------------
    
    
    FILE: /var/www/arvalis/web/modules/contrib/index_now/tests/src/Unit/TermOperationsTest.php
    ----------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AFFECTING 1 LINE
    ----------------------------------------------------------------------------------------------------
     9 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\index_now\Service\IndexNowInterface.
    ----------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    ----------------------------------------------------------------------------------------------------
    
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    14 pass
  • Hello @MacSim,
    Hope you are doing well,
    Created a patch for index_now version 2.0.x-dev . Updated all the changes mentioned in #3. The patch seems to fix the errors and warnings.

    Kindly review the patch.
    Thank you.

  • Status changed to Fixed over 1 year ago
  • 🇫🇷France MacSim

    Thanks to both you.

    Last patch has been merged to 2.0.x and will be part of the next release

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

Production build 0.71.5 2024