
Problem/Motivation
This is a quirky issue relating to EntityStorageInterface::loadRevision being deprecated.
PHPStan is caching interface methods from left to right.
@Kingdutch had some information on the internals for how PHP handles this: https://drupal.slack.com/archives/C033S2JUMLJ/p1692251803456129?thread_t...
Kingdutch on August 17th at 7:56:43 AM
This sounds very similar to https://github.com/phpstan/phpstan/issues/8437 that I filed for https://www.drupal.org/project/drupal/issues/3324733 which was slightly different
(We have more of these hidden in Drupal core)
Usually these things are not PHPStan issues but PHP quirks :sweat_smile:
PHP does not document its interface inheritance order, but I can find https://www.php.net/manual/en/language.oop5.interfaces.php#125893 which links to 3 bug reports that suggest that the evaluation happens from right to left?
If we follow the right to left logic, I think things suddenly make sense and that's exactly why flipping them fixes it (because RevisionableStorageInterface which has the most specific method, comes last)
I don't think it really matters. Drupal core just extends EntityStorageInterface a lot.
Steps to reproduce
Scan code with PHPStan and deprecation rules package. Get warnings.
Proposed resolution
Stop extending `EntityStorageInterface` if another interface is extending it.
Rearrange extends for TranslatableRevisionableStorageInterface
Remaining tasks
User interface changes
API changes
Data model changes
Release notes snippet
Issue fork drupal-3383215
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 #2
mglamanAlso. R before T so it fixes alphabetical sorting 🤷♂️. May not be testable until #3263109: Use PHPStan for deprecation checking
Comment #4
mglamanActually, it looks like I can fix this in phpstan-drupal after all. So it can bridge the gap without committing this https://github.com/mglaman/phpstan-drupal/pull/596
Comment #5
mglamanNevermind, I forgot it asserts an incorrect error in the test:
This is from:
So the generic content entity storage interface doesn't work due to ordering of extends.
Comment #6
bbralaWe talked about this on Slack and there is no real possible problem that this could bring. Tests are also green. Setting rtbc
Comment #7
catchThis is going to need a re-roll after #3383279: Bump mglaman/phpstan-drupal to latest to make daily "updated deps" QA run pass again
Comment #8
mglamanRebased the MR
Comment #9
spokjeComment #10
spokjeComment #11
spokjeComment #12
bbralaBaseline updated, rebated, looking good.
Comment #13
spokjeCome to think of it: There might very well be a Coder follow-up in here to force the
implements
to be in alphabetical order?Comment #15
catchCommitted/pushed to 11.x, thanks!
Alphabetical implements seems worth opening a follow-up issue for if that'll help the phpstan baseline, would also match how we alphabetise use statements.
Comment #16
spokjeOpened Coder issue #3383525: Check alphabetical ordering for "implements"
Comment #17
bbralaIts not about alphabetical but about load order, so please don't force alphabetical :)
Comment #18
spokjeConfused now, but closed Coder issue anyway.
Comment #19
bbralaIt's a cooincedence it's alphabetical, there is a load order to interfaces in php. Which is logica but very edge casey. We might run into this in the future. See the Slack thread.
Comment #20
kingdutchJust copying in my Slack message in case people don't want to (or can no longer) go there.
The TL;DR is: "Although undocumented, PHP, consistently and by design, evaluates interfaces from right to left"
Comment #22
mxr576Can this be also cherry-picked back to 10.1.x?
https://github.com/mglaman/phpstan-drupal/issues/621