Skip to content

Commit bf3bb15

Browse files
author
Stefan Siegl
committed
Add dynamic return type extension for EntityManager#merge
1 parent af4cb66 commit bf3bb15

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

extension.neon

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ services:
2121
repositoryClass: %doctrine.repositoryClass%
2222
tags:
2323
- phpstan.broker.dynamicMethodReturnTypeExtension
24+
-
25+
class: PHPStan\Type\Doctrine\EntityManagerMergeDynamicReturnTypeExtension
26+
tags:
27+
- phpstan.broker.dynamicMethodReturnTypeExtension
2428
-
2529
class: PHPStan\Type\Doctrine\EntityRepositoryDynamicReturnTypeExtension
2630
tags:
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 EntityManagerMergeDynamicReturnTypeExtension implements \PHPStan\Type\DynamicMethodReturnTypeExtension
11+
{
12+
13+
public function getClass(): string
14+
{
15+
return \Doctrine\ORM\EntityManager::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+
}

0 commit comments

Comments
 (0)