Make create() method in base clases abstract

Created on 4 November 2024, about 1 month ago

Problem/Motivation

PHPStan has warned that returning static can be confusing and depends significantly upon class extension.

Some modules try and use the create() method to retain BC using the model of

public static function create(...) {
  $object = parent::create(..)
  $object->newProperty = something
}

however this has pitfalls that variables may never be fully initialized if the constructor is called directly. While the constructor could be marked @internal, this forces the setup to always use the create 'factory' when not needed.

While this has become somewhat a Drupalism to construct methods in the create() method I would rather we create an ecosystem where the constructor is expected to handle class setup.

We can mark the method abstract on base classes to allow extension by other classes, and provide BC as we already do as part of the base class constructor.

Steps to reproduce

Proposed resolution

Make create() method abstract in base classes.

Remaining tasks

User interface changes

API changes

Classes extending our base classes MUST implement the create() method. This may

Data model changes

πŸ“Œ Task
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States cmlara

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