10
10
use Doctrine \Persistence \ObjectManager ;
11
11
use PHPStan \ShouldNotHappenException ;
12
12
use ReflectionException ;
13
+ use function class_exists ;
13
14
use function is_file ;
14
15
use function is_readable ;
15
16
use function sprintf ;
@@ -69,7 +70,12 @@ public function isTransient(string $className): bool
69
70
70
71
try {
71
72
if ($ objectManager === null ) {
72
- return $ this ->getMetadataFactory ()->isTransient ($ className );
73
+ $ metadataFactory = $ this ->getMetadataFactory ();
74
+ if ($ metadataFactory === null ) {
75
+ return true ;
76
+ }
77
+
78
+ return $ metadataFactory ->isTransient ($ className );
73
79
}
74
80
75
81
return $ objectManager ->getMetadataFactory ()->isTransient ($ className );
@@ -81,12 +87,16 @@ public function isTransient(string $className): bool
81
87
/**
82
88
* @return ClassMetadataFactory<ClassMetadata>
83
89
*/
84
- private function getMetadataFactory (): ClassMetadataFactory
90
+ private function getMetadataFactory (): ? ClassMetadataFactory
85
91
{
86
92
if ($ this ->metadataFactory !== null ) {
87
93
return $ this ->metadataFactory ;
88
94
}
89
95
96
+ if (!class_exists (\Doctrine \ORM \Mapping \ClassMetadataFactory::class)) {
97
+ return null ;
98
+ }
99
+
90
100
$ metadataFactory = new \PHPStan \Doctrine \Mapping \ClassMetadataFactory ();
91
101
92
102
return $ this ->metadataFactory = $ metadataFactory ;
@@ -107,7 +117,12 @@ public function getClassMetadata(string $className): ?ClassMetadataInfo
107
117
108
118
try {
109
119
if ($ objectManager === null ) {
110
- $ metadata = $ this ->getMetadataFactory ()->getMetadataFor ($ className );
120
+ $ metadataFactory = $ this ->getMetadataFactory ();
121
+ if ($ metadataFactory === null ) {
122
+ return null ;
123
+ }
124
+
125
+ $ metadata = $ metadataFactory ->getMetadataFor ($ className );
111
126
} else {
112
127
$ metadata = $ objectManager ->getClassMetadata ($ className );
113
128
}
0 commit comments