PhpStan finds an error where context goes over interface definition

Created on 8 August 2025, 16 days ago

Problem/Motivation

The following code worked for a long time:

    if (isset($original) && !$entity->isNew()) {
      // Behave the same as \Drupal\Core\Entity\EntityStorageBase::doPreSave.
      $id = $entity->getOriginalId() ?? $entity->id();
      if ($id !== NULL) {
        $etm = $this->entityTypeManager ?? \Drupal::entityTypeManager();

But now, PhpStan insists that $id !== NULL is always TRUE. The interface definitions don't tell that, but because we checked for !$entity->isNew() before, which implies that ID can not be NULL anymore.

Proposed resolution

We've discussed this at length and came to the conclusion that this is an improvement and the redundant if-statement should be removed.

📌 Task
Status

Active

Version

3.0

Component

Code

Created by

🇩🇪Germany jurgenhaas Gottmadingen

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

Comments & Activities

Production build 0.71.5 2024