1010use Doctrine \Persistence \ObjectManager ;
1111use PHPStan \ShouldNotHappenException ;
1212use ReflectionException ;
13+ use function class_exists ;
1314use function is_file ;
1415use function is_readable ;
1516use function sprintf ;
@@ -69,7 +70,12 @@ public function isTransient(string $className): bool
6970
7071 try {
7172 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 );
7379 }
7480
7581 return $ objectManager ->getMetadataFactory ()->isTransient ($ className );
@@ -81,12 +87,16 @@ public function isTransient(string $className): bool
8187 /**
8288 * @return ClassMetadataFactory<ClassMetadata>
8389 */
84- private function getMetadataFactory (): ClassMetadataFactory
90+ private function getMetadataFactory (): ? ClassMetadataFactory
8591 {
8692 if ($ this ->metadataFactory !== null ) {
8793 return $ this ->metadataFactory ;
8894 }
8995
96+ if (!class_exists (\Doctrine \ORM \Mapping \ClassMetadataFactory::class)) {
97+ return null ;
98+ }
99+
90100 $ metadataFactory = new \PHPStan \Doctrine \Mapping \ClassMetadataFactory ();
91101
92102 return $ this ->metadataFactory = $ metadataFactory ;
@@ -107,7 +117,12 @@ public function getClassMetadata(string $className): ?ClassMetadataInfo
107117
108118 try {
109119 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 );
111126 } else {
112127 $ metadata = $ objectManager ->getClassMetadata ($ className );
113128 }
0 commit comments