Problem/Motivation

The Upgrade Status module reports all "Unsafe usage of new static()" errors generated by PHPStan. These are almost certainly false positives; the usage of "new static()" is an established pattern in Drupal code.

Furthermore, there is no feasible alternative to ignoring: using final on the class or the constructor prevents inheritance, and using new self() may break other interfaces which expect static (see discussion in core issue).

The errors are ignored in the module's phpstan.neon, but that file is not used when running the analysis.

The errors are NOT ignored in the module's deprecation_testing_template.neon, which is used when running the analysis. This causes them to be reported as compatibility issues.

Steps to reproduce

Run upgrade_status:analyze on any codebase which has custom modules which override __construct() and create()

Proposed resolution

Copy the ignore rule from phpstan.neon to deprecation_testing_template.neon:

		# new static() is a best practice in Drupal, so we cannot fix that.
		- "#^Unsafe usage of new static#"
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

marttir created an issue. See original summary.

miha.wagner made their first commit to this issue’s fork.

miha.wagner’s picture

Status: Active » Needs review

I've gotten this too since upgrading. MR fixes the issue as suggested by author. Fixed the issue in our project. Thank you marttir.

liam morland made their first commit to this issue’s fork.

solideogloria’s picture

Version: 4.3.9 » 4.x-dev
solideogloria’s picture

Status: Needs review » Reviewed & tested by the community