File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ services:
2121 repositoryClass : %doctrine.repositoryClass%
2222 tags :
2323 - phpstan.broker.dynamicMethodReturnTypeExtension
24+ -
25+ class : PHPStan\Type\Doctrine\ObjectManagerMergeDynamicReturnTypeExtension
26+ tags :
27+ - phpstan.broker.dynamicMethodReturnTypeExtension
2428 -
2529 class : PHPStan\Type\Doctrine\EntityRepositoryDynamicReturnTypeExtension
2630 tags :
Original file line number Diff line number Diff line change 1+ <?php declare (strict_types = 1 );
2+
3+ namespace PHPStan \Type \Doctrine ;
4+
5+ use PhpParser \Node \Expr \MethodCall ;
6+ use PHPStan \Analyser \Scope ;
7+ use PHPStan \Reflection \MethodReflection ;
8+ use PHPStan \Type \Type ;
9+
10+ class ObjectManagerMergeDynamicReturnTypeExtension implements \PHPStan \Type \DynamicMethodReturnTypeExtension
11+ {
12+
13+ public function getClass (): string
14+ {
15+ return \Doctrine \Common \Persistence \ObjectManager::class;
16+ }
17+
18+ public function isMethodSupported (MethodReflection $ methodReflection ): bool
19+ {
20+ return $ methodReflection ->getName () === 'merge ' ;
21+ }
22+
23+ public function getTypeFromMethodCall (
24+ MethodReflection $ methodReflection ,
25+ MethodCall $ methodCall ,
26+ Scope $ scope
27+ ): Type
28+ {
29+ if (count ($ methodCall ->args ) === 0 ) {
30+ return $ methodReflection ->getReturnType ();
31+ }
32+
33+ return $ scope ->getType ($ methodCall ->args [0 ]->value );
34+ }
35+
36+ }
You can’t perform that action at this time.
0 commit comments