@@ -37,6 +37,10 @@ public static function getType(IndexInfo $index)
37
37
$ type = static ::getSpecialType ($ index );
38
38
}
39
39
40
+ if (empty ($ type )) {
41
+ $ type = static ::getDefaultType ($ index );
42
+ }
43
+
40
44
return $ type ;
41
45
}
42
46
@@ -46,52 +50,32 @@ protected static function getCommonType(IndexInfo $index)
46
50
47
51
if ($ index ->isText ()) {
48
52
$ type = "TEXT " ;
49
- }
50
-
51
- if ($ index ->is2dSphere ()) {
53
+ } else if ($ index ->is2dSphere ()) {
52
54
$ type = "2DSPARSE " ;
53
- }
54
-
55
- if ($ index ->isTtl ()) {
55
+ } else if ($ index ->isTtl ()) {
56
56
$ type = "TTL " ;
57
- }
58
-
59
- if ($ index ->isGeoHaystack ()) {
57
+ } else if ($ index ->isGeoHaystack ()) {
60
58
$ type = "GEOHAYSTACK " ;
61
59
}
62
60
63
- if ($ type === "" ) {
64
- $ type = static ::getDefaultType ($ index );
65
- }
66
-
67
61
return $ type ;
68
62
}
69
63
70
64
protected static function getSpecialType (IndexInfo $ index )
71
65
{
72
66
$ type = "" ;
73
67
74
- if ($ index -> isUnique () && ! $ index -> isSparse () && ! static ::checkDescending ($ index )) {
68
+ if (static ::checkUnique ($ index )) {
75
69
$ type = "UNIQUE " ;
76
- }
77
-
78
- if ($ index ->isUnique () && !$ index ->isSparse () && static ::checkDescending ($ index )) {
70
+ } else if (static ::checkUniqueDesc ($ index )) {
79
71
$ type = "UNIQUE_DESC " ;
80
- }
81
-
82
- if ($ index ->isSparse () && !static ::checkDescending ($ index )) {
72
+ } else if (static ::checkSparse ($ index )) {
83
73
$ type = "SPARSE " ;
84
- }
85
-
86
- if ($ index ->isSparse () && $ index ->isUnique () && !static ::checkDescending ($ index )) {
74
+ } else if (static ::checkSparseUnique ($ index )) {
87
75
$ type = "SPARSE_UNIQUE " ;
88
- }
89
-
90
- if ($ index ->isSparse () && $ index ->isUnique () && static ::checkDescending ($ index )) {
76
+ } else if (static ::checkSparseUniqueDesc ($ index )) {
91
77
$ type = "SPARSE_UNIQUE_DESC " ;
92
- }
93
-
94
- if ($ index ->isSparse () && static ::checkDescending ($ index )) {
78
+ } else if (static ::checkSparseDesc ($ index )) {
95
79
$ type = "SPARSE_DESC " ;
96
80
}
97
81
@@ -106,19 +90,45 @@ protected static function getDefaultType(IndexInfo $index)
106
90
107
91
if ($ type == 'asc ' ) {
108
92
return "ASC " ;
109
- }
110
-
111
- if ($ type == 'index ' ) {
93
+ } else if ($ type == 'index ' ) {
112
94
return "INDEX " ;
113
- }
114
-
115
- if ($ type == 'desc ' ) {
95
+ } else if ($ type == 'desc ' ) {
116
96
return "DESC " ;
117
97
}
118
98
119
99
return "" ;
120
100
}
121
101
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
+
122
132
protected static function checkDescending ($ index )
123
133
{
124
134
$ keys = $ index ->getKey ();
0 commit comments