File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace PHPStan \Type \Doctrine ;
4
4
5
+ use Doctrine \ORM \Mapping \Entity ;
5
6
use Doctrine \Persistence \ObjectManager ;
6
7
use PHPStan \Reflection \ReflectionProvider ;
8
+ use ReflectionClass ;
7
9
use function is_file ;
8
10
use function is_readable ;
9
11
@@ -97,6 +99,19 @@ public function getResolvedRepositoryClass(): string
97
99
98
100
public function getRepositoryClass (string $ className ): string
99
101
{
102
+ if (PHP_MAJOR_VERSION >= 8 && $ this ->reflectionProvider ->hasClass ($ className )) {
103
+ $ classReflection = $ this ->reflectionProvider ->getClass ($ className )->getNativeReflection ();
104
+ if (method_exists ($ classReflection , 'getAttributes ' )) {
105
+ $ attribute = $ classReflection ->getAttributes (Entity::class)[0 ] ?? null ;
106
+ if ($ attribute !== null ) {
107
+ $ attributeInstance = $ attribute ->newInstance ();
108
+ if ($ attributeInstance ->repositoryClass !== null ) {
109
+ return $ attributeInstance ->repositoryClass ;
110
+ }
111
+ }
112
+ }
113
+ }
114
+
100
115
$ objectManager = $ this ->getObjectManager ();
101
116
if ($ objectManager === null ) {
102
117
return $ this ->getResolvedRepositoryClass ();
You can’t perform that action at this time.
0 commit comments