Typehint change in UniteOfWork::gettScheduledCollection* couses phpstan to fail after v2.8.3 #6681

Closed
opened 2026-01-22 15:36:54 +01:00 by admin · 1 comment
Owner

Originally created by @mmarton on GitHub (Apr 6, 2021).

Hi!

In the UnitOfWork class getScheduledCollectionUpdates and getScheduledCollectionDeletions methods got new return typehints:
@psalm-return array<string, Collection<array-key, object>>

I think this should be @psalm-return array<string, PersistentCollection<array-key, object>> as every time when a ScheduledCollection item is set it is explicitly checked for PersistentCollection. (like https://github.com/doctrine/orm/blob/2.8.x/lib/Doctrine/ORM/UnitOfWork.php#L775 and https://github.com/doctrine/orm/blob/2.8.x/lib/Doctrine/ORM/UnitOfWork.php#L898)

Because of this change phpstan fails on my eventsubscriber with:

 Line   src/.../Subscriber.php         
 ------ -------------------------------------------------------- 
  118    Call to an undefined method                             
         Doctrine\Common\Collections\Collection::getOwner().     
  124    Call to an undefined method                             
         Doctrine\Common\Collections\Collection::getMapping().   
  125    Call to an undefined method                             
         Doctrine\Common\Collections\Collection::getSnapshot().  
  126    Call to an undefined method                             
         Doctrine\Common\Collections\Collection::unwrap().

I know I can manually typehint it to PersistentCollection, and I'm doing it right now. Just wanted to report this.

Originally created by @mmarton on GitHub (Apr 6, 2021). Hi! In the UnitOfWork class getScheduledCollectionUpdates and getScheduledCollectionDeletions methods got new return typehints: `@psalm-return array<string, Collection<array-key, object>>` I think this should be `@psalm-return array<string, PersistentCollection<array-key, object>>` as every time when a ScheduledCollection item is set it is explicitly checked for PersistentCollection. (like https://github.com/doctrine/orm/blob/2.8.x/lib/Doctrine/ORM/UnitOfWork.php#L775 and https://github.com/doctrine/orm/blob/2.8.x/lib/Doctrine/ORM/UnitOfWork.php#L898) Because of this change phpstan fails on my eventsubscriber with: ``` Line src/.../Subscriber.php ------ -------------------------------------------------------- 118 Call to an undefined method Doctrine\Common\Collections\Collection::getOwner(). 124 Call to an undefined method Doctrine\Common\Collections\Collection::getMapping(). 125 Call to an undefined method Doctrine\Common\Collections\Collection::getSnapshot(). 126 Call to an undefined method Doctrine\Common\Collections\Collection::unwrap(). ``` I know I can manually typehint it to PersistentCollection, and I'm doing it right now. Just wanted to report this.
admin closed this issue 2026-01-22 15:36:55 +01:00
Author
Owner

@mmarton commented on GitHub (Oct 2, 2024):

no longer relevant / got fixed sometime

@mmarton commented on GitHub (Oct 2, 2024): no longer relevant / got fixed sometime
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6681