Fix the issues reported by phpcs

Created on 10 February 2023, almost 2 years ago
Updated 13 January 2024, 10 months ago

Problem/Motivation

Getting the following phpcs errors/warnings:

FILE: /Documents/config_ignore/tests/modules/config_ignore_hook_test.info.yml
----------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------
 7 | WARNING | All dependencies must be prefixed with the project name, for example "drupal:"
----------------------------------------------------------------------------------------------------


FILE: /Documents/config_ignore/tests/src/Functional/ConfigIgnoreBrowserTestBase.php
---------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
---------------------------------------------------------------------------------------------------------------------
  6 | WARNING | [x] Unused use statement
  8 | WARNING | [x] Unused use statement
 15 | WARNING | [ ] The class short comment should describe what the class does and not simply repeat the class name
---------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------


FILE: /Documents/config_ignore/tests/src/Functional/ConfigIgnoreTest.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------
 34 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
-----------------------------------------------------------------------------------------------------------------------------------------


FILE: /Documents/config_ignore/tests/src/Functional/ConfigWithTranslationTest.php
-------------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
-------------------------------------------------------------------------------------------------------------------------------------
 91 | ERROR | The array declaration extends to column 82 (the limit is 80). The array content should be split up over multiple lines
 95 | ERROR | The array declaration extends to column 83 (the limit is 80). The array content should be split up over multiple lines
-------------------------------------------------------------------------------------------------------------------------------------


FILE: /Documents/config_ignore/tests/src/Kernel/IgnoreKernelTest.php
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 16 ERRORS AND 9 WARNINGS AFFECTING 21 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 154 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
 163 | ERROR   | [x] 6 spaces found before inline comment; expected "// 'new config is not ignored in lenient mode' => [" but found "//      'new config is not ignored in lenient mode' => ["
 164 | ERROR   | [ ] Comment indentation error, expected only 6 spaces
 167 | ERROR   | [ ] Comment indentation error, expected only 8 spaces
 168 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
 168 | ERROR   | [ ] Comment indentation error, expected only 10 spaces
 172 | ERROR   | [ ] Comment indentation error, expected only 8 spaces
 173 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
 173 | ERROR   | [ ] Comment indentation error, expected only 10 spaces
 174 | WARNING | [ ] Line exceeds 80 characters; contains 81 characters
 179 | ERROR   | [ ] Comment indentation error, expected only 8 spaces
 180 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
 180 | ERROR   | [ ] Comment indentation error, expected only 10 spaces
 181 | WARNING | [ ] Line exceeds 80 characters; contains 81 characters
 188 | ERROR   | [ ] The array declaration extends to column 82 (the limit is 80). The array content should be split up over multiple lines
 188 | ERROR   | [ ] The array declaration extends to column 81 (the limit is 80). The array content should be split up over multiple lines
 192 | ERROR   | [x] 6 spaces found before inline comment; expected "// 'new config with  only key ignored lenient (issue 3137437)' => [" but found "//      'new config with  only key ignored lenient
     |         |     (issue 3137437)' => ["
 193 | ERROR   | [ ] Comment indentation error, expected only 6 spaces
 195 | WARNING | [ ] Line exceeds 80 characters; contains 91 characters
 197 | WARNING | [ ] Line exceeds 80 characters; contains 91 characters
 202 | ERROR   | [ ] Parameter $modes is not described in comment
 205 | ERROR   | [ ] Doc comment for parameter $mode does not match actual variable name $expected
 206 | ERROR   | [x] Parameter comment must end with a full stop
 229 | ERROR   | [ ] Description for the @return value is missing
 232 | WARNING | [x] '@todo: add meaningful tests in https://www.drupal.org/project/config_ignore/issues/2857247' should match the format '@todo Fix problem X here.'
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 5 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


FILE: /Documents/config_ignore/config_ignore.install
---------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
---------------------------------------------------------------------------
 30 | ERROR | [x] Expected 1 newline at end of file; 2 found
---------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------

Steps to reproduce

Run the following command from the module folder.

phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml .

Proposed resolution

Fix the errors and warnings.

📌 Task
Status

Fixed

Version

3.0

Component

Code

Created by

🇮🇳India mrinalini9 New Delhi

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

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Issue created by @mrinalini9
  • Issue was unassigned.
  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India mrinalini9 New Delhi

    Added patch for the above phpcs fixes, please review it.

    Thanks & Regards,
    Mrinalini

  • 🇮🇳India rajneeshb New Delhi

    Reviewed patch #3 patch applied successfully and all reported coding standard issue fixed. Looks good +1 RTBC

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs work over 1 year ago
  • First commit to issue fork.
  • Merge request !15fix phpcs issues → (Closed) created by mukhtarm
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
       /**
        * {@inheritdoc}
    @@ -34,7 +31,9 @@ abstract class ConfigIgnoreBrowserTestBase extends BrowserTestBase {
       public function doImport() {
         // Set up the ConfigImporter object for testing.
         $storage_comparer = new StorageComparer(
    -      $this->getImportStorage(),
    +      $this->container->get('config.import_transformer')->transform(
    +        $this->container->get('config.storage.sync')
    

    Does a class that extends BroweserTestBase have access to $this->container? It is not listed in the class properties.

    -//      'new config is not ignored in lenient mode' => [
    -//        ['lenient'],
    -//        ['config_test.*'],
    -//        [
    -//          '' => [
    -//            'config_test.dynamic.exist' => ['id' => 'exist', 'label' => 'E'],
    -//          ],
    -//        ],
    -//        [
    -//          '' => [
    -//            'config_test.dynamic.exist' => ['id' => 'exist', 'label' => 'N'],
    -//            'config_test.dynamic.new' => ['id' => 'new', 'label' => 'N'],
    -//            'config_test.system' => ['foo' => 'ignored']
    -//          ],
    -//        ],
    -//        [
    -//          '' => [
    -//            'config_test.dynamic.exist' => ['id' => 'exist', 'label' => 'E'],
    -//            'config_test.dynamic.new' => ['id' => 'new', 'label' => 'N'],
    -//          ],
    -//        ],
    -//      ],
    +      // 'new config is not ignored in lenient mode' => [
    +      //        ['lenient'],
    +      //        ['config_test.*'],
    +      //        [
    

    Line indentation, as per Drupal coding standards, is two spaces.
    I am not sure it is worth editing commented out code, though.

    -    // @todo: add meaningful tests in https://www.drupal.org/project/config_ignore/issues/2857247
    +    // @todo add meaningful tests in https://www.drupal.org/project/config_ignore/issues/2857247
    

    What follows @todo is a sentence: It starts with a capitalized word and ends with a period.
    Also, that sentence is wrong: Tests are not added in an issue report; they are added as reported in an issue report.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India chaitanyadessai Goa

    adding patch, applied following phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig

  • Status changed to Needs work over 1 year ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
    -  - config_ignore
    +  - drupal:config_ignore

    The modules for this project are not part of Drupal core; their project machine name cannot be drupal.

     /**
    - * Class ConfigIgnoreBrowserTestBase.
    + * Abstract class Definition.

    That description does not describe the class. It does not even make sense, since that is not an abstract class.

    -    $this->assertSame(['name' => 'config_ignore.settings', 'state' => 'Different'], $diff['config_ignore.settings']);
    +    $this->assertSame([
    +      'name' => 'config_ignore.settings',
    +      'state' => 'Different',
    +    ], $diff['config_ignore.settings']);
    -        ['' => ['config_test.dynamic.exist' => ['id' => 'exist', 'label' => 'E']]],
    +        [
    +          '' => [
    +            'config_test.dynamic.exist' =>
    +        ['id' => 'exist', 'label' => 'E'],
    +          ],
    +        ],

    Code lines can exceed 80 characters, if they are more readable. I do not find the changed code more readable.

    -   * @param string $mode
    -   *   The export mode
    +   * @param string $modes
    +   *   The export mode.

    That method is declared as public function testExport(array $modes, array $patterns, array $active, array $sync, array $expected). It means that $modes type is array (not string) and its description must be The export modes. (since an array can contain more values).

        * @return array
    +   *   Test case.

    Since it is an array, its description should be The test cases.

    -    // @todo: add meaningful tests in https://www.drupal.org/project/config_ignore/issues/2857247
    +    // @todo add meaningful tests in https://www.drupal.org/project/config_ignore/issues/2857247

    What follow @todo is a sentence: It starts with a capitalized word and it ends with a period (preferable), a question mark, or an exclamation point. If the sentences ends with a URL, the last punctuation mark is probably omitted.

  • Status changed to Needs review over 1 year ago
  • 🇮🇳India mrinalini9 New Delhi

    Updated patch #17 by addressing #18, please review it.

    Thanks!

  • 🇮🇳India arpitk

    Hi I reviewed the patch #19 .it applied cleanly. All the issues has been addressed and the update from #18 has been implemented. However the following errors is shown:

    FILE: /home/arpitkayare/drupal_9.5/web/modules/contrib/config_ignore/tests/src/Kernel/IgnoreKernelTest.php
    --------------------------------------------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 1 LINE
    --------------------------------------------------------------------------------------------------------------------------------------
    166 | ERROR | The array declaration extends to column 82 (the limit is 80). The array content should be split up over multiple lines
    166 | ERROR | The array declaration extends to column 81 (the limit is 80). The array content should be split up over multiple lines
    --------------------------------------------------------------------------------------------------------------------------------------

    FILE: /home/arpitkayare/drupal_9.5/web/modules/contrib/config_ignore/tests/src/Functional/ConfigWithTranslationTest.php
    -------------------------------------------------------------------------------------------------------------------------------------
    FOUND 2 ERRORS AFFECTING 2 LINES
    -------------------------------------------------------------------------------------------------------------------------------------
    91 | ERROR | The array declaration extends to column 82 (the limit is 80). The array content should be split up over multiple lines
    95 | ERROR | The array declaration extends to column 83 (the limit is 80). The array content should be split up over multiple lines
    -------------------------------------------------------------------------------------------------------------------------------------

    Time: 4.04 secs; Memory: 12MB

    Thanks!

  • Assigned to sourabhjain
  • Status changed to Needs work over 1 year ago
  • 🇮🇳India sourabhjain

    Let me work on this.

  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India sourabhjain

    Fixed issues mentioned in #20. Please review.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    18 pass, 2 fail
  • Status changed to Needs work over 1 year ago
  • 🇮🇳India arpitk

    Hi @sourabhjain I reviewed the patch #22. It applied cleanly all the errors/warnings are fixed. Running phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,js . returned clean.
    Keeping the status as Needs work as the test cases are failing that need to be be fixed as well.

    Thanks!

  • 🇮🇹Italy apaderno Brescia, 🇮🇹

    One of the tests failed because the following error.

    Error: Call to undefined method Drupal\Tests\config_ignore\Functional\ConfigIgnoreTest::t()

    Replacing t() calls with calls to $this->t() is not sufficient.

  • 🇮🇳India bharath-kondeti Hyderabad

    Addressed failed test cases.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4.x-dev & MySQL 5.7
    last update over 1 year ago
    run-tests.sh fatal error
  • 🇮🇳India bharath-kondeti Hyderabad

    Updated the patch as the previous one was failing.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 7.4.x-dev & MySQL 5.7
    last update over 1 year ago
    25 pass
  • Status changed to Needs review over 1 year ago
  • Status changed to Fixed about 1 year ago
  • 🇨🇭Switzerland bircher 🇨🇿

    phpcs is now fixed on the main branch as part of the refactoring.
    Thanks for working on this issue!

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

Production build 0.71.5 2024