@@ -38,27 +38,14 @@ public function encode(mixed $value): stdClass
38
38
throw UnsupportedValueException::invalidEncodableValue ($ value );
39
39
}
40
40
41
- switch ($ value ::ENCODE ) {
42
- case Encode::Single:
43
- return $ this ->encodeAsSingle ($ value );
44
-
45
- case Encode::Array:
46
- return $ this ->encodeAsArray ($ value );
47
-
48
- case Encode::Object:
49
- case Encode::FlatObject:
50
- return $ this ->encodeAsObject ($ value );
51
-
52
- case Encode::DollarObject:
53
- return $ this ->encodeAsDollarObject ($ value );
54
-
55
- case Encode::Group:
56
- assert ($ value instanceof GroupStage);
57
-
58
- return $ this ->encodeAsGroup ($ value );
59
- }
60
-
61
- throw new LogicException (sprintf ('Class "%s" does not have a valid ENCODE constant. ' , $ value ::class));
41
+ return match ($ value ::ENCODE ) {
42
+ Encode::Single => $ this ->encodeAsSingle ($ value ),
43
+ Encode::Array => $ this ->encodeAsArray ($ value ),
44
+ Encode::Object, Encode::FlatObject => $ this ->encodeAsObject ($ value ),
45
+ Encode::DollarObject => $ this ->encodeAsDollarObject ($ value ),
46
+ Encode::Group => $ this ->encodeAsGroup ($ value ),
47
+ default => throw new LogicException (sprintf ('Class "%s" does not have a valid ENCODE constant. ' , $ value ::class)),
48
+ };
62
49
}
63
50
64
51
/**
@@ -111,8 +98,10 @@ private function encodeAsDollarObject(OperatorInterface $value): stdClass
111
98
/**
112
99
* $group stage have a specific encoding because the _id argument is required and others are variadic
113
100
*/
114
- private function encodeAsGroup (GroupStage $ value ): stdClass
101
+ private function encodeAsGroup (OperatorInterface $ value ): stdClass
115
102
{
103
+ assert ($ value instanceof GroupStage);
104
+
116
105
$ result = new stdClass ();
117
106
$ result ->_id = $ this ->recursiveEncode ($ value ->_id );
118
107
0 commit comments