Skip to content

Commit 10530b3

Browse files
authored
Fix psalm build (#2525)
* Fix return type * Fix psalm build These new errors are because a bug in psalm with get_class see vimeo/psalm#9607, they will be gone once we use ::class
1 parent 97cbc8f commit 10530b3

File tree

8 files changed

+218
-112
lines changed

8 files changed

+218
-112
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@
4242
"doctrine/coding-standard": "^11.0",
4343
"jmikola/geojson": "^1.0",
4444
"phpbench/phpbench": "^1.0.0@dev",
45-
"phpstan/phpstan": "^1.9.4",
45+
"phpstan/phpstan": "^1.10.11",
4646
"phpstan/phpstan-phpunit": "^1.0",
4747
"phpunit/phpunit": "^9.5.5 || ^10.0.15",
4848
"squizlabs/php_codesniffer": "^3.5",
4949
"symfony/cache": "^4.4 || ^5.0 || ^6.0",
50-
"vimeo/psalm": "^5.7.7"
50+
"vimeo/psalm": "^5.9.0"
5151
},
5252
"suggest": {
5353
"ext-bcmath": "Decimal128 type support"

lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ private function hasQueryOperators($value): bool
14671467
/**
14681468
* Returns the list of discriminator values for the given ClassMetadata
14691469
*
1470-
* @psalm-return list<class-string>
1470+
* @psalm-return list<class-string|null>
14711471
*/
14721472
private function getClassDiscriminatorValues(ClassMetadata $metadata): array
14731473
{

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ parameters:
145145
path: lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
146146

147147
-
148-
message: "#^Parameter \\#2 \\$options of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:addIndex\\(\\) expects array\\{background\\?\\: bool, bits\\?\\: int, default_language\\?\\: string, expireAfterSeconds\\?\\: int, language_override\\?\\: string, min\\?\\: float, max\\?\\: float, name\\?\\: string, \\.\\.\\.\\}, array\\<string, non\\-empty\\-array\\<string, array\\<int\\|string, mixed\\>\\|bool\\|float\\|int\\|string\\|null\\>\\|bool\\|float\\|int\\|string\\|null\\> given\\.$#"
148+
message: "#^Parameter \\#2 \\$options of method Doctrine\\\\ODM\\\\MongoDB\\\\Mapping\\\\ClassMetadata\\<object\\>\\:\\:addIndex\\(\\) expects array\\{background\\?\\: bool, bits\\?\\: int, default_language\\?\\: string, expireAfterSeconds\\?\\: int, language_override\\?\\: string, min\\?\\: float, max\\?\\: float, name\\?\\: string, \\.\\.\\.\\}, array\\<string, non\\-empty\\-array\\<string, array\\<int\\<0, max\\>\\|string, mixed\\>\\|bool\\|float\\|int\\|string\\|null\\>\\|bool\\|float\\|int\\|string\\|null\\> given\\.$#"
149149
count: 1
150150
path: lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
151151

psalm-baseline.xml

Lines changed: 205 additions & 105 deletions
Large diffs are not rendered by default.

psalm.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
<file name="lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup/Match.php" />
2020
<file name="lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Match.php" />
2121
<file name="tests/Doctrine/ODM/MongoDB/Tests/Mapping/Driver/fixtures/User.php" />
22-
<!-- Remove CollWithPHP81Types once Psalm supports native intersection https://github.com/vimeo/psalm/issues/6413 -->
23-
<file name="tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/DefaultPersistentCollectionGeneratorTest.php" />
24-
<file name="tests/Doctrine/ODM/MongoDB/Tests/PersistentCollection/CollWithPHP81Types.php" />
2522
<directory name="vendor" />
2623
</ignoreFiles>
2724
</projectFiles>

tests/Doctrine/ODM/MongoDB/Tests/DocumentManagerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,17 +213,20 @@ public function testDifferentStoreAsDbReferences(): void
213213
self::assertInstanceOf(ObjectId::class, $dbRef);
214214

215215
$dbRef = $this->dm->createReference($r, $class->associationMappings['ref2']);
216+
self::assertIsArray($dbRef);
216217
self::assertCount(2, $dbRef);
217218
self::assertArrayHasKey('$ref', $dbRef);
218219
self::assertArrayHasKey('$id', $dbRef);
219220

220221
$dbRef = $this->dm->createReference($r, $class->associationMappings['ref3']);
222+
self::assertIsArray($dbRef);
221223
self::assertCount(3, $dbRef);
222224
self::assertArrayHasKey('$ref', $dbRef);
223225
self::assertArrayHasKey('$id', $dbRef);
224226
self::assertArrayHasKey('$db', $dbRef);
225227

226228
$dbRef = $this->dm->createReference($r, $class->associationMappings['ref4']);
229+
self::assertIsArray($dbRef);
227230
self::assertCount(1, $dbRef);
228231
self::assertArrayHasKey('id', $dbRef);
229232
}

tests/Doctrine/ODM/MongoDB/Tests/Functional/ReferencePrimerTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ public function testPrimeReferencesInvokesPrimer(): void
382382
$this->dm->flush();
383383
$this->dm->clear();
384384

385+
/** @var array<int, array<int, mixed>> $invokedArgs */
385386
$invokedArgs = [];
386387
$primer = static function (DocumentManager $dm, ClassMetadata $class, array $ids, array $hints) use (&$invokedArgs) {
387388
$invokedArgs[] = func_get_args();
@@ -395,6 +396,8 @@ public function testPrimeReferencesInvokesPrimer(): void
395396
->getQuery()
396397
->toArray();
397398

399+
self::assertIsArray($invokedArgs[0]);
400+
self::assertIsArray($invokedArgs[1]);
398401
self::assertCount(2, $invokedArgs, 'Primer was invoked once for each referenced class.');
399402
self::assertArrayHasKey(Query::HINT_READ_PREFERENCE, $invokedArgs[0][3], 'Primer was invoked with UnitOfWork hints from original query.');
400403
self::assertSame($readPreference, $invokedArgs[0][3][Query::HINT_READ_PREFERENCE], 'Primer was invoked with UnitOfWork hints from original query.');

tests/Doctrine/ODM/MongoDB/Tests/Functional/ShardKeyTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function testUpdateAfterSave(): void
5555
self::assertSame('update', $lastQuery->getCommandName());
5656

5757
$command = $lastQuery->getCommand();
58+
self::assertIsArray($command->updates);
5859
self::assertCount(1, $command->updates);
5960
self::assertEquals($o->key, $command->updates[0]->q->k);
6061
}
@@ -71,6 +72,7 @@ public function testUpsert(): void
7172
self::assertSame('update', $lastQuery->getCommandName());
7273

7374
$command = $lastQuery->getCommand();
75+
self::assertIsArray($command->updates);
7476
self::assertCount(1, $command->updates);
7577
self::assertEquals($o->key, $command->updates[0]->q->k);
7678
self::assertTrue($command->updates[0]->upsert);
@@ -89,6 +91,7 @@ public function testRemove(): void
8991
self::assertSame('delete', $lastQuery->getCommandName());
9092

9193
$command = $lastQuery->getCommand();
94+
self::assertIsArray($command->deletes);
9295
self::assertCount(1, $command->deletes);
9396
self::assertEquals($o->key, $command->deletes[0]->q->k);
9497
}

0 commit comments

Comments
 (0)