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

Created on 22 August 2022, about 2 years ago
Updated 23 May 2024, 6 months ago

Problem/Motivation

I try to run phpcs coding standard check on the module. I found some dependency injection warning in some files as follows:

FILE: /app/modules/contrib/contacts/src/Form/ContactTabForm.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
49 | WARNING | \Drupal calls should be avoided in classes, use
| | dependency injection instead
----------------------------------------------------------------------

FILE: .../modules/contrib/contacts/src/Form/DashboardTabConfigureForm.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
139 | WARNING | \Drupal calls should be avoided in classes, use
| | dependency injection instead
----------------------------------------------------------------------

FILE: ...app/modules/contrib/contacts/src/Plugin/Block/ContactsEntity.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
641 | WARNING | \Drupal calls should be avoided in classes, use
| | dependency injection instead
----------------------------------------------------------------------

FILE: .../modules/contrib/contacts/src/Controller/DashboardController.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 3 WARNINGS AFFECTING 3 LINES
----------------------------------------------------------------------
567 | WARNING | \Drupal calls should be avoided in classes, use
| | dependency injection instead
568 | WARNING | \Drupal calls should be avoided in classes, use
| | dependency injection instead
612 | WARNING | \Drupal calls should be avoided in classes, use
| | dependency injection instead
----------------------------------------------------------------------

FILE: ...es/contrib/contacts/modules/crm_tools/src/Form/OverviewRoles.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
121 | WARNING | \Drupal calls should be avoided in classes, use
| | dependency injection instead
----------------------------------------------------------------------

FILE: .../contacts/modules/user_dashboard/src/Routing/RouteSubscriber.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
25 | WARNING | \Drupal calls should be avoided in classes, use
| | dependency injection instead
----------------------------------------------------------------------

FILE: ...trib/contacts/modules/dbs/src/Plugin/Block/DBSStatusAddBlock.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
96 | WARNING | \Drupal calls should be avoided in classes, use
| | dependency injection instead
----------------------------------------------------------------------

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Fixed

Version

2.0

Component

Code

Created by

🇮🇳India Meeni_Dhobale

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

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024