@@ -51,6 +51,7 @@ class DoctrineEntitySniff extends AbstractVariableSniff
5151 'scale ' => 'integer ' ,
5252 'unique ' => 'boolean ' ,
5353 'nullable ' => 'boolean ' ,
54+ 'enumType ' => 'class ' ,
5455 'options ' => 'array ' ,
5556 'columnDefinition ' => 'string ' ,
5657 ],
@@ -719,6 +720,12 @@ protected function inferTypedPropertyColumnAnnotationDefaults(array $attributes,
719720 case 'string ' :
720721 $ attributes ['type ' ] = 'string ' ;
721722 break ;
723+
724+ default :
725+ if ($ this ->soundsLikeClass ($ type )) {
726+ $ attributes ['type ' ] = 'string ' ;
727+ $ attributes ['enumType ' ] = $ type . self ::CLASS_SUFFIX ;
728+ }
722729 }
723730 }
724731
@@ -874,7 +881,7 @@ protected function validateAnnotationAttributeType(string $name, string $attrNam
874881 break ;
875882
876883 case 'class ' :
877- $ valid = (ucfirst ($ value ) === $ value || $ value === 'self::class ' ) && (
884+ $ valid = ($ this -> soundsLikeClass ($ value ) || $ value === 'self::class ' ) && (
878885 (strpos ($ value , "\\" ) !== false )
879886 || strpos ($ value , self ::CLASS_SUFFIX , -self ::CLASS_SUFFIX_LENGTH )
880887 );
@@ -923,6 +930,10 @@ protected function validateAnnotationColumn(string $name, array $attributes): vo
923930 if (isset ($ attributes ['type ' ])) {
924931 $ columnType = $ attributes ['type ' ];
925932
933+ if (isset ($ attributes ['enumType ' ])) {
934+ $ columnType = $ this ->getShortClassName ($ attributes ['enumType ' ]);
935+ }
936+
926937 if ($ expectedType = $ this ->suggestType ($ columnType )) {
927938 if (!$ this ->varType && !$ this ->memberType ) {
928939 $ error = 'Variable type required for column; expected "%s" ' ;
@@ -1009,7 +1020,15 @@ protected function suggestType(string $type): string
10091020 }
10101021 }
10111022
1012- return $ this ->mappingTypes [$ type ] ?? $ this ->calculateMappingTypeDynamically ($ type );
1023+ if (isset ($ this ->mappingTypes [$ type ])) {
1024+ return $ this ->mappingTypes [$ type ];
1025+ }
1026+
1027+ if ($ this ->soundsLikeClass ($ type )) {
1028+ return $ type ;
1029+ }
1030+
1031+ return $ this ->calculateMappingTypeDynamically ($ type );
10131032 }
10141033
10151034 protected function calculateMappingTypeDynamically (string $ columnType , string $ fallbackToType = 'string ' ): string
@@ -1494,4 +1513,9 @@ private function getLongType(string $shortType): string
14941513 {
14951514 return self ::SCALAR_TYPES [$ shortType ] ?? $ shortType ;
14961515 }
1516+
1517+ private function soundsLikeClass (string $ type ): bool
1518+ {
1519+ return ucfirst ($ type ) === $ type ;
1520+ }
14971521}
0 commit comments