@@ -90,77 +90,32 @@ public static function anyOf(string ...$types): Constraint
90
90
91
91
private function doMatches ($ other ): bool
92
92
{
93
- switch ($ this ->type ) {
94
- case 'double ' :
95
- return is_float ($ other );
96
-
97
- case 'string ' :
98
- return is_string ($ other );
99
-
100
- case 'object ' :
101
- return self ::isObject ($ other );
102
-
103
- case 'array ' :
104
- return self ::isArray ($ other );
105
-
106
- case 'binData ' :
107
- return $ other instanceof BinaryInterface;
108
-
109
- case 'undefined ' :
110
- return $ other instanceof Undefined;
111
-
112
- case 'objectId ' :
113
- return $ other instanceof ObjectIdInterface;
114
-
115
- case 'bool ' :
116
- return is_bool ($ other );
117
-
118
- case 'date ' :
119
- return $ other instanceof UTCDateTimeInterface;
120
-
121
- case 'null ' :
122
- return $ other === null ;
123
-
124
- case 'regex ' :
125
- return $ other instanceof RegexInterface;
126
-
127
- case 'dbPointer ' :
128
- return $ other instanceof DBPointer;
129
-
130
- case 'javascript ' :
131
- return $ other instanceof JavascriptInterface && $ other ->getScope () === null ;
132
-
133
- case 'symbol ' :
134
- return $ other instanceof Symbol;
135
-
136
- case 'javascriptWithScope ' :
137
- return $ other instanceof JavascriptInterface && $ other ->getScope () !== null ;
138
-
139
- case 'int ' :
140
- return is_int ($ other );
141
-
142
- case 'timestamp ' :
143
- return $ other instanceof TimestampInterface;
144
-
145
- case 'long ' :
146
- return is_int ($ other ) || $ other instanceof Int64;
147
-
148
- case 'decimal ' :
149
- return $ other instanceof Decimal128Interface;
150
-
151
- case 'minKey ' :
152
- return $ other instanceof MinKeyInterface;
153
-
154
- case 'maxKey ' :
155
- return $ other instanceof MaxKeyInterface;
156
-
157
- case 'number ' :
158
- return is_int ($ other ) || $ other instanceof Int64 || is_float ($ other ) || $ other instanceof Decimal128Interface;
159
-
160
- default :
161
- // This should already have been caught in the constructor
162
- throw new LogicException ('Unsupported type: ' . $ this ->type );
163
- }
93
+ return match ($ this ->type ) {
94
+ 'double ' => is_float ($ other ),
95
+ 'string ' => is_string ($ other ),
96
+ 'object ' => self ::isObject ($ other ),
97
+ 'array ' => self ::isArray ($ other ),
98
+ 'binData ' => $ other instanceof BinaryInterface,
99
+ 'undefined ' => $ other instanceof Undefined,
100
+ 'objectId ' => $ other instanceof ObjectIdInterface,
101
+ 'bool ' => is_bool ($ other ),
102
+ 'date ' => $ other instanceof UTCDateTimeInterface,
103
+ 'null ' => $ other === null ,
104
+ 'regex ' => $ other instanceof RegexInterface,
105
+ 'dbPointer ' => $ other instanceof DBPointer,
106
+ 'javascript ' => $ other instanceof JavascriptInterface && $ other ->getScope () === null ,
107
+ 'symbol ' => $ other instanceof Symbol,
108
+ 'javascriptWithScope ' => $ other instanceof JavascriptInterface && $ other ->getScope () !== null ,
109
+ 'int ' => is_int ($ other ),
110
+ 'timestamp ' => $ other instanceof TimestampInterface,
111
+ 'long ' => is_int ($ other ) || $ other instanceof Int64,
112
+ 'decimal ' => $ other instanceof Decimal128Interface,
113
+ 'minKey ' => $ other instanceof MinKeyInterface,
114
+ 'maxKey ' => $ other instanceof MaxKeyInterface,
115
+ 'number ' => is_int ($ other ) || $ other instanceof Int64 || is_float ($ other ) || $ other instanceof Decimal128Interface,
116
+ // This should already have been caught in the constructor
117
+ default => throw new LogicException ('Unsupported type: ' . $ this ->type ),
118
+ };
164
119
}
165
120
166
121
private function doToString (): string
0 commit comments