Skip to content

Commit 8177b06

Browse files
committed
Fix Mongo stubs
1 parent b5881e3 commit 8177b06

File tree

5 files changed

+30
-18
lines changed

5 files changed

+30
-18
lines changed

src/Type/Doctrine/ObjectMetadataResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private function getResolvedRepositoryClass(): string
7979
if ($this->repositoryClass !== null) {
8080
return $this->resolvedRepositoryClass = $this->repositoryClass;
8181
} elseif ($objectManager !== null && get_class($objectManager) === 'Doctrine\ODM\MongoDB\DocumentManager') {
82-
return $this->resolvedRepositoryClass = 'Doctrine\ODM\MongoDB\DocumentRepository';
82+
return $this->resolvedRepositoryClass = 'Doctrine\ODM\MongoDB\Repository\DocumentRepository';
8383
}
8484

8585
return $this->resolvedRepositoryClass = 'Doctrine\ORM\EntityRepository';

stubs/DocumentManager.stub

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class DocumentManager implements ObjectManager
99
{
1010

1111
/**
12-
* @template T
12+
* @template T of object
1313
* @phpstan-param class-string<T> $documentName
1414
* @phpstan-param mixed $identifier
1515
* @phpstan-param integer|null $lockMode
@@ -19,7 +19,7 @@ class DocumentManager implements ObjectManager
1919
public function find($documentName, $identifier, $lockMode = null, $lockVersion = null);
2020

2121
/**
22-
* @template T
22+
* @template T of object
2323
* @phpstan-param T $document
2424
* @phpstan-return T
2525
*/
@@ -33,15 +33,15 @@ class DocumentManager implements ObjectManager
3333
public function getRepository($documentName);
3434

3535
/**
36-
* @template T
36+
* @template T of object
3737
* @phpstan-param class-string<T> $documentName
3838
* @phpstan-param mixed $identifier
39-
* @phpstan-return T|null
39+
* @phpstan-return T
4040
*/
4141
public function getReference($documentName, $identifier);
4242

4343
/**
44-
* @template T
44+
* @template T of object
4545
* @phpstan-param class-string<T> $documentName
4646
* @phpstan-param mixed $identifier
4747
*

tests/DoctrineIntegration/ODM/data/documentManagerDynamicReturn-2.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
},
77
{
88
"message": "Call to an undefined method PHPStan\\DoctrineIntegration\\ODM\\DocumentManagerDynamicReturn\\MyDocument::doSomethingElse().",
9-
"line": 43,
9+
"line": 38,
1010
"ignorable": true
1111
},
1212
{
1313
"message": "Call to an undefined method PHPStan\\DoctrineIntegration\\ODM\\DocumentManagerDynamicReturn\\MyDocument::doSomethingElse().",
14-
"line": 55,
14+
"line": 45,
1515
"ignorable": true
1616
}
1717
]

tests/DoctrineIntegration/ODM/data/documentManagerDynamicReturn.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,13 @@ public function findDynamicType(): void
3434
public function getReferenceDynamicType(): void
3535
{
3636
$test = $this->documentManager->getReference(MyDocument::class, 'blah-123');
37-
38-
if ($test === null) {
39-
throw new RuntimeException('Sorry, but no...');
40-
}
41-
4237
$test->doSomething();
4338
$test->doSomethingElse();
4439
}
4540

4641
public function getPartialReferenceDynamicType(): void
4742
{
4843
$test = $this->documentManager->getPartialReference(MyDocument::class, 'blah-123');
49-
50-
if ($test === null) {
51-
throw new RuntimeException('Sorry, but no...');
52-
}
53-
5444
$test->doSomething();
5545
$test->doSomethingElse();
5646
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[
2+
{
3+
"message": "Call to an undefined method object::doSomething().",
4+
"line": 31,
5+
"ignorable": true
6+
},
7+
{
8+
"message": "Call to an undefined method object::doSomethingElse().",
9+
"line": 32,
10+
"ignorable": true
11+
},
12+
{
13+
"message": "Call to an undefined method object::doSomething().",
14+
"line": 43,
15+
"ignorable": true
16+
},
17+
{
18+
"message": "Call to an undefined method object::doSomethingElse().",
19+
"line": 44,
20+
"ignorable": true
21+
}
22+
]

0 commit comments

Comments
 (0)