From e9f80831f6b0f7ffc0ed17ae1c11ae7ad2b74a8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Tue, 2 Jul 2024 13:31:49 +0200 Subject: [PATCH] Add native type to private properties and final classes (#2666) --- lib/Doctrine/ODM/MongoDB/APM/Command.php | 4 +- .../ODM/MongoDB/Aggregation/Stage/Bucket.php | 4 +- .../ODM/MongoDB/Aggregation/Stage/Fill.php | 3 +- .../MongoDB/Aggregation/Stage/Fill/Output.php | 2 +- .../ODM/MongoDB/Aggregation/Stage/GeoNear.php | 2 +- .../MongoDB/Aggregation/Stage/GraphLookup.php | 2 +- .../ODM/MongoDB/Aggregation/Stage/Lookup.php | 2 +- .../ODM/MongoDB/Aggregation/Stage/Merge.php | 14 ++--- .../ODM/MongoDB/Aggregation/Stage/Out.php | 7 +-- .../Aggregation/Stage/Search/Equals.php | 3 +- .../Aggregation/Stage/Search/GeoShape.php | 3 +- .../Aggregation/Stage/Search/GeoWithin.php | 3 +- .../MongoDB/Aggregation/Stage/Search/Near.php | 6 +-- .../Aggregation/Stage/Search/Range.php | 12 ++--- .../Aggregation/Stage/SetWindowFields.php | 3 +- .../MongoDB/Aggregation/Stage/UnionWith.php | 7 +-- .../Event/DocumentNotFoundEventArgs.php | 3 +- .../MongoDB/Iterator/HydratingIterator.php | 2 +- .../ODM/MongoDB/Mapping/ClassMetadata.php | 14 ++--- .../PersistentCollectionTrait.php | 42 ++++++--------- .../Proxy/Factory/StaticProxyFactory.php | 3 -- lib/Doctrine/ODM/MongoDB/Query/Builder.php | 3 +- lib/Doctrine/ODM/MongoDB/Query/Expr.php | 4 +- .../ODM/MongoDB/Query/ReferencePrimer.php | 49 ++++++++--------- phpstan-baseline.neon | 52 +++---------------- psalm-baseline.xml | 8 +++ 26 files changed, 86 insertions(+), 171 deletions(-) diff --git a/lib/Doctrine/ODM/MongoDB/APM/Command.php b/lib/Doctrine/ODM/MongoDB/APM/Command.php index 4670253cfa..1bc16b9b92 100644 --- a/lib/Doctrine/ODM/MongoDB/APM/Command.php +++ b/lib/Doctrine/ODM/MongoDB/APM/Command.php @@ -14,9 +14,7 @@ final class Command { private CommandStartedEvent $startedEvent; - - /** @var CommandSucceededEvent|CommandFailedEvent */ - private $finishedEvent; + private CommandSucceededEvent|CommandFailedEvent $finishedEvent; private function __construct() { diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php index eac3323e8c..67e9c80d3f 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php @@ -10,9 +10,7 @@ class Bucket extends AbstractBucket { /** @var mixed[] */ private array $boundaries; - - /** @var mixed */ - private $default; + private mixed $default = null; /** * An array of values based on the groupBy expression that specify the diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill.php index f136cbb3d2..df1069166c 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill.php @@ -32,8 +32,7 @@ */ class Fill extends Stage { - /** @var mixed|Expr|null */ - private $partitionBy = null; + private mixed $partitionBy = null; /** @var array */ private array $partitionByFields = []; diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill/Output.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill/Output.php index d975df84eb..f12ce9f62c 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill/Output.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Fill/Output.php @@ -23,7 +23,7 @@ class Output extends Stage private string $currentField = ''; /** @var array> */ - private $output = []; + private array $output = []; public function __construct(Builder $builder, private Fill $fill) { diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GeoNear.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GeoNear.php index 5de79b710b..7c8bd0fccc 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GeoNear.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GeoNear.php @@ -25,7 +25,7 @@ class GeoNear extends MatchStage private ?float $minDistance = null; /** @var array|array{int|float, int|float} */ - private $near; + private array $near; private ?int $num = null; diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php index 4e75de85a1..962da0b50a 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php @@ -26,7 +26,7 @@ class GraphLookup extends Stage private ?string $from; /** @var string|Expr|mixed[]|null */ - private $startWith; + private string|Expr|array|null $startWith; private ?string $connectFromField = null; diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php index c2d4455bdf..7b6fcde709 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php @@ -48,7 +48,7 @@ class Lookup extends Stage * @var Builder|array>|null * @psalm-var Builder|PipelineExpression|null */ - private $pipeline = null; + private Builder|array|null $pipeline = null; private bool $excludeLocalAndForeignField = false; diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Merge.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Merge.php index 0db46342c7..356efa3eb9 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Merge.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Merge.php @@ -33,11 +33,8 @@ */ class Merge extends Stage { - /** - * @var string|array - * @psalm-var OutputCollection - */ - private $into; + /** @psalm-var OutputCollection */ + private string|array $into; /** @var list */ private array $on = []; @@ -45,11 +42,8 @@ class Merge extends Stage /** @var array */ private array $let = []; - /** - * @var string|array|Builder|Stage - * @psalm-var WhenMatchedParamType - */ - private $whenMatched; + /** @psalm-var WhenMatchedParamType */ + private string|array|Builder|Stage|null $whenMatched = null; private ?string $whenNotMatched = null; diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Out.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Out.php index 5343cfeade..aa6a335012 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Out.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Out.php @@ -19,11 +19,8 @@ */ class Out extends Stage { - /** - * @var array|string - * @psalm-var OutputCollection - */ - private $out; + /** @psalm-var OutputCollection */ + private array|string $out; public function __construct(Builder $builder, string $collection, private DocumentManager $dm) { diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Equals.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Equals.php index 960013dbe6..fbaf401ed3 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Equals.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Equals.php @@ -19,8 +19,7 @@ class Equals extends AbstractSearchOperator implements ScoredSearchOperator private string $path = ''; - /** @var mixed */ - private $value; + private mixed $value; /** @param string|int|float|ObjectId|UTCDateTime|null $value */ public function __construct(Search $search, string $path = '', $value = null) diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/GeoShape.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/GeoShape.php index 600ad2f936..c7ab3e4014 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/GeoShape.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/GeoShape.php @@ -24,8 +24,7 @@ class GeoShape extends AbstractSearchOperator implements ScoredSearchOperator private array $path = []; private string $relation = ''; - /** @var LineString|Point|Polygon|MultiPolygon|array|null */ - private $geometry = null; + private LineString|Point|Polygon|MultiPolygon|array|null $geometry = null; /** @param LineString|Point|Polygon|MultiPolygon|array|null $geometry */ public function __construct(Search $search, $geometry = null, string $relation = '', string ...$path) diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/GeoWithin.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/GeoWithin.php index 5237a194dd..c72b283e47 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/GeoWithin.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/GeoWithin.php @@ -25,8 +25,7 @@ class GeoWithin extends AbstractSearchOperator implements ScoredSearchOperator private ?object $box = null; private ?object $circle = null; - /** @var array|MultiPolygon|Polygon|null */ - private $geometry = null; + private array|MultiPolygon|Polygon|null $geometry = null; public function __construct(Search $search, string ...$path) { diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Near.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Near.php index ad0e1d1d3c..f244259c94 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Near.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Near.php @@ -18,11 +18,9 @@ class Near extends AbstractSearchOperator implements ScoredSearchOperator { use ScoredSearchOperatorTrait; - /** @var int|float|UTCDateTime|array|Point|null */ - private $origin; + private int|float|UTCDateTime|array|Point|null $origin; - /** @var int|float|null */ - private $pivot; + private int|float|null $pivot; /** @var list */ private array $path; diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Range.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Range.php index 62bed26a8e..af3fc0cdd9 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Range.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Search/Range.php @@ -15,14 +15,10 @@ class Range extends AbstractSearchOperator implements ScoredSearchOperator { use ScoredSearchOperatorTrait; - /** @var int|float|UTCDateTime|null */ - private $gt = null; - - /** @var int|float|UTCDateTime|null */ - private $lt = null; - - private bool $includeLowerBound = false; - private bool $includeUpperBound = false; + private int|float|UTCDateTime|null $gt = null; + private int|float|UTCDateTime|null $lt = null; + private bool $includeLowerBound = false; + private bool $includeUpperBound = false; /** @var list */ private array $path; diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/SetWindowFields.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/SetWindowFields.php index 23c6748a45..9d8b436568 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/SetWindowFields.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/SetWindowFields.php @@ -28,8 +28,7 @@ */ class SetWindowFields extends Stage { - /** @var mixed|Expr|null */ - private $partitionBy = null; + private mixed $partitionBy = null; /** @var array */ private array $sortBy = []; diff --git a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/UnionWith.php b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/UnionWith.php index 8d651ef42e..6c468c9427 100644 --- a/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/UnionWith.php +++ b/lib/Doctrine/ODM/MongoDB/Aggregation/Stage/UnionWith.php @@ -24,11 +24,8 @@ */ class UnionWith extends Stage { - /** - * @var array|Builder|null - * @psalm-var ?PipelineParamType - */ - private $pipeline = null; + /** @psalm-var ?PipelineParamType */ + private array|Builder|Stage|null $pipeline = null; public function __construct(Builder $builder, private DocumentManager $dm, private string $collection) { diff --git a/lib/Doctrine/ODM/MongoDB/Event/DocumentNotFoundEventArgs.php b/lib/Doctrine/ODM/MongoDB/Event/DocumentNotFoundEventArgs.php index 4a25347064..3a31a1ffbb 100644 --- a/lib/Doctrine/ODM/MongoDB/Event/DocumentNotFoundEventArgs.php +++ b/lib/Doctrine/ODM/MongoDB/Event/DocumentNotFoundEventArgs.php @@ -13,8 +13,7 @@ final class DocumentNotFoundEventArgs extends LifecycleEventArgs { private bool $disableException = false; - /** @param mixed $identifier */ - public function __construct(object $document, DocumentManager $dm, private $identifier) + public function __construct(object $document, DocumentManager $dm, private mixed $identifier) { parent::__construct($document, $dm); } diff --git a/lib/Doctrine/ODM/MongoDB/Iterator/HydratingIterator.php b/lib/Doctrine/ODM/MongoDB/Iterator/HydratingIterator.php index 3c4cd318f2..94f5f219f6 100644 --- a/lib/Doctrine/ODM/MongoDB/Iterator/HydratingIterator.php +++ b/lib/Doctrine/ODM/MongoDB/Iterator/HydratingIterator.php @@ -25,7 +25,7 @@ final class HydratingIterator implements Iterator { /** @var Generator>|null */ - private $iterator; + private ?Generator $iterator; /** * @param Traversable> $traversable diff --git a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php index d47bf6dcae..34c13622de 100644 --- a/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php @@ -539,17 +539,14 @@ /** * Allows users to specify a validation schema for the collection. * - * @var array|object|null * @psalm-var array|object|null */ - private $validator; + private array|object|null $validator = null; /** * Determines whether to error on invalid documents or just warn about the violations but allow invalid documents to be inserted. - * - * @var string */ - private $validationAction = self::SCHEMA_VALIDATION_ACTION_ERROR; + private string $validationAction = self::SCHEMA_VALIDATION_ACTION_ERROR; /** * Determines how strictly MongoDB applies the validation rules to existing documents during an update. @@ -813,11 +810,8 @@ private ReflectionService $reflectionService; - /** - * @var string|null - * @psalm-var class-string|null - */ - private $rootClass; + /** @var class-string|null */ + private ?string $rootClass; /** * Initializes a new ClassMetadata instance that will hold the object-document mapping diff --git a/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php b/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php index cac58fb6a0..1ccb2aab0f 100644 --- a/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php +++ b/lib/Doctrine/ODM/MongoDB/PersistentCollection/PersistentCollectionTrait.php @@ -41,71 +41,61 @@ trait PersistentCollectionTrait * * @var array */ - private $snapshot = []; + private array $snapshot = []; /** * Collection's owning document - * - * @var object|null */ - private $owner; + private ?object $owner = null; /** - * @var array|null + * @var array|null * @psalm-var FieldMapping|null */ - private $mapping; + private ?array $mapping = null; /** * Whether the collection is dirty and needs to be synchronized with the database * when the UnitOfWork that manages its persistent state commits. - * - * @var bool */ - private $isDirty = false; + private bool $isDirty = false; /** * Whether the collection has already been initialized. - * - * @var bool */ - private $initialized = true; + private bool $initialized = true; /** * The wrapped Collection instance. * * @var BaseCollection */ - private $coll; + private BaseCollection $coll; /** * The DocumentManager that manages the persistence of the collection. - * - * @var DocumentManager|null */ - private $dm; + private DocumentManager $dm; /** * The UnitOfWork that manages the persistence of the collection. - * - * @var UnitOfWork */ - private $uow; + private UnitOfWork $uow; /** * The raw mongo data that will be used to initialize this collection. * * @var mixed[] */ - private $mongoData = []; + private array $mongoData = []; /** * Any hints to account for during reconstitution/lookup of the documents. * - * @var array + * @var array * @psalm-var Hints */ - private $hints = []; + private array $hints = []; public function setDocumentManager(DocumentManager $dm) { @@ -292,7 +282,7 @@ public function getMapping() public function getTypeClass() { - if ($this->dm === null) { + if (! isset($this->dm)) { throw new MongoDBException('No DocumentManager is associated with this PersistentCollection, please set one using setDocumentManager method.'); } @@ -653,7 +643,7 @@ private function doAdd($value, $arrayAccess) $arrayAccess ? $this->coll->offsetSet(null, $value) : $this->coll->add($value); $this->changed(); - if ($this->uow !== null && $this->isOrphanRemovalEnabled() && $value !== null) { + if (isset($this->uow) && $this->isOrphanRemovalEnabled() && $value !== null) { $this->uow->unscheduleOrphanRemoval($value); } @@ -702,7 +692,7 @@ private function doSet($offset, $value, bool $arrayAccess): void $arrayAccess ? $this->coll->offsetSet($offset, $value) : $this->coll->set($offset, $value); // Handle orphanRemoval - if ($this->uow !== null && $this->isOrphanRemovalEnabled() && $value !== null) { + if (isset($this->uow) && $this->isOrphanRemovalEnabled() && $value !== null) { $this->uow->unscheduleOrphanRemoval($value); } @@ -733,7 +723,7 @@ private function isOrphanRemovalEnabled(): bool */ private function needsSchedulingForSynchronization(): bool { - return $this->owner && $this->dm && ! empty($this->mapping['isOwningSide']) + return $this->owner && isset($this->dm) && ! empty($this->mapping['isOwningSide']) && $this->dm->getClassMetadata(get_class($this->owner))->isChangeTrackingNotify(); } diff --git a/lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php b/lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php index 08109dadc5..737795fe48 100644 --- a/lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php +++ b/lib/Doctrine/ODM/MongoDB/Proxy/Factory/StaticProxyFactory.php @@ -25,11 +25,8 @@ */ final class StaticProxyFactory implements ProxyFactory { - /** @var UnitOfWork The UnitOfWork this factory is bound to. */ private UnitOfWork $uow; - private LifecycleEventManager $lifecycleEventManager; - private LazyLoadingGhostFactory $proxyFactory; public function __construct(DocumentManager $documentManager) diff --git a/lib/Doctrine/ODM/MongoDB/Query/Builder.php b/lib/Doctrine/ODM/MongoDB/Query/Builder.php index a01629873d..7e249a5a92 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/Builder.php +++ b/lib/Doctrine/ODM/MongoDB/Query/Builder.php @@ -85,10 +85,9 @@ class Builder /** * Array containing the query data. * - * @var array * @psalm-var QueryShape */ - private $query = ['type' => Query::TYPE_FIND]; + private array $query = ['type' => Query::TYPE_FIND]; /** * The Expr instance used for building this query. diff --git a/lib/Doctrine/ODM/MongoDB/Query/Expr.php b/lib/Doctrine/ODM/MongoDB/Query/Expr.php index cd0d81412f..ca96ca4fe5 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/Expr.php +++ b/lib/Doctrine/ODM/MongoDB/Query/Expr.php @@ -40,10 +40,8 @@ class Expr { /** * The query criteria array. - * - * @var array|mixed */ - private $query = []; + private mixed $query = []; /** * The "new object" array containing either a full document or a number of diff --git a/lib/Doctrine/ODM/MongoDB/Query/ReferencePrimer.php b/lib/Doctrine/ODM/MongoDB/Query/ReferencePrimer.php index b754661dd3..ab39bff8ac 100644 --- a/lib/Doctrine/ODM/MongoDB/Query/ReferencePrimer.php +++ b/lib/Doctrine/ODM/MongoDB/Query/ReferencePrimer.php @@ -4,7 +4,6 @@ namespace Doctrine\ODM\MongoDB\Query; -use Closure; use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Iterator\Iterator; use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; @@ -43,13 +42,6 @@ */ final class ReferencePrimer { - /** - * The default primer Closure. - * - * @var Closure - */ - private $defaultPrimer; - /** * The DocumentManager instance. */ @@ -64,23 +56,6 @@ public function __construct(DocumentManager $dm, UnitOfWork $uow) { $this->dm = $dm; $this->uow = $uow; - - $this->defaultPrimer = static function (DocumentManager $dm, ClassMetadata $class, array $ids, array $hints): void { - if ($class->identifier === null) { - return; - } - - $qb = $dm->createQueryBuilder($class->name) - ->field($class->identifier)->in($ids); - - if (! empty($hints[Query::HINT_READ_PREFERENCE])) { - $qb->setReadPreference($hints[Query::HINT_READ_PREFERENCE]); - } - - $iterator = $qb->getQuery()->execute(); - assert($iterator instanceof Iterator); - $iterator->toArray(); - }; } /** @@ -124,7 +99,7 @@ public function primeReferences(ClassMetadata $class, $documents, string $fieldN throw new LogicException(sprintf('Field "%s" is an identifier reference without a target document class in class "%s"', $fieldName, $class->name)); } - $primer = $primer ?: $this->defaultPrimer; + $primer = $primer ?: self::defaultPrimer(...); $groupedIds = []; foreach ($documents as $document) { @@ -276,4 +251,26 @@ private function addManyReferences(PersistentCollectionInterface $persistentColl $groupedIds[$className][serialize($id)] = $id; } } + + /** + * @param list $ids + * @param array $hints + */ + private static function defaultPrimer(DocumentManager $dm, ClassMetadata $class, array $ids, array $hints): void + { + if ($class->identifier === null) { + return; + } + + $qb = $dm->createQueryBuilder($class->name) + ->field($class->identifier)->in($ids); + + if (! empty($hints[Query::HINT_READ_PREFERENCE])) { + $qb->setReadPreference($hints[Query::HINT_READ_PREFERENCE]); + } + + $iterator = $qb->getQuery()->execute(); + assert($iterator instanceof Iterator); + $iterator->toArray(); + } } diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 736b03a30c..ae58dfd951 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -495,58 +495,28 @@ parameters: count: 1 path: lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php - - - message: "#^Access to offset 'embedded' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\FieldMapping\\.$#" - count: 1 - path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php - - - - message: "#^Access to offset 'isOwningSide' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\FieldMapping\\.$#" - count: 3 - path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php - - - - message: "#^Access to offset 'orphanRemoval' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\FieldMapping\\.$#" - count: 1 - path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php - - - - message: "#^Access to offset 'reference' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\FieldMapping\\.$#" - count: 1 - path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php - - - - message: "#^Access to offset 'strategy' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\FieldMapping\\.$#" - count: 4 - path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php - - - - message: "#^Access to offset 'targetDocument' on an unknown class Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\FieldMapping\\.$#" - count: 2 - path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php - - message: "#^Method Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\:\\:add\\(\\) with return type void returns true but should not return anything\\.$#" count: 1 path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php - - message: "#^Method Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\:\\:getHints\\(\\) should return array\\ but returns Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\Hints\\.$#" + message: "#^PHPDoc tag @var for property Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\:\\:\\$hints with type Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\Hints is incompatible with native type array\\.$#" count: 1 path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php - - message: "#^Method Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\:\\:getMapping\\(\\) should return array\\{type\\: string, fieldName\\: string, name\\: string, isCascadeRemove\\: bool, isCascadePersist\\: bool, isCascadeRefresh\\: bool, isCascadeMerge\\: bool, isCascadeDetach\\: bool, \\.\\.\\.\\} but returns Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\FieldMapping\\|null\\.$#" + message: "#^PHPDoc tag @var for property Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\:\\:\\$mapping with type Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\FieldMapping\\|null is not subtype of native type array\\|null\\.$#" count: 1 path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php - - message: "#^Property Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\:\\:\\$hints \\(Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\Hints\\) does not accept default value of type array\\.$#" + message: "#^Property Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\:\\:\\$hints has unknown class Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\Hints as its type\\.$#" count: 1 path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php - - message: "#^Property Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\:\\:\\$hints has unknown class Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\Hints as its type\\.$#" + message: "#^Property Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\:\\:\\$hints type has no value type specified in iterable type array\\.$#" count: 1 path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php @@ -556,12 +526,12 @@ parameters: path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php - - message: "#^Property Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\:\\:\\$hints \\(Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\Hints\\) does not accept array\\\\.$#" + message: "#^Property Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\:\\:\\$mapping type has no value type specified in iterable type array\\.$#" count: 1 path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php - - message: "#^Property Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\:\\:\\$mapping \\(Doctrine\\\\ODM\\\\MongoDB\\\\PersistentCollection\\\\FieldMapping\\|null\\) does not accept array\\\\|bool\\|int\\|string\\|null\\>\\.$#" + message: "#^Right side of && is always true\\.$#" count: 1 path: lib/Doctrine/ODM/MongoDB/PersistentCollection.php @@ -865,16 +835,6 @@ parameters: count: 1 path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1990Test.php - - - message: "#^Dead catch \\- MongoDB\\\\Driver\\\\Exception\\\\BulkWriteException is never thrown in the try block\\.$#" - count: 1 - path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH580Test.php - - - - message: "#^Unreachable statement \\- code above always terminates\\.$#" - count: 1 - path: tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH580Test.php - - message: "#^Property Doctrine\\\\ODM\\\\MongoDB\\\\Tests\\\\Functional\\\\Ticket\\\\GH921Post\\:\\:\\$id is never written, only read\\.$#" count: 1 diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 366e569ae5..110172f146 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -142,7 +142,15 @@ coll)]]> + uow) && $this->isOrphanRemovalEnabled() && $value !== null]]> + uow) && $this->isOrphanRemovalEnabled() && $value !== null]]> + + owner && isset($this->dm)]]> + dm)]]> + uow)]]> + uow)]]> +