Fix dependency injection warnings from phpstan

Created on 19 March 2025, 25 days ago

Problem/Motivation

phpstan reports,

------ ------------------------------------------------------------------------------
Line src/ConditionalFieldsFormHelper.php
------ ------------------------------------------------------------------------------
346 \Drupal calls should be avoided in classes, use dependency injection instead
------ ------------------------------------------------------------------------------

------ ------------------------------------------------------------------------------
Line src/Form/ConditionalFieldDeleteForm.php
------ ------------------------------------------------------------------------------
54 Unsafe usage of new static().
πŸ’‘ See:
https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static
------ ------------------------------------------------------------------------------

------ ------------------------------------------------------------------------------
Line src/Form/ConditionalFieldEditForm.php
------ ------------------------------------------------------------------------------
48 Unsafe usage of new static().
πŸ’‘ See:
https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static
------ ------------------------------------------------------------------------------

------ ------------------------------------------------------------------------------
Line src/Form/ConditionalFieldForm.php
------ ------------------------------------------------------------------------------
78 Unsafe usage of new static().
πŸ’‘ See:
https://phpstan.org/blog/solving-phpstan-error-unsafe-usage-of-new-static
------ ------------------------------------------------------------------------------

------ -------------------------------------------------------------
Line src/Plugin/conditional_fields/handler/TextAreaFormatted.php
------ -------------------------------------------------------------
36 Undefined variable: $selectors
------ -------------------------------------------------------------

Steps to reproduce

phpstan analyse conditional_fields

Proposed resolution

  • Inject the entityTypeManager dependency into the ConditionalFieldsFormHelper service and update the unit test to match.
  • In ConditionalFieldDeleteForm, ConditionalFieldEditForm, and ConditionalFieldForm, use the pattern $instance = parent::create() instead of re-implementing the __construct() method.
  • In TextAreaFormatted, comment out the code referencing the undefined variable.

Remaining tasks

Make an MR.

πŸ“Œ Task
Status

Active

Version

4.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States BenStallings

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024