diff --git a/composer.json b/composer.json index 438c66384..11c2ef3d6 100644 --- a/composer.json +++ b/composer.json @@ -42,12 +42,12 @@ "doctrine/coding-standard": "^11.0", "jmikola/geojson": "^1.0", "phpbench/phpbench": "^1.0.0@dev", - "phpstan/phpstan": "^1.9.4", + "phpstan/phpstan": "^1.10.11", "phpstan/phpstan-phpunit": "^1.0", "phpunit/phpunit": "^9.5.5 || ^10.0.15", "squizlabs/php_codesniffer": "^3.5", "symfony/cache": "^4.4 || ^5.0 || ^6.0", - "vimeo/psalm": "^5.7.7" + "vimeo/psalm": "^5.9.0" }, "suggest": { "ext-bcmath": "Decimal128 type support" diff --git a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php index 5cd97cb4e..69ea29eae 100644 --- a/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php +++ b/lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php @@ -1467,7 +1467,7 @@ private function hasQueryOperators($value): bool /** * Returns the list of discriminator values for the given ClassMetadata * - * @psalm-return list + * @psalm-return list */ private function getClassDiscriminatorValues(ClassMetadata $metadata): array { diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 9e449e8c7..c3fa31dd1 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -145,7 +145,7 @@ parameters: path: lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php - - message: "#^Parameter \\#2 \\$options of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\\\:\\:addIndex\\(\\) expects array\\{background\\?\\: bool, bits\\?\\: int, default_language\\?\\: string, expireAfterSeconds\\?\\: int, language_override\\?\\: string, min\\?\\: float, max\\?\\: float, name\\?\\: string, \\.\\.\\.\\}, array\\\\|bool\\|float\\|int\\|string\\|null\\>\\|bool\\|float\\|int\\|string\\|null\\> given\\.$#" + message: "#^Parameter \\#2 \\$options of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\\\:\\:addIndex\\(\\) expects array\\{background\\?\\: bool, bits\\?\\: int, default_language\\?\\: string, expireAfterSeconds\\?\\: int, language_override\\?\\: string, min\\?\\: float, max\\?\\: float, name\\?\\: string, \\.\\.\\.\\}, array\\\\|string, mixed\\>\\|bool\\|float\\|int\\|string\\|null\\>\\|bool\\|float\\|int\\|string\\|null\\> given\\.$#" count: 1 path: lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 49373a5ce..439b6dee2 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + IteratorAggregate @@ -12,8 +12,8 @@ - $reflectionClass->implementsInterface(GridFSRepository::class) - $reflectionClass->implementsInterface(ObjectRepository::class) + implementsInterface(GridFSRepository::class)]]> + implementsInterface(ObjectRepository::class)]]> @@ -33,7 +33,7 @@ - array<string|null> + ]]> $mapping @@ -43,29 +43,29 @@ $mapping - [$this->identifier => $this->getIdentifierValue($object)] + identifier => $this->getIdentifierValue($object)]]]> - $this->associationMappings - $this->associationMappings - $this->fieldMappings + associationMappings]]> + associationMappings]]> + fieldMappings]]> $mapping $mapping - array_filter( - $this->associationMappings, - static fn ($assoc) => ! empty($assoc['embedded']) - ) + associationMappings, + static fn ($assoc) => ! empty($assoc['embedded']) + )]]> FieldMapping FieldMappingConfig - array<string, FieldMapping> + ]]> array - array<string|null> + ]]> @@ -84,64 +84,64 @@ $options - $xmlRoot->field - $xmlRoot->id - $xmlRoot->{'also-load-methods'} - $xmlRoot->{'default-discriminator-value'} - $xmlRoot->{'discriminator-field'} - $xmlRoot->{'discriminator-map'} - $xmlRoot->{'embed-many'} - $xmlRoot->{'embed-one'} - $xmlRoot->{'indexes'} - $xmlRoot->{'lifecycle-callbacks'} - $xmlRoot->{'read-preference'} - $xmlRoot->{'reference-many'} - $xmlRoot->{'reference-one'} - $xmlRoot->{'schema-validation'} - $xmlRoot->{'shard-key'} + field]]> + id]]> + {'also-load-methods'}]]> + {'default-discriminator-value'}]]> + {'discriminator-field'}]]> + {'discriminator-map'}]]> + {'embed-many'}]]> + {'embed-one'}]]> + {'indexes'}]]> + {'lifecycle-callbacks'}]]> + {'read-preference'}]]> + {'reference-many'}]]> + {'reference-one'}]]> + {'schema-validation'}]]> + {'shard-key'}]]> - (bool) $mapping['background'] - (bool) $mapping['sparse'] - (bool) $mapping['unique'] - (string) $mapping['index-name'] + + + + assert($attributes instanceof SimpleXMLElement) - isset($xmlRoot->field) - isset($xmlRoot->id) - isset($xmlRoot->{'default-discriminator-value'}) - isset($xmlRoot->{'discriminator-field'}) - isset($xmlRoot->{'discriminator-map'}) - isset($xmlRoot->{'embed-many'}) - isset($xmlRoot->{'embed-one'}) - isset($xmlRoot->{'indexes'}) - isset($xmlRoot->{'lifecycle-callbacks'}) - isset($xmlRoot->{'read-preference'}) - isset($xmlRoot->{'reference-many'}) - isset($xmlRoot->{'reference-one'}) - isset($xmlRoot->{'schema-validation'}) - isset($xmlRoot->{'shard-key'}) + field)]]> + id)]]> + {'default-discriminator-value'})]]> + {'discriminator-field'})]]> + {'discriminator-map'})]]> + {'embed-many'})]]> + {'embed-one'})]]> + {'indexes'})]]> + {'lifecycle-callbacks'})]]> + {'read-preference'})]]> + {'reference-many'})]]> + {'reference-one'})]]> + {'schema-validation'})]]> + {'shard-key'})]]> - $xmlRoot->getName() === 'document' - $xmlRoot->getName() === 'embedded-document' - $xmlRoot->getName() === 'gridfs-file' - $xmlRoot->getName() === 'mapped-superclass' - $xmlRoot->getName() === 'query-result-document' - $xmlRoot->getName() === 'view' - isset($xmlRoot->{'also-load-methods'}) + getName() === 'document']]> + getName() === 'embedded-document']]> + getName() === 'gridfs-file']]> + getName() === 'mapped-superclass']]> + getName() === 'query-result-document']]> + getName() === 'view']]> + {'also-load-methods'})]]> - new PersistentCollection($coll, $dm, $dm->getUnitOfWork()) - new PersistentCollection($coll, $dm, $dm->getUnitOfWork()) + getUnitOfWork())]]> + getUnitOfWork())]]> - is_object($this->coll) + coll)]]> @@ -151,7 +151,7 @@ - $this->resolvedNames + resolvedNames]]> @@ -164,10 +164,10 @@ $query - $this->query - $this->query - $this->query - $this->query + query]]> + query]]> + query]]> + query]]> @@ -180,11 +180,6 @@ array - - - $documentIndexWeights[$key] - - getDocumentManager @@ -253,16 +248,16 @@ $mapping - $this->parentAssociations + parentAssociations]]> $divided - array<class-string, array{0: ClassMetadata<object>, 1: array<string, object>}> + , 1: array}>]]> - $mapping['targetDocument'] + @@ -275,12 +270,12 @@ - $class->associationMappings['ref'] - $class->associationMappings['ref1'] - $class->associationMappings['ref2'] - $class->associationMappings['ref3'] - $class->associationMappings['ref4'] - ['storeAs' => ClassMetadata::REFERENCE_STORE_AS_DB_REF] + associationMappings['ref']]]> + associationMappings['ref1']]]> + associationMappings['ref2']]]> + associationMappings['ref3']]]> + associationMappings['ref4']]]> + ClassMetadata::REFERENCE_STORE_AS_DB_REF]]]> @@ -288,13 +283,96 @@ new ArrayCollection([$project]) + + + friends]]> + friends]]> + friends]]> + friends]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + inception]]> + phonebooks]]> + phonebooks]]> + phonebooks]]> + phonebooks]]> + phonebooks]]> + phonebooks]]> + phonenumbers]]> + phonenumbers]]> + phonenumbers]]> + phonenumbers]]> + phonenumbers]]> + phonenumbers]]> + phonenumbers]]> + phonenumbers]]> + phonenumbersArray]]> + phonenumbersArray]]> + phonenumbersArray]]> + phonenumbersArray]]> + phonenumbersArray]]> + clear + + - [$user->categories[0]->children, $user->categories[1]->children] - [$user->categories[0]->children[0]->children, $user->categories[0]->children[1]->children] - [$user->categories[0]->children[0]->children, $user->categories[0]->children[1]->children] + categories[0]->children, $user->categories[1]->children]]]> + categories[0]->children[0]->children, $user->categories[0]->children[1]->children]]]> + categories[0]->children[0]->children, $user->categories[0]->children[1]->children]]]> + + + $phonenumbers + $phonenumbers + + $i @@ -302,6 +380,16 @@ $j $j + + coll]]> + coll]]> + + + + + $phonenumbers + $phonenumbers + @@ -310,14 +398,14 @@ - new ArrayCollection([ + - new ArrayCollection([ + ])]]> + + ])]]> @@ -327,14 +415,20 @@ - ['upsert' => true] + true]]]> - $doc->embeds + embeds]]> + + + embeds]]> + embeds]]> + + assertIsInt @@ -366,14 +460,20 @@ - new ArrayCollection([ + + ])]]> new ArrayCollection([$referenceMany1, $referenceMany2]) + + + refMany]]> + refMany]]> + + $collection @@ -384,29 +484,29 @@ DocumentManager - $this->dm + dm]]> $config $mapping - [ - 'fieldName' => 'assoc', - 'reference' => true, - 'type' => 'many', - 'targetDocument' => 'stdClass', - 'repositoryMethod' => 'fetch', - $prop => $value, - ] - [ - 'fieldName' => 'enum', - 'enumType' => Card::class, - ] - [ - 'fieldName' => 'enum', - 'enumType' => SuitNonBacked::class, - ] + 'assoc', + 'reference' => true, + 'type' => 'many', + 'targetDocument' => 'stdClass', + 'repositoryMethod' => 'fetch', + $prop => $value, + ]]]> + 'enum', + 'enumType' => Card::class, + ]]]> + 'enum', + 'enumType' => SuitNonBacked::class, + ]]]> @@ -416,7 +516,7 @@ - ['type' => -1] + -1]]]> diff --git a/psalm.xml b/psalm.xml index 02911c8bf..e89edfc04 100644 --- a/psalm.xml +++ b/psalm.xml @@ -19,9 +19,6 @@ - - - diff --git a/tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php b/tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php index 27476cd02..a6866191e 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php @@ -213,17 +213,20 @@ public function testDifferentStoreAsDbReferences(): void self::assertInstanceOf(ObjectId::class, $dbRef); $dbRef = $this->dm->createReference($r, $class->associationMappings['ref2']); + self::assertIsArray($dbRef); self::assertCount(2, $dbRef); self::assertArrayHasKey('$ref', $dbRef); self::assertArrayHasKey('$id', $dbRef); $dbRef = $this->dm->createReference($r, $class->associationMappings['ref3']); + self::assertIsArray($dbRef); self::assertCount(3, $dbRef); self::assertArrayHasKey('$ref', $dbRef); self::assertArrayHasKey('$id', $dbRef); self::assertArrayHasKey('$db', $dbRef); $dbRef = $this->dm->createReference($r, $class->associationMappings['ref4']); + self::assertIsArray($dbRef); self::assertCount(1, $dbRef); self::assertArrayHasKey('id', $dbRef); } diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencePrimerTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencePrimerTest.php index b58e8ba20..ac5c05929 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencePrimerTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencePrimerTest.php @@ -382,6 +382,7 @@ public function testPrimeReferencesInvokesPrimer(): void $this->dm->flush(); $this->dm->clear(); + /** @var array> $invokedArgs */ $invokedArgs = []; $primer = static function (DocumentManager $dm, ClassMetadata $class, array $ids, array $hints) use (&$invokedArgs) { $invokedArgs[] = func_get_args(); @@ -395,6 +396,8 @@ public function testPrimeReferencesInvokesPrimer(): void ->getQuery() ->toArray(); + self::assertIsArray($invokedArgs[0]); + self::assertIsArray($invokedArgs[1]); self::assertCount(2, $invokedArgs, 'Primer was invoked once for each referenced class.'); self::assertArrayHasKey(Query::HINT_READ_PREFERENCE, $invokedArgs[0][3], 'Primer was invoked with UnitOfWork hints from original query.'); self::assertSame($readPreference, $invokedArgs[0][3][Query::HINT_READ_PREFERENCE], 'Primer was invoked with UnitOfWork hints from original query.'); diff --git a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ShardKeyTest.php b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ShardKeyTest.php index c69c46611..b2c17c69c 100644 --- a/tests/Doctrine/ODM/MongoDB/Tests/Functional/ShardKeyTest.php +++ b/tests/Doctrine/ODM/MongoDB/Tests/Functional/ShardKeyTest.php @@ -55,6 +55,7 @@ public function testUpdateAfterSave(): void self::assertSame('update', $lastQuery->getCommandName()); $command = $lastQuery->getCommand(); + self::assertIsArray($command->updates); self::assertCount(1, $command->updates); self::assertEquals($o->key, $command->updates[0]->q->k); } @@ -71,6 +72,7 @@ public function testUpsert(): void self::assertSame('update', $lastQuery->getCommandName()); $command = $lastQuery->getCommand(); + self::assertIsArray($command->updates); self::assertCount(1, $command->updates); self::assertEquals($o->key, $command->updates[0]->q->k); self::assertTrue($command->updates[0]->upsert); @@ -89,6 +91,7 @@ public function testRemove(): void self::assertSame('delete', $lastQuery->getCommandName()); $command = $lastQuery->getCommand(); + self::assertIsArray($command->deletes); self::assertCount(1, $command->deletes); self::assertEquals($o->key, $command->deletes[0]->q->k); }