Skip to content

Commit 7cafcdc

Browse files
authored
Merge pull request #2331 from franmomu/psalm_to_level_6_repo
Fix phpdoc for repositories
2 parents 4d34a81 + a2f5002 commit 7cafcdc

File tree

5 files changed

+36
-26
lines changed

5 files changed

+36
-26
lines changed

lib/Doctrine/ODM/MongoDB/DocumentManager.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Doctrine\ODM\MongoDB\Repository\RepositoryFactory;
2121
use Doctrine\ODM\MongoDB\Repository\ViewRepository;
2222
use Doctrine\Persistence\ObjectManager;
23-
use Doctrine\Persistence\ObjectRepository;
2423
use InvalidArgumentException;
2524
use Jean85\PrettyVersions;
2625
use MongoDB\Client;
@@ -573,7 +572,7 @@ public function unlock(object $document): void
573572
* @param string $className The name of the Document.
574573
* @psalm-param class-string<T> $className
575574
*
576-
* @return ObjectRepository|DocumentRepository|GridFSRepository|ViewRepository The repository.
575+
* @return DocumentRepository|GridFSRepository|ViewRepository The repository.
577576
* @psalm-return DocumentRepository<T>|GridFSRepository<T>|ViewRepository<T>
578577
*
579578
* @template T of object

lib/Doctrine/ODM/MongoDB/Repository/AbstractRepositoryFactory.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Doctrine\Persistence\ObjectRepository;
1212

1313
use function is_a;
14-
use function ltrim;
1514
use function spl_object_hash;
1615

1716
/**
@@ -42,7 +41,7 @@ public function getRepository(DocumentManager $documentManager, string $document
4241
return $this->repositoryList[$hashKey];
4342
}
4443

45-
$repository = $this->createRepository($documentManager, ltrim($documentName, '\\'));
44+
$repository = $this->createRepository($documentManager, $documentName);
4645

4746
$this->repositoryList[$hashKey] = $repository;
4847

@@ -54,7 +53,7 @@ public function getRepository(DocumentManager $documentManager, string $document
5453
*
5554
* @psalm-param class-string<T> $documentName
5655
*
57-
* @return ObjectRepository|DocumentRepository|GridFSRepository|ViewRepository
56+
* @return DocumentRepository|GridFSRepository|ViewRepository
5857
* @psalm-return DocumentRepository<T>|GridFSRepository<T>|ViewRepository<T>
5958
*
6059
* @template T of object

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
99
use Doctrine\ODM\MongoDB\Tests\BaseTest;
1010

11+
use function assert;
12+
1113
/**
1214
* Test the orphan removal on embedded documents that contain references with cascade operations.
1315
*/
@@ -138,20 +140,22 @@ public function testClearAndAddEmbedMany()
138140
$this->assertNotNull($this->getAddressRepository()->find($address3->id), 'Should have added address 3');
139141
}
140142

141-
/**
142-
* @return DocumentRepository
143-
*/
144-
private function getUserRepository()
143+
private function getUserRepository(): DocumentRepository
145144
{
146-
return $this->dm->getRepository(OrphanRemovalCascadeUser::class);
145+
$repository = $this->dm->getRepository(OrphanRemovalCascadeUser::class);
146+
147+
assert($repository instanceof DocumentRepository);
148+
149+
return $repository;
147150
}
148151

149-
/**
150-
* @return DocumentRepository
151-
*/
152-
private function getAddressRepository()
152+
private function getAddressRepository(): DocumentRepository
153153
{
154-
return $this->dm->getRepository(OrphanRemovalCascadeAddress::class);
154+
$repository = $this->dm->getRepository(OrphanRemovalCascadeAddress::class);
155+
156+
assert($repository instanceof DocumentRepository);
157+
158+
return $repository;
155159
}
156160
}
157161

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
99
use Doctrine\ODM\MongoDB\Tests\BaseTest;
1010

11+
use function assert;
12+
1113
class OrphanRemovalTest extends BaseTest
1214
{
1315
public function testOrphanRemoval()
@@ -279,20 +281,22 @@ public function testOrphanRemovalReferenceManyOnRemoveWithoutCascade()
279281
$this->assertNull($this->getProfileRepository()->find($profile2->id), 'Profile 2 should have been removed');
280282
}
281283

282-
/**
283-
* @return DocumentRepository
284-
*/
285-
private function getUserRepository()
284+
private function getUserRepository(): DocumentRepository
286285
{
287-
return $this->dm->getRepository(OrphanRemovalUser::class);
286+
$repository = $this->dm->getRepository(OrphanRemovalUser::class);
287+
288+
assert($repository instanceof DocumentRepository);
289+
290+
return $repository;
288291
}
289292

290-
/**
291-
* @return DocumentRepository
292-
*/
293-
private function getProfileRepository()
293+
private function getProfileRepository(): DocumentRepository
294294
{
295-
return $this->dm->getRepository(OrphanRemovalProfile::class);
295+
$repository = $this->dm->getRepository(OrphanRemovalProfile::class);
296+
297+
assert($repository instanceof DocumentRepository);
298+
299+
return $repository;
296300
}
297301
}
298302

tests/Doctrine/ODM/MongoDB/Tests/Repository/DefaultGridFSRepositoryTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ public function testUploadFileWithoutChunkSize()
257257

258258
private function getRepository($className = File::class): GridFSRepository
259259
{
260-
return $this->dm->getRepository($className);
260+
$repository = $this->dm->getRepository($className);
261+
262+
assert($repository instanceof GridFSRepository);
263+
264+
return $repository;
261265
}
262266

263267
private function uploadFile($filename, ?UploadOptions $uploadOptions = null): File

0 commit comments

Comments
 (0)