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

Created on 25 April 2023, about 1 year ago
Updated 19 May 2023, about 1 year ago

Problem/Motivation

UserPasswordFormAlter.php throws a dependency injection error for the services.

Steps to reproduce

Run the phpcs command on the module.

Proposed resolution

Implement the dependency injection for the file.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Needs review

Version

2.0

Component

Code

Created by

🇮🇳India sidharth_soman Bangalore

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @sidharth_soman
  • @sidharth_soman opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India sidharth_soman Bangalore

    I have implemented the dependency injection and issued an MR. Please review.

  • Assigned to arpitk
  • Status changed to Needs work about 1 year ago
  • 🇮🇳India arpitk

    Hi @sidharth_soman, I reviewed the MR and found an issue. with UserPasswordFormAlter class. The $container->get('entity_type.manager') container is missing which is causing this error as follows:

    ArgumentCountError: Too few arguments to function Drupal\decoupled_auth\Form\UserPasswordFormAlter::__construct(), 2 passed in /app/web/modules/contrib/decoupled_auth-3356179/src/Form/UserPasswordFormAlter.php on line 58 and exactly 3 expected in Drupal\decoupled_auth\Form\UserPasswordFormAlter->__construct() (line 46 of /app/web/modules/contrib/decoupled_auth-3356179/src/Form/UserPasswordFormAlter.php)

    There are few more issue reported by phpcs here:

    FILE: /home/arpitkayare/drupal_9.5/web/modules/contrib/decoupled_auth-3356179/src/DecoupledAuthSettingsForm.php
    ---------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    ---------------------------------------------------------------------------------------------------------------
     117 | WARNING | Role::loadMultiple calls should be avoided in classes, use dependency injection instead
    
    FILE: /home/arpitkayare/drupal_9.5/web/modules/contrib/decoupled_auth-3356179/tests/src/Functional/RegistrationTest.php
    -----------------------------------------------------------------------------------------------------------------------------------------
    FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
    -----------------------------------------------------------------------------------------------------------------------------------------
     75 | WARNING | t() calls should be avoided in classes, use \Drupal\Core\StringTranslation\StringTranslationTrait and $this->t() instead

    Moving the issue to Needs work and updating the MR.

    Thanks!

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

    I have updated the MR with fixes. Please review.

    Thanks!

Production build 0.69.0 2024