Skip to content

Fix wrongly deprecated method RevisionableStorageInterface::loadRevision#980

Merged
mglaman merged 1 commit intomglaman:mainfrom
TheFakeCake:fix-revisionable-storage-interface-deprecation
Apr 24, 2026
Merged

Fix wrongly deprecated method RevisionableStorageInterface::loadRevision#980
mglaman merged 1 commit intomglaman:mainfrom
TheFakeCake:fix-revisionable-storage-interface-deprecation

Conversation

@TheFakeCake
Copy link
Copy Markdown
Contributor

Since RevisionableStorageInterface extends EntityStorageInterface, the deprecations are also inherited.

The loadRevision() method is not supposed to be deprecated on RevisionableStorageInterface though.

@mglaman
Copy link
Copy Markdown
Owner

mglaman commented Apr 23, 2026

Did this work for you? We tried it in #576 and follow up in #586

@TheFakeCake TheFakeCake force-pushed the fix-revisionable-storage-interface-deprecation branch from 5028a77 to 5532dd0 Compare April 23, 2026 16:46
@TheFakeCake
Copy link
Copy Markdown
Contributor Author

TheFakeCake commented Apr 23, 2026

In my Drupal 10.6.8 project, the following code gives me a PhpStan error:

$storage = \Drupal::entityTypeManager()->getStorage('paragraph');

if (!$storage instanceof RevisionableStorageInterface) {
  return null;
}

foreach ($node->get('field_content')->getValue() as $content) {
  if (isset($content['target_revision_id'])) {
    $firstLevelParagraph = $storage->loadRevision($content['target_revision_id']); // <----ERROR
    // ...
  }
}
Call to deprecated method loadRevision() of interface Drupal\Core\Entity\RevisionableStorageInterface:
in drupal:10.1.0 and is removed from drupal:11.0.0. Use
\Drupal\Core\Entity\RevisionableStorageInterface::loadRevision instead.
🪪  method.deprecated

This is obviously a false positive and after some research I found https://phpstan.org/writing-php-code/phpdocs-basics#deprecations where the @not-deprecated is mentionned.

When I add @not-deprecated to the phpstan-drupal stub, clear PhpStan cache and analyze again, I don't get the error anymore.

Some details about my project setup:

PHP runtime version: 8.1.30
PHP version for analysis: 8.4.19 (from config)

PHPStan version: 2.1.51

Extension installer:
composer/pcre: 3.3.2
mglaman/phpstan-drupal: 2.0.14
phpstan/phpstan-deprecation-rules: 2.0.4

I changed my PR commit to add the @not-deprecated to deleteRevision() too since it has the same false positive problem (I get the same result).

@mglaman
Copy link
Copy Markdown
Owner

mglaman commented Apr 24, 2026

Thanks for the info!

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts Drupal entity storage stubs so PHPStan’s deprecation analysis does not incorrectly report RevisionableStorageInterface revision operations as deprecated.

Changes:

  • Add @not-deprecated to RevisionableStorageInterface::loadRevision().
  • Add @not-deprecated to RevisionableStorageInterface::deleteRevision().

@mglaman mglaman merged commit b61426d into mglaman:main Apr 24, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants