1616use Doctrine \ORM \EntityManagerInterface ;
1717use Doctrine \ORM \Mapping \AssociationMapping ;
1818use Doctrine \ORM \Mapping \ClassMetadata ;
19+ use Doctrine \ORM \Mapping \EmbeddedClassMapping ;
20+ use Doctrine \ORM \Mapping \FieldMapping ;
21+ use Doctrine \ORM \Mapping \JoinColumnMapping ;
1922use Doctrine \ORM \Mapping \MappingException as OrmMappingException ;
2023use Doctrine \Persistence \Mapping \MappingException ;
2124use Symfony \Component \PropertyInfo \PropertyAccessExtractorInterface ;
@@ -88,20 +91,20 @@ public function getTypes(string $class, string $property, array $context = [])
8891 if ($ metadata instanceof ClassMetadata) {
8992 $ associationMapping = $ metadata ->getAssociationMapping ($ property );
9093
91- if (isset ($ associationMapping[ 'indexBy ' ] )) {
92- $ subMetadata = $ this ->entityManager ->getClassMetadata ($ associationMapping[ 'targetEntity ' ] );
94+ if (self :: getMappingValue ($ associationMapping, 'indexBy ' )) {
95+ $ subMetadata = $ this ->entityManager ->getClassMetadata (self :: getMappingValue ( $ associationMapping, 'targetEntity ' ) );
9396
9497 // Check if indexBy value is a property
95- $ fieldName = $ associationMapping[ 'indexBy ' ] ;
98+ $ fieldName = self :: getMappingValue ( $ associationMapping, 'indexBy ' ) ;
9699 if (null === ($ typeOfField = $ subMetadata ->getTypeOfField ($ fieldName ))) {
97- $ fieldName = $ subMetadata ->getFieldForColumn ($ associationMapping[ 'indexBy ' ] );
100+ $ fieldName = $ subMetadata ->getFieldForColumn (self :: getMappingValue ( $ associationMapping, 'indexBy ' ) );
98101 // Not a property, maybe a column name?
99102 if (null === ($ typeOfField = $ subMetadata ->getTypeOfField ($ fieldName ))) {
100103 // Maybe the column name is the association join column?
101104 $ associationMapping = $ subMetadata ->getAssociationMapping ($ fieldName );
102105
103106 $ indexProperty = $ subMetadata ->getSingleAssociationReferencedJoinColumnName ($ fieldName );
104- $ subMetadata = $ this ->entityManager ->getClassMetadata ($ associationMapping[ 'targetEntity ' ] );
107+ $ subMetadata = $ this ->entityManager ->getClassMetadata (self :: getMappingValue ( $ associationMapping, 'targetEntity ' ) );
105108
106109 // Not a property, maybe a column name?
107110 if (null === ($ typeOfField = $ subMetadata ->getTypeOfField ($ indexProperty ))) {
@@ -128,7 +131,7 @@ public function getTypes(string $class, string $property, array $context = [])
128131 }
129132
130133 if ($ metadata instanceof ClassMetadata && isset ($ metadata ->embeddedClasses [$ property ])) {
131- return [new Type (Type::BUILTIN_TYPE_OBJECT , false , $ metadata ->embeddedClasses [$ property ][ 'class ' ] )];
134+ return [new Type (Type::BUILTIN_TYPE_OBJECT , false , self :: getMappingValue ( $ metadata ->embeddedClasses [$ property ], 'class ' ) )];
132135 }
133136
134137 if ($ metadata ->hasField ($ property )) {
@@ -140,7 +143,7 @@ public function getTypes(string $class, string $property, array $context = [])
140143
141144 $ nullable = $ metadata instanceof ClassMetadata && $ metadata ->isNullable ($ property );
142145 $ enumType = null ;
143- if (null !== $ enumClass = $ metadata ->getFieldMapping ($ property )[ 'enumType ' ] ?? null ) {
146+ if (null !== $ enumClass = self :: getMappingValue ( $ metadata ->getFieldMapping ($ property ), 'enumType ' ) ?? null ) {
144147 $ enumType = new Type (Type::BUILTIN_TYPE_OBJECT , $ nullable , $ enumClass );
145148 }
146149
@@ -236,17 +239,17 @@ private function getMetadata(string $class): ?ClassMetadata
236239 */
237240 private function isAssociationNullable ($ associationMapping ): bool
238241 {
239- if (isset ($ associationMapping[ ' id ' ]) && $ associationMapping [ 'id ' ] ) {
242+ if (self :: getMappingValue ($ associationMapping, 'id ' ) ) {
240243 return false ;
241244 }
242245
243- if (!isset ($ associationMapping[ 'joinColumns ' ] )) {
246+ if (!self :: getMappingValue ($ associationMapping, 'joinColumns ' )) {
244247 return true ;
245248 }
246249
247- $ joinColumns = $ associationMapping[ 'joinColumns ' ] ;
250+ $ joinColumns = self :: getMappingValue ( $ associationMapping, 'joinColumns ' ) ;
248251 foreach ($ joinColumns as $ joinColumn ) {
249- if (isset ( $ joinColumn [ ' nullable ' ]) && ! $ joinColumn[ 'nullable ' ] ) {
252+ if (false === self :: getMappingValue ( $ joinColumn, 'nullable ' ) ) {
250253 return false ;
251254 }
252255 }
@@ -302,4 +305,13 @@ private function getPhpType(string $doctrineType): ?string
302305
303306 return null ;
304307 }
308+
309+ private static function getMappingValue (array |AssociationMapping |EmbeddedClassMapping |FieldMapping |JoinColumnMapping $ mapping , string $ key ): mixed
310+ {
311+ if ($ mapping instanceof AssociationMapping || $ mapping instanceof EmbeddedClassMapping || $ mapping instanceof FieldMapping || $ mapping instanceof JoinColumnMapping) {
312+ return $ mapping ->$ key ;
313+ }
314+
315+ return $ mapping [$ key ] ?? null ;
316+ }
305317}
0 commit comments