From 47b4ccc4e62e304fb3e95921f2e023ab8a5c1b62 Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 20 Nov 2022 22:49:51 +0100 Subject: [PATCH 1/2] Solve some baseline errors --- lib/Doctrine/ORM/PersistentCollection.php | 7 ++++--- lib/Doctrine/ORM/UnitOfWork.php | 16 +++++---------- phpstan-baseline.neon | 25 ----------------------- 3 files changed, 9 insertions(+), 39 deletions(-) diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index d80710a85f0..36a5d806efd 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -97,7 +97,7 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec * * @param EntityManagerInterface $em The EntityManager the collection will be associated with. * @param ClassMetadata $class The class descriptor of the entity type of this collection. - * @psalm-param Collection $collection The collection elements. + * @psalm-param Collection&Selectable $collection The collection elements. */ public function __construct(EntityManagerInterface $em, $class, Collection $collection) { @@ -675,11 +675,12 @@ public function matching(Criteria $criteria): Collection /** * Retrieves the wrapped Collection instance. * - * @return Collection + * @return Collection&Selectable */ public function unwrap(): Collection { - assert($this->collection !== null); + assert($this->collection instanceof Collection); + assert($this->collection instanceof Selectable); return $this->collection; } diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 9b85bbd5558..3b776f621cd 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -222,14 +222,14 @@ class UnitOfWork implements PropertyChangedListener /** * All pending collection deletions. * - * @psalm-var array> + * @psalm-var array> */ private $collectionDeletions = []; /** * All pending collection updates. * - * @psalm-var array> + * @psalm-var array> */ private $collectionUpdates = []; @@ -238,7 +238,7 @@ class UnitOfWork implements PropertyChangedListener * At the end of the UnitOfWork all these collections will make new snapshots * of their data. * - * @psalm-var array> + * @psalm-var array> */ private $visitedCollections = []; @@ -419,12 +419,6 @@ public function commit($entity = null) try { // Collection deletions (deletions of complete collections) foreach ($this->collectionDeletions as $collectionToDelete) { - if (! $collectionToDelete instanceof PersistentCollection) { - $this->getCollectionPersister($collectionToDelete->getMapping())->delete($collectionToDelete); - - continue; - } - // Deferred explicit tracked collections can be removed only when owning relation was persisted $owner = $collectionToDelete->getOwner(); @@ -3376,7 +3370,7 @@ public function getScheduledEntityDeletions() /** * Gets the currently scheduled complete collection deletions * - * @psalm-return array> + * @psalm-return array> */ public function getScheduledCollectionDeletions() { @@ -3386,7 +3380,7 @@ public function getScheduledCollectionDeletions() /** * Gets the currently scheduled collection inserts, updates and deletes. * - * @psalm-return array> + * @psalm-return array> */ public function getScheduledCollectionUpdates() { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 5e2b2da9089..b65a0347f79 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -250,11 +250,6 @@ parameters: count: 1 path: lib/Doctrine/ORM/NativeQuery.php - - - message: "#^Call to an undefined method Doctrine\\\\Common\\\\Collections\\\\Collection\\\\:\\:matching\\(\\)\\.$#" - count: 1 - path: lib/Doctrine/ORM/PersistentCollection.php - - message: "#^Method Doctrine\\\\ORM\\\\Persisters\\\\Collection\\\\OneToManyPersister\\:\\:delete\\(\\) should return int\\|null but empty return statement found\\.$#" count: 1 @@ -715,26 +710,6 @@ parameters: count: 1 path: lib/Doctrine/ORM/Tools/SchemaTool.php - - - message: "#^Call to an undefined method Doctrine\\\\Common\\\\Collections\\\\Collection\\<\\(int\\|string\\), object\\>\\:\\:getMapping\\(\\)\\.$#" - count: 2 - path: lib/Doctrine/ORM/UnitOfWork.php - - - - message: "#^Call to an undefined method Doctrine\\\\Common\\\\Collections\\\\Collection\\<\\(int\\|string\\), object\\>\\:\\:takeSnapshot\\(\\)\\.$#" - count: 1 - path: lib/Doctrine/ORM/UnitOfWork.php - - - - message: "#^Parameter \\#1 \\$collection of method Doctrine\\\\ORM\\\\Persisters\\\\Collection\\\\CollectionPersister\\:\\:delete\\(\\) expects Doctrine\\\\ORM\\\\PersistentCollection, Doctrine\\\\Common\\\\Collections\\\\Collection\\<\\(int\\|string\\), object\\> given\\.$#" - count: 1 - path: lib/Doctrine/ORM/UnitOfWork.php - - - - message: "#^Parameter \\#1 \\$collection of method Doctrine\\\\ORM\\\\Persisters\\\\Collection\\\\CollectionPersister\\:\\:update\\(\\) expects Doctrine\\\\ORM\\\\PersistentCollection, Doctrine\\\\Common\\\\Collections\\\\Collection\\<\\(int\\|string\\), object\\> given\\.$#" - count: 1 - path: lib/Doctrine/ORM/UnitOfWork.php - - message: "#^Parameter \\#3 \\$changeSet of class Doctrine\\\\ORM\\\\Event\\\\PreUpdateEventArgs constructor is passed by reference, so it expects variables only$#" count: 1 From db7333cc844c7b304175fd1ff4f08a890d4a331b Mon Sep 17 00:00:00 2001 From: Vincent Langlet Date: Sun, 20 Nov 2022 23:37:42 +0100 Subject: [PATCH 2/2] Update baseline --- phpstan-baseline.neon | 5 +++++ psalm-baseline.xml | 29 +++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index b65a0347f79..a212a9673c6 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -715,6 +715,11 @@ parameters: count: 1 path: lib/Doctrine/ORM/UnitOfWork.php + - + message: "#^Parameter \\#3 \\$collection of class Doctrine\\\\ORM\\\\PersistentCollection constructor expects Doctrine\\\\Common\\\\Collections\\\\Collection\\<\\(int\\|string\\), mixed\\>&Doctrine\\\\Common\\\\Collections\\\\Selectable\\<\\(int\\|string\\), mixed\\>, Doctrine\\\\Common\\\\Collections\\\\Collection given\\.$#" + count: 1 + path: lib/Doctrine/ORM/UnitOfWork.php + - message: "#^Access to an undefined property Doctrine\\\\Persistence\\\\Mapping\\\\ClassMetadata\\:\\:\\$name\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f3631549f66..2e4ae2bc412 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1031,6 +1031,11 @@ $entity + + + MemcachedAdapter::createConnection('memcached://127.0.0.1') + + Collection<TKey, T> @@ -1039,6 +1044,12 @@ $this->em->find($this->typeClass->name, $key) + + Collection<TKey, T> + + + $this->unwrap()->matching($criteria) + $offset @@ -1070,9 +1081,6 @@ setValue setValue - - matching - @@ -2800,11 +2808,9 @@ - + $class $class - $collectionToDelete - $collectionToUpdate $commitOrder[$i] @@ -2829,10 +2835,13 @@ $this->identityMap[$rootClassName][$idHash] + + $value + $this->identityMap[$rootClassName] - + $assoc $assoc $assoc @@ -2842,6 +2851,7 @@ $collection->getOwner() $collection->getOwner() $collectionToDelete->getMapping() + $collectionToUpdate->getMapping() $entity $entity $owner @@ -2905,11 +2915,6 @@ $visited - - getMapping - getMapping - takeSnapshot -