\Drupal calls should be avoided in classes, use dependency injection instead

Created on 11 July 2023, over 1 year ago
Updated 30 July 2024, 4 months ago

Problem/Motivation

FILE: /Users/ashutoshahirwal/Sites/lando/contribution/web/modules/custom/gcontent_moderation/tests/modules/gcontent_moderation_test/src/GroupStateTransitionValidation.php
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 6 ERRORS AFFECTING 6 LINES
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
12 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Entity\EntityTypeManagerInterface.
33 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
34 | ERROR | [x] Expected 5 space(s) before asterisk; 3 found
35 | ERROR | [x] Expected 5 space(s) before asterisk; 3 found
36 | ERROR | [x] Expected 5 space(s) before asterisk; 3 found
37 | ERROR | [x] Expected 5 space(s) before asterisk; 3 found
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

FILE: /Users/ashutoshahirwal/Sites/lando/contribution/web/modules/custom/gcontent_moderation/tests/src/Functional/ContentModerationIntegrationTest.php
------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AND 4 WARNINGS AFFECTING 5 LINES
------------------------------------------------------------------------------------------------------------------------------------------------------
151 | ERROR | The array declaration extends to column 86 (the limit is 80). The array content should be split up over multiple lines
173 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
188 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
190 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
204 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
------------------------------------------------------------------------------------------------------------------------------------------------------

Time: 346ms; Memory: 12MB

Steps to reproduce

./vendor/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,css,js,yml web/modules/custom/gcontent_moderation

šŸ“Œ Task
Status

RTBC

Version

1.0

Component

Code

Created by

šŸ‡®šŸ‡³India sidharth_soman Bangalore

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 @sidharth_soman
  • 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 & MySQL 5.7
    last update over 1 year ago
    run-tests.sh fatal error
  • šŸ‡®šŸ‡³India sidharth_soman Bangalore

    I have implemented the DI. Please review.

  • šŸ‡®šŸ‡³India Ashutosh Ahirwal India

    Provided patch in #2 get applied cleanly but there are still some error found
    Providing updated patch

    ./vendor/bin/phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,info,txt,md,css,js,yml web/modules/custom/gcontent_moderation

    FILE: /Users/ashutoshahirwal/Sites/lando/contribution/web/modules/custom/gcontent_moderation/tests/modules/gcontent_moderation_test/src/GroupStateTransitionValidation.php
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 6 ERRORS AFFECTING 6 LINES
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    12 | ERROR | [x] Use statements should be sorted alphabetically. The first wrong one is Drupal\Core\Entity\EntityTypeManagerInterface.
    33 | ERROR | [x] Line indented incorrectly; expected 2 spaces, found 4
    34 | ERROR | [x] Expected 5 space(s) before asterisk; 3 found
    35 | ERROR | [x] Expected 5 space(s) before asterisk; 3 found
    36 | ERROR | [x] Expected 5 space(s) before asterisk; 3 found
    37 | ERROR | [x] Expected 5 space(s) before asterisk; 3 found
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    PHPCBF CAN FIX THE 6 MARKED SNIFF VIOLATIONS AUTOMATICALLY
    --------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    FILE: /Users/ashutoshahirwal/Sites/lando/contribution/web/modules/custom/gcontent_moderation/tests/src/Functional/ContentModerationIntegrationTest.php
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    FOUND 1 ERROR AND 4 WARNINGS AFFECTING 5 LINES
    ------------------------------------------------------------------------------------------------------------------------------------------------------
    151 | ERROR | The array declaration extends to column 86 (the limit is 80). The array content should be split up over multiple lines
    173 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    188 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    190 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    204 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead
    ------------------------------------------------------------------------------------------------------------------------------------------------------

    Time: 346ms; Memory: 12MB

  • Status changed to RTBC 4 months ago
  • šŸ‡µšŸ‡­Philippines cleavinjosh

    Hi @Ashutosh Ahirwal,

    I applied your patch, it was applied smoothly and fixed the phpcs issues.

    āžœ  gcontent_moderation git:(1.x) curl https://www.drupal.org/files/issues/2024-01-25/phpcs-issue-fixes_1.patch | patch -p1
      % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                     Dload  Upload   Total   Spent    Left  Speed
    100  5576  100  5576    0     0  16156      0 --:--:-- --:--:-- --:--:-- 16209
    patching file tests/modules/gcontent_moderation_test/gcontent_moderation_test.services.yml
    patching file tests/modules/gcontent_moderation_test/src/GroupStateTransitionValidation.php
    patching file tests/src/Functional/ContentModerationIntegrationTest.php
    āžœ  gcontent_moderation git:(1.x) āœ— ..
    āžœ  contrib phpcs --standard=Drupal,DrupalPractice --extensions=php,module,inc,install,test,profile,theme,css,info,txt,md,yml gcontent_moderation
    āžœ  contrib

    Thank you.

Production build 0.71.5 2024