Fix the issues reported by phpcs

Created on 18 January 2023, almost 2 years ago
Updated 31 May 2024, 7 months ago

Problem/Motivation

Getting following error/warnings

FILE: /var/www/html/modules/contrib/storage/storage.routing.yml
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
18 | ERROR | [x] Expected 1 newline at end of file; 2 found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/config/schema/storage.schema.yml
----------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------------
10 | ERROR | [x] Expected 1 newline at end of file; 2 found
----------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/storage.tokens.inc
-----------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------
127 | WARNING | Only string literals should be passed to t() where possible
-----------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/src/Form/StorageSettingsForm.php
-----------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------
12 | WARNING | The class short comment should describe what the class does and not simply repeat the class name
-----------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/src/Form/StorageRevisionDeleteForm.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------------------------------------------------
94 | ERROR | The array declaration extends to column 169 (the limit is 80). The array content should be split up over multiple lines
95 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
95 | ERROR | The array declaration extends to column 249 (the limit is 80). The array content should be split up over multiple lines
-----------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/src/Form/StorageRevisionRevertForm.php
------------------------------------------------------------------------------------------------------------------------------------------
FOUND 2 ERRORS AND 1 WARNING AFFECTING 2 LINES
------------------------------------------------------------------------------------------------------------------------------------------
118 | ERROR | The array declaration extends to column 170 (the limit is 80). The array content should be split up over multiple lines
119 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
119 | ERROR | The array declaration extends to column 226 (the limit is 80). The array content should be split up over multiple lines
------------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/src/Form/StorageTypeForm.php
------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 11 WARNINGS AFFECTING 11 LINES
------------------------------------------------------------------------------------------------------------------------------------------
118 | WARNING | Line exceeds 80 characters; contains 88 characters
133 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
135 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
140 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
142 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
147 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
149 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
154 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
156 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
167 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
169 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
------------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/src/Form/StorageForm.php
---------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
---------------------------------------------------------------------------------------------
60 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
---------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/src/Access/StorageRevisionAccessCheck.php
----------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------
125 | WARNING | \Drupal calls should be avoided in classes, use dependency injection instead
----------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/src/StorageViewsData.php
-----------------------------------------------------------------------------
FOUND 0 ERRORS AND 4 WARNINGS AFFECTING 3 LINES
-----------------------------------------------------------------------------
69 | WARNING | [x] There must be no blank line following an inline comment
69 | WARNING | [ ] There must be no blank line following an inline comment
292 | WARNING | [ ] Line exceeds 80 characters; contains 82 characters
327 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
-----------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
-----------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/src/Entity/StorageType.php
------------------------------------------------------------------------
FOUND 6 ERRORS AND 3 WARNINGS AFFECTING 8 LINES
------------------------------------------------------------------------
166 | WARNING | [ ] Possible useless method overriding detected
169 | ERROR | [x] Inline comments must start with a capital letter
170 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
170 | ERROR | [ ] Comment indentation error, expected only 1 spaces
172 | ERROR | [ ] Comment indentation error, expected only 3 spaces
173 | ERROR | [ ] Comment indentation error, expected only 5 spaces
175 | WARNING | [ ] Line exceeds 80 characters; contains 81 characters
177 | ERROR | [ ] Comment indentation error, expected only 7 spaces
184 | ERROR | [ ] Comment indentation error, expected only 1 spaces
------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/src/Controller/StorageController.php
---------------------------------------------------------------------------------------------------------------------------------------------
FOUND 6 ERRORS AND 1 WARNING AFFECTING 6 LINES
---------------------------------------------------------------------------------------------------------------------------------------------
111 | WARNING | [ ] \Drupal calls should be avoided in classes, use dependency injection instead
130 | ERROR | [x] Line indented incorrectly; expected 6 spaces, found 4
130 | ERROR | [x] Object operator not indented correctly; expected 6 spaces but found 4
131 | ERROR | [x] Object operator not indented correctly; expected 4 spaces but found 6
186 | ERROR | [ ] The array declaration extends to column 141 (the limit is 80). The array content should be split up over multiple lines
215 | ERROR | [ ] The array declaration extends to column 138 (the limit is 80). The array content should be split up over multiple lines
216 | ERROR | [x] Expected newline after closing brace
---------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 4 MARKED SNIFF VIOLATIONS AUTOMATICALLY
---------------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/src/StoragePermissions.php
-----------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
-----------------------------------------------------------------------------------------------------------------------------------------
78 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
82 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
-----------------------------------------------------------------------------------------------------------------------------------------

FILE: /var/www/html/modules/contrib/storage/src/StorageListBuilder.php
----------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------------------
22 | WARNING | [x] A comma should follow the last multiline array item. Found: ]
34 | WARNING | [x] Inline @var declarations should use the /** */ delimiters
----------------------------------------------------------------------------------
PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------------------

Time: 2 secs; Memory: 6MB

Steps to reproduce

Run following command

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

Proposed resolution

Above error/warnings need to be fixed

๐Ÿ“Œ Task
Status

RTBC

Version

1.1

Component

Code

Created by

๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

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.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Charchil Khandelwal

    Charchil Khandelwal โ†’ made their first commit to this issueโ€™s fork.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Charchil Khandelwal

    I will review this.

  • @charchil-khandelwal opened merge request.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Charchil Khandelwal

    Thanks @samit.310@gmail.com, patch #2 applied cleanly, all errors and warnings are fixed.
    And i also created MR for same.
    Please review.

  • Status changed to Needs work almost 2 years ago
  • ๐Ÿ‡ฉ๐Ÿ‡ชGermany mxh Offenburg

    In the StorageTypeForm class, the dependency injection of the string_translation service is missing.

  • Status changed to Needs review almost 2 years ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

    Hi @mxh,

    Thanks for the review, string_translation service has been added.

    Please review.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    -  /**
    -   * {@inheritdoc}
    -   */
    -  public function postSave(EntityStorageInterface $storage, $update = TRUE) {
    -    parent::postSave($storage, $update);
    -
    -    // if ($update && $this->getOriginalId() != $this->id()) {
    -    //   $update_count = node_type_update_nodes($this->getOriginalId(), $this->id());
    -    //   if ($update_count) {
    -    //     \Drupal::messenger()->addStatus(\Drupal::translation()->formatPlural(
    -    //       $update_count,
    -    //       'Changed the storage type of 1 post from %old-type to %type.',
    -    //       'Changed the storage type of @count posts from %old-type to %type.',
    -    //       [
    -    //         '%old-type' => $this->getOriginalId(),
    -    //         '%type' => $this->id(),
    -    //       ]
    -    //     ));
    -    //   }
    -    // }
    -    // if ($update) {
    -    //   // Clear the cached field definitions as some settings affect the field
    -    //   // definitions.
    -    //   \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
    -    // }
    -  }

    I am not sure it is correct to remove that method. The commented out code could be code maintainers temporary commented out to then change it.

     /**
    - * Class StorageSettingsForm.
    + * The StorageSettingsForm class.

    That description is still repeating the class name without describing what the class purpose is.

    -        // Automatically join to the storage table (or actually, storage_field_data).
    +        // Automatically join to the storage table
    +        // (or actually, storage_field_data).
             // Use a Views table alias to allow other modules to use this table too,
             // if they use the search index.

    Avoiding that lines exceed 80 characters does not making shortening them to 50 characters. Also, when a comment line is shortened, all comment must be reformatted.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia chaitanyadessai Goa

    Please review patch.

  • Status changed to RTBC over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sidharth_soman Bangalore

    Patch #10 applies cleanly and resolves all errors. I have attached the relevant screenshots.

    Moving to RTBC.

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
    +    $this->logger('content')->notice('Storage: deleted %name revision %revision.', [
    +      '%name' => $this->revision->label(),
    +      '%revision' => $this->revision->getRevisionId(),
    +    ]);
    +    $this->messenger()->addMessage($this->t('Revision from %revision-date of Storage %name has been deleted.', [
    +      '%revision-date' => \Drupal::service('date.formatter')->format($this->revision->getRevisionCreationTime()),
    +      '%name' => $this->revision->label(),
    +    ]));

    The code is still using \Drupal to inject dependencies.

     /**
    - * Class StorageSettingsForm.
    + * The StorageSettingsForm class.

    Like the existing comment, the changed comment is still repeating the class name.

    +/**
    + * @file
    + * File description.
    + */
    +

    That does not describe the file purpose.
    I suggest to check the description used by Drupal core for those files.

  • Status changed to Needs review over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia mrinalini9 New Delhi

    Updated patch #10 by addressing #12, please review it.

    Thanks & Regards,
    Mrinalini

  • Status changed to Needs work over 1 year ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia Shiv_Sharma

    @Mrinalini I applied your patch it applied successfully but still able to see some warning which can be fix by phpcbf.

  • Assigned to nitin_lama
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nitin_lama India
  • Issue was unassigned.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia nitin_lama India
  • Status changed to Needs review about 1 year ago
  • ๐Ÿ‡ท๐Ÿ‡บRussia zniki.ru

    Fixes issue mentioned in #9 and #12.
    We can disable phpcs for StorageType::postSave() to fix violation we still have, or we can completely remove this method. Maintainer can always get the code from git history. I'd prefer removing postSave().

  • Status changed to Needs work 7 months ago
  • Hi @Nikolay Shapovalov,

    Applied patch #17 successfully, however it threw 6 errors and 3 warnings.

    storage git:(1.1.x) curl https://www.drupal.org/files/issues/2023-11-17/3334370-17.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 23366  100 23366    0     0  57595      0 --:--:-- --:--:-- --:--:-- 59759
    patching file config/schema/storage.schema.yml
    patching file src/Access/StorageRevisionAccessCheck.php
    patching file src/Controller/StorageController.php
    patching file src/Entity/Storage.php
    patching file src/Entity/StorageInterface.php
    patching file src/Form/StorageForm.php
    patching file src/Form/StorageRevisionDeleteForm.php
    patching file src/Form/StorageRevisionRevertForm.php
    patching file src/Form/StorageSettingsForm.php
    patching file src/Form/StorageTypeForm.php
    patching file src/StorageAccessControlHandler.php
    patching file src/StorageListBuilder.php
    patching file src/StoragePermissions.php
    patching file src/StorageStorage.php
    patching file src/StorageStorageInterface.php
    patching file src/StorageViewsData.php
    patching file storage.post_update.php
    patching file storage.routing.yml
    patching file storage.tokens.inc
    โžœ  storage git:(1.1.x) โœ— cd ..
    โžœ  contrib git:(main) โœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig storage
    
    FILE: /Users/PrometInterns/Demo-site/drupal-orgissue/web/modules/contrib/storage/src/Entity/StorageType.php
    -----------------------------------------------------------------------------------------------------------
    FOUND 6 ERRORS AND 3 WARNINGS AFFECTING 8 LINES
    -----------------------------------------------------------------------------------------------------------
     166 | WARNING | [ ] Possible useless method overriding detected
     169 | ERROR   | [x] Inline comments must start with a capital letter
     170 | WARNING | [ ] Line exceeds 80 characters; contains 85 characters
     170 | ERROR   | [ ] Comment indentation error, expected only 1 spaces
     172 | ERROR   | [ ] Comment indentation error, expected only 3 spaces
     173 | ERROR   | [ ] Comment indentation error, expected only 5 spaces
     175 | WARNING | [ ] Line exceeds 80 characters; contains 81 characters
     177 | ERROR   | [ ] Comment indentation error, expected only 7 spaces
     184 | ERROR   | [ ] Comment indentation error, expected only 1 spaces
    -----------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    -----------------------------------------------------------------------------------------------------------
    
    Time: 1.12 secs; Memory: 12MB

    Kindly check.

    Thanks,
    Jake

  • First commit to issue fork.
  • Status changed to Needs review 7 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia atul_ghate

    Added MR to fix all phpcs issue please.

  • Status changed to RTBC 7 months ago
  • Hi @atul_ghate,

    Applied latest MR!16 version successfully, confirmed all issues fixed.

    storage git:(1.1.x) โœ— curl https://git.drupalcode.org/project/storage/-/merge_requests/16.diff | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100 26758    0 26758    0     0  66117      0 --:--:-- --:--:-- --:--:-- 67570
    patching file config/schema/storage.schema.yml
    patching file src/Access/StorageRevisionAccessCheck.php
    patching file src/Controller/StorageController.php
    patching file src/Entity/Storage.php
    patching file src/Entity/StorageInterface.php
    patching file src/Entity/StorageType.php
    patching file src/Form/StorageForm.php
    Hunk #1 succeeded at 22 with fuzz 2.
    Hunk #2 FAILED at 36.
    Hunk #3 FAILED at 65.
    2 out of 3 hunks FAILED -- saving rejects to file src/Form/StorageForm.php.rej
    patching file src/Form/StorageRevisionDeleteForm.php
    patching file src/Form/StorageRevisionRevertForm.php
    patching file src/Form/StorageSettingsForm.php
    patching file src/Form/StorageTypeForm.php
    patching file src/StorageAccessControlHandler.php
    patching file src/StorageListBuilder.php
    patching file src/StoragePermissions.php
    patching file src/StorageStorage.php
    patching file src/StorageStorageInterface.php
    patching file src/StorageViewsData.php
    patching file storage.post_update.php
    patching file storage.routing.yml
    patching file storage.tokens.inc
    โžœ  storage git:(1.1.x) โœ— cd ..
    โžœ  contrib git:(main) โœ— phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml,twig storage
    โžœ  contrib git:(main) โœ—

    Will move this to RTBC.

    Thanks,
    Jake

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

    apaderno โ†’ changed the visibility of the branch 3334370-drupal-coding-standards to hidden.

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

    apaderno โ†’ changed the visibility of the branch 1.1.x to hidden.

  • Pipeline finished with Success
    7 months ago
    Total: 263s
    #186886
  • ๐Ÿ‡ฎ๐Ÿ‡นItaly apaderno Brescia, ๐Ÿ‡ฎ๐Ÿ‡น
Production build 0.71.5 2024