Skip to content

Commit 9676493

Browse files
authored
Add more specific phpdoc to DocumentRepository (#2326)
* Bump phpstan and psalm * Update phpdoc of DocumentRepository Psalm does not work well inheriting phpdoc templates in methods, so duplicating them fixes the issue.
1 parent f033c43 commit 9676493

File tree

4 files changed

+22
-14
lines changed

4 files changed

+22
-14
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@
4343
"doctrine/coding-standard": "^9.0",
4444
"jmikola/geojson": "^1.0",
4545
"phpbench/phpbench": "^1.0.0",
46-
"phpstan/phpstan": "^0.12.32",
46+
"phpstan/phpstan": "^0.12.89",
4747
"phpstan/phpstan-phpunit": "^0.12.19",
4848
"phpunit/phpunit": "^8.5 || ^9",
4949
"squizlabs/php_codesniffer": "^3.5",
5050
"symfony/cache": "^4.4 || ^5.0",
51-
"vimeo/psalm": "^4.2.1"
51+
"vimeo/psalm": "^4.8.1"
5252
},
5353
"suggest": {
5454
"ext-bcmath": "Decimal128 type support"

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ public function clear(): void
101101
*
102102
* @param mixed $id Identifier.
103103
*
104+
* @psalm-return T|null
105+
*
104106
* @throws MappingException
105107
* @throws LockException
106108
*/
@@ -155,6 +157,8 @@ public function find($id, int $lockMode = LockMode::NONE, ?int $lockVersion = nu
155157

156158
/**
157159
* Finds all documents in the repository.
160+
*
161+
* {@inheritDoc}
158162
*/
159163
public function findAll(): array
160164
{
@@ -164,8 +168,7 @@ public function findAll(): array
164168
/**
165169
* Finds documents by a set of criteria.
166170
*
167-
* @param int|null $limit
168-
* @param int|null $offset
171+
* {@inheritDoc}
169172
*/
170173
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
171174
{
@@ -175,14 +178,20 @@ public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $
175178
/**
176179
* Finds a single document by a set of criteria.
177180
*
178-
* @param array $criteria
179-
* @param array|null $sort
181+
* @param array<string, mixed>|null $sort
182+
* @param array<string, mixed> $criteria
183+
*
184+
* @return object|null The object.
185+
* @psalm-return T|null
180186
*/
181187
public function findOneBy(array $criteria, ?array $sort = null): ?object
182188
{
183189
return $this->getDocumentPersister()->load($criteria, null, [], 0, $sort);
184190
}
185191

192+
/**
193+
* @psalm-return class-string<T>
194+
*/
186195
public function getDocumentName(): string
187196
{
188197
return $this->documentName;
@@ -193,11 +202,17 @@ public function getDocumentManager(): DocumentManager
193202
return $this->dm;
194203
}
195204

205+
/**
206+
* @psalm-return ClassMetadata<T>
207+
*/
196208
public function getClassMetadata(): ClassMetadata
197209
{
198210
return $this->class;
199211
}
200212

213+
/**
214+
* @psalm-return class-string<T>
215+
*/
201216
public function getClassName(): string
202217
{
203218
return $this->getDocumentName();
@@ -207,7 +222,7 @@ public function getClassName(): string
207222
* Selects all elements from a selectable that match the expression and
208223
* returns a new collection containing these elements.
209224
*
210-
* @see Selectable::matching()
225+
* {@inheritDoc}
211226
*/
212227
public function matching(Criteria $criteria): ArrayCollection
213228
{

phpstan-baseline.neon

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,6 @@ parameters:
229229
count: 1
230230
path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php
231231

232-
-
233-
message: "#^Function mongodb\\\\bson\\\\tophp invoked with 1 parameter, 2 required\\.$#"
234-
count: 2
235-
path: tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php
236-
237232
-
238233
message: "#^Access to an undefined property Documents\\\\CmsArticle\\:\\:\\$title\\.$#"
239234
count: 4

tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ public function testClassMetadataInstanceSerialization()
6767
$cm->setVersioned(true);
6868
$cm->setVersionField('version');
6969
$validatorJson = '{ "$and": [ { "email": { "$regex": { "$regularExpression" : { "pattern": "@mongodb\\\\.com$", "options": "" } } } } ] }';
70-
/** @psalm-suppress TooFewArguments */
7170
$cm->setValidator(toPHP(fromJSON($validatorJson)));
7271
$cm->setValidationAction(ClassMetadata::SCHEMA_VALIDATION_ACTION_WARN);
7372
$cm->setValidationLevel(ClassMetadata::SCHEMA_VALIDATION_LEVEL_OFF);
@@ -100,7 +99,6 @@ public function testClassMetadataInstanceSerialization()
10099
$this->assertEquals('lock', $cm->lockField);
101100
$this->assertEquals(true, $cm->isVersioned);
102101
$this->assertEquals('version', $cm->versionField);
103-
/** @psalm-suppress TooFewArguments */
104102
$this->assertEquals(toPHP(fromJSON($validatorJson)), $cm->getValidator());
105103
$this->assertEquals(ClassMetadata::SCHEMA_VALIDATION_ACTION_WARN, $cm->getValidationAction());
106104
$this->assertEquals(ClassMetadata::SCHEMA_VALIDATION_LEVEL_OFF, $cm->getValidationLevel());

0 commit comments

Comments
 (0)