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

Issue fork storage-3334370

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

samit.310@gmail.com created an issue. See original summary.

samitk’s picture

Assigned: samitk » Unassigned
Status: Needs work » Needs review
StatusFileSize
new18.79 KB

Error/warnings are fixed.

Also i removed public function postSave(EntityStorageInterface $storage, $update = TRUE) { function from src/Entity/StorageType.php path. As that function doesn't have any function definition.

Charchil Khandelwal made their first commit to this issue’s fork.

charchil khandelwal’s picture

Assigned: Unassigned » charchil khandelwal
Issue tags: -, -

I will review this.

charchil khandelwal’s picture

Assigned: charchil khandelwal » Unassigned

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

mxh’s picture

Status: Needs review » Needs work

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

samitk’s picture

Status: Needs work » Needs review
StatusFileSize
new20.07 KB
new1.27 KB

Hi @mxh,

Thanks for the review, string_translation service has been added.

Please review.

avpaderno’s picture

Title: Drupal Coding Standards Issues | phpcs » Fix the issues reported by phpcs
Category: Bug report » Task
Priority: Normal » Minor
Status: Needs review » Needs work
Issue tags: +Coding standards
-  /**
-   * {@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.

chaitanyadessai’s picture

Status: Needs work » Needs review
StatusFileSize
new20.38 KB

Please review patch.

sidharth_soman’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new10.95 KB
new52.65 KB

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

Moving to RTBC.

avpaderno’s picture

Status: Reviewed & tested by the community » Needs work
+    $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.

mrinalini9’s picture

Status: Needs work » Needs review
StatusFileSize
new21.26 KB
new1.82 KB

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

Thanks & Regards,
Mrinalini

shiv_sharma’s picture

Status: Needs review » Needs work
StatusFileSize
new171.33 KB
new157 KB

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

nitin_lama’s picture

Assigned: Unassigned » nitin_lama
nitin_lama’s picture

Assigned: nitin_lama » Unassigned
nikolay shapovalov’s picture

Status: Needs work » Needs review
StatusFileSize
new22.82 KB
new4.07 KB

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().

a.aaronjake’s picture

Status: Needs review » Needs work

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

atul_ghate made their first commit to this issue’s fork.

atul_ghate’s picture

Status: Needs work » Needs review
StatusFileSize
new115.8 KB

Added MR to fix all phpcs issue please.

a.aaronjake’s picture

Status: Needs review » Reviewed & tested by the community

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

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

apaderno changed the visibility of the branch 1.1.x to hidden.

avpaderno’s picture

mandclu made their first commit to this issue’s fork.

mandclu’s picture

Version: 1.1.x-dev » 1.4.x-dev

  • mandclu committed d9de8ff0 on 1.4.x authored by atul_ghate
    task: #3334370 Fix the issues reported by phpcs
    
    By: mxh
    By: avpaderno...
mandclu’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for everyone's work here. I updated this for the 1.4.x branch and merged it in.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.