Problem/Motivation
When scanning this module with Upgrade Status in Drupal 11, a number of warnings are produced of the form, "Unsafe usage of new static()." While this pattern was tolerated in Drupal 10, we now have better ways to resolve it in D11.
Steps to reproduce
In Drupal 11, use Upgrade Status to scan this module. Check the resulting "problems."
Proposed resolution
- Forms: use autowiring (core's AutowireTrait, available since our minimum of Drupal 10.3) instead of create() methods, adding service aliases to search_api.services.yml where needed.
- IndexListBuilder: use the $instance = parent::createInstance() pattern.
- Plugin base classes, derivers and Query, where new static() is required so that inherited create() methods instantiate the correct subclass: declare the constructor contract with @phpstan-consistent-constructor, which both PHPStan and Upgrade Status respect. (new self() would break subclasses that inherit create().)
- Remove the blanket "Unsafe usage of new static" ignore from phpstan.neon, keeping only a narrow ignore for the bleeding-edge-only "in abstract class" variant, which Upgrade Status does not report.
Remaining tasks
Make an MR. I'm assigning this to myself since I intend to work on it right away.
Issue fork search_api-3593375
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
Comment #3
benstallings commentedComment #4
benstallings commented