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

Created on 11 July 2023, 12 months ago
Updated 25 January 2024, 5 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

Needs review

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 12 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 8.1 & MySQL 5.7
    last update 12 months 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

Production build 0.69.0 2024