@@ -51,6 +51,7 @@ class DoctrineEntitySniff extends AbstractVariableSniff
51
51
'scale ' => 'integer ' ,
52
52
'unique ' => 'boolean ' ,
53
53
'nullable ' => 'boolean ' ,
54
+ 'enumType ' => 'class ' ,
54
55
'options ' => 'array ' ,
55
56
'columnDefinition ' => 'string ' ,
56
57
],
@@ -719,6 +720,12 @@ protected function inferTypedPropertyColumnAnnotationDefaults(array $attributes,
719
720
case 'string ' :
720
721
$ attributes ['type ' ] = 'string ' ;
721
722
break ;
723
+
724
+ default :
725
+ if ($ this ->soundsLikeClass ($ type )) {
726
+ $ attributes ['type ' ] = 'string ' ;
727
+ $ attributes ['enumType ' ] = $ type . self ::CLASS_SUFFIX ;
728
+ }
722
729
}
723
730
}
724
731
@@ -874,7 +881,7 @@ protected function validateAnnotationAttributeType(string $name, string $attrNam
874
881
break ;
875
882
876
883
case 'class ' :
877
- $ valid = (ucfirst ($ value ) === $ value || $ value === 'self::class ' ) && (
884
+ $ valid = ($ this -> soundsLikeClass ($ value ) || $ value === 'self::class ' ) && (
878
885
(strpos ($ value , "\\" ) !== false )
879
886
|| strpos ($ value , self ::CLASS_SUFFIX , -self ::CLASS_SUFFIX_LENGTH )
880
887
);
@@ -923,6 +930,10 @@ protected function validateAnnotationColumn(string $name, array $attributes): vo
923
930
if (isset ($ attributes ['type ' ])) {
924
931
$ columnType = $ attributes ['type ' ];
925
932
933
+ if (isset ($ attributes ['enumType ' ])) {
934
+ $ columnType = $ this ->getShortClassName ($ attributes ['enumType ' ]);
935
+ }
936
+
926
937
if ($ expectedType = $ this ->suggestType ($ columnType )) {
927
938
if (!$ this ->varType && !$ this ->memberType ) {
928
939
$ error = 'Variable type required for column; expected "%s" ' ;
@@ -1009,7 +1020,15 @@ protected function suggestType(string $type): string
1009
1020
}
1010
1021
}
1011
1022
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 );
1013
1032
}
1014
1033
1015
1034
protected function calculateMappingTypeDynamically (string $ columnType , string $ fallbackToType = 'string ' ): string
@@ -1494,4 +1513,9 @@ private function getLongType(string $shortType): string
1494
1513
{
1495
1514
return self ::SCALAR_TYPES [$ shortType ] ?? $ shortType ;
1496
1515
}
1516
+
1517
+ private function soundsLikeClass (string $ type ): bool
1518
+ {
1519
+ return ucfirst ($ type ) === $ type ;
1520
+ }
1497
1521
}
0 commit comments