Fix dependency injection reports

Created on 17 June 2022, about 2 years ago
Updated 29 February 2024, 4 months ago

Drupal Version

9.4.x.

Domain module version

8.x-1.x

Expected Behavior

Run drupal-check without errors.

Actual Behavior

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

Steps to reproduce

Run phpstan without suppressing "Drupal calls should be avoided in classes, use dependency injection instead"

UPDATE: Implementation details

The README shows what tests we want to run. The relevant parts are below.

### Code linting

We use (and recommend) [PHPCBF](https://phpqa.io/projects/phpcbf.html), [PHP Codesniffer](https://github.com/squizlabs/PHP_CodeSniffer) and [phpstan](https://phpstan.org/) for code quality review.

The following commands are run before commit:

* `vendor/bin/phpcbf web/modules/contrib/domain --standard="Drupal,DrupalPractice" -n --extensions="php,module,inc,install,test,profile,theme"`
* `vendor/bin/phpcs web/modules/contrib/domain --standard="Drupal,DrupalPractice" -n --extensions="php,module,inc,install,test,profile,theme"`
* `vendor/bin/phpstan analyse web/modules/contrib/domain`

### Testing tools

We are using the following composer dev dependencies for local testing:

```
  "drupal/coder": "^8.3",
  "mglaman/drupal-check": "^1.4",
  "squizlabs/php_codesniffer": "^3.6",
```

Note that PHPCBF is installed as part of php_codesniffer.

### phpstan config

We use the following phpstan.neon file:

```
parameters:
  level: 2
  ignoreErrors:
    # new static() is a best practice in Drupal, so we cannot fix that.
    - "#^Unsafe usage of new static#"
    # Ignore common errors for now.
    - "#Drupal calls should be avoided in classes, use dependency injection instead#"
  drupal:
    entityMapping:
      domain:
        class: Drupal\domain\Entity\Domain
        storage: Drupal\domain\DomainStorage
      domain_alias:
          class: Drupal\domain_alias\Entity\DomainAlias
          storage: Drupal\domain_alias\DomainAliasStorage

```

The drupal entityMapping is also provided by `entity_mapping.neon` in the project root, for use with other tests.

For this issue, we want to remove this part of phpstan.neon:

    # Ignore common errors for now.
    - "#Drupal calls should be avoided in classes, use dependency injection instead#"
📌 Task
Status

Needs review

Version

2.0

Component

Code

Created by

🇺🇸United States agentrickard Georgia (US)

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

Merge Requests

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.69.0 2024