@@ -37,6 +37,10 @@ public static function getType(IndexInfo $index)
3737 $ type = static ::getSpecialType ($ index );
3838 }
3939
40+ if (empty ($ type )) {
41+ $ type = static ::getDefaultType ($ index );
42+ }
43+
4044 return $ type ;
4145 }
4246
@@ -46,52 +50,32 @@ protected static function getCommonType(IndexInfo $index)
4650
4751 if ($ index ->isText ()) {
4852 $ type = "TEXT " ;
49- }
50-
51- if ($ index ->is2dSphere ()) {
53+ } else if ($ index ->is2dSphere ()) {
5254 $ type = "2DSPARSE " ;
53- }
54-
55- if ($ index ->isTtl ()) {
55+ } else if ($ index ->isTtl ()) {
5656 $ type = "TTL " ;
57- }
58-
59- if ($ index ->isGeoHaystack ()) {
57+ } else if ($ index ->isGeoHaystack ()) {
6058 $ type = "GEOHAYSTACK " ;
6159 }
6260
63- if ($ type === "" ) {
64- $ type = static ::getDefaultType ($ index );
65- }
66-
6761 return $ type ;
6862 }
6963
7064 protected static function getSpecialType (IndexInfo $ index )
7165 {
7266 $ type = "" ;
7367
74- if ($ index -> isUnique () && ! $ index -> isSparse () && ! static ::checkDescending ($ index )) {
68+ if (static ::checkUnique ($ index )) {
7569 $ type = "UNIQUE " ;
76- }
77-
78- if ($ index ->isUnique () && !$ index ->isSparse () && static ::checkDescending ($ index )) {
70+ } else if (static ::checkUniqueDesc ($ index )) {
7971 $ type = "UNIQUE_DESC " ;
80- }
81-
82- if ($ index ->isSparse () && !static ::checkDescending ($ index )) {
72+ } else if (static ::checkSparse ($ index )) {
8373 $ type = "SPARSE " ;
84- }
85-
86- if ($ index ->isSparse () && $ index ->isUnique () && !static ::checkDescending ($ index )) {
74+ } else if (static ::checkSparseUnique ($ index )) {
8775 $ type = "SPARSE_UNIQUE " ;
88- }
89-
90- if ($ index ->isSparse () && $ index ->isUnique () && static ::checkDescending ($ index )) {
76+ } else if (static ::checkSparseUniqueDesc ($ index )) {
9177 $ type = "SPARSE_UNIQUE_DESC " ;
92- }
93-
94- if ($ index ->isSparse () && static ::checkDescending ($ index )) {
78+ } else if (static ::checkSparseDesc ($ index )) {
9579 $ type = "SPARSE_DESC " ;
9680 }
9781
@@ -106,19 +90,45 @@ protected static function getDefaultType(IndexInfo $index)
10690
10791 if ($ type == 'asc ' ) {
10892 return "ASC " ;
109- }
110-
111- if ($ type == 'index ' ) {
93+ } else if ($ type == 'index ' ) {
11294 return "INDEX " ;
113- }
114-
115- if ($ type == 'desc ' ) {
95+ } else if ($ type == 'desc ' ) {
11696 return "DESC " ;
11797 }
11898
11999 return "" ;
120100 }
121101
102+ protected static function checkUnique ($ index )
103+ {
104+ return $ index ->isUnique () && !$ index ->isSparse () && !static ::checkDescending ($ index ) ? true : false ;
105+ }
106+
107+ protected static function checkUniqueDesc ($ index )
108+ {
109+ return $ index ->isUnique () && !$ index ->isSparse () && static ::checkDescending ($ index ) ? true : false ;
110+ }
111+
112+ protected static function checkSparse ($ index )
113+ {
114+ return $ index ->isSparse () && !static ::checkDescending ($ index ) ? true : false ;
115+ }
116+
117+ protected static function checkSparseUnique ($ index )
118+ {
119+ return $ index ->isSparse () && $ index ->isUnique () && !static ::checkDescending ($ index ) ? true : false ;
120+ }
121+
122+ protected static function checkSparseUniqueDesc ($ index )
123+ {
124+ return $ index ->isSparse () && $ index ->isUnique () && static ::checkDescending ($ index ) ? true : false ;
125+ }
126+
127+ protected static function checkSparseDesc ($ index )
128+ {
129+ return $ index ->isSparse () && static ::checkDescending ($ index ) ? true : false ;
130+ }
131+
122132 protected static function checkDescending ($ index )
123133 {
124134 $ keys = $ index ->getKey ();
0 commit comments