@@ -39,27 +39,27 @@ public static function serializeItem(mixed $value, ?object $parameters = null):
3939 }
4040
4141 /**
42- * @param iterable<TupleInterface|array{ mixed, object}> $value
42+ * @param iterable<TupleInterface|list{TupleInterface|list{ mixed, object} , object}> $value
4343 */
4444 public static function serializeList (iterable $ value ): string
4545 {
4646 if ($ value instanceof \Traversable) {
47- // @todo Checking for Traversable is not required for PHP ^8.2.0.
4847 $ value = iterator_to_array ($ value );
4948 }
5049
5150 $ returnValue = array_map (function ($ item ) {
52- if ($ item instanceof TupleInterface) {
53- $ itemValue = $ item ->getValue ();
54- $ itemParameters = $ item ->getParameters ();
55- } elseif (is_array ($ item ) && count ($ item ) === 2 ) {
51+ if (is_array ($ item ) && count ($ item ) === 2 ) {
5652 $ itemValue = $ item [0 ];
5753 $ itemParameters = $ item [1 ];
54+ } elseif ($ item instanceof TupleInterface) {
55+ $ itemValue = $ item ->getValue ();
56+ $ itemParameters = $ item ->getParameters ();
5857 } else {
5958 throw new SerializeException ("Invalid item in list " );
6059 }
6160
6261 if (is_array ($ itemValue )) {
62+ /** @var array<TupleInterface|list{mixed, object}> $itemValue */
6363 return self ::serializeInnerList ($ itemValue , $ itemParameters );
6464 } else {
6565 return self ::serializeItem ($ itemValue , $ itemParameters );
@@ -73,8 +73,6 @@ public static function serializeList(iterable $value): string
7373 * Serialize an object as a dictionary.
7474 *
7575 * Either a Traversable object can be provided, or the public properties of the object will be extracted.
76- *
77- * @param Dictionary|object $value
7876 */
7977 public static function serializeDictionary (object $ value ): string
8078 {
@@ -84,6 +82,10 @@ public static function serializeDictionary(object $value): string
8482 $ value = get_object_vars ($ value );
8583 }
8684
85+ /**
86+ * @var string $key
87+ * @var TupleInterface|list{TupleInterface|list{mixed,object}, object} $item
88+ */
8789 foreach ($ value as $ key => $ item ) {
8890 if (!empty ($ returnValue )) {
8991 $ returnValue .= ', ' ;
@@ -102,6 +104,7 @@ public static function serializeDictionary(object $value): string
102104 if ($ itemValue === true ) {
103105 $ returnValue .= self ::serializeParameters ($ itemParameters );
104106 } elseif (is_array ($ itemValue )) {
107+ /** @var array<TupleInterface|list{mixed, object}> $itemValue */
105108 $ returnValue .= '= ' . self ::serializeInnerList ($ itemValue , $ itemParameters );
106109 } else {
107110 $ returnValue .= '= ' . self ::serializeItem ($ itemValue , $ itemParameters );
@@ -189,7 +192,7 @@ private static function serializeDecimal(float $value): string
189192
190193 // Casting to a string loses a digit on long numbers, but is preserved
191194 // by json_encode (e.g. 111111111111.111).
192- /** @var string $result */
195+ /** @var non-empty- string $result */
193196 $ result = json_encode (round ($ value , 3 , PHP_ROUND_HALF_EVEN ));
194197
195198 if (!str_contains ($ result , '. ' )) {
@@ -250,6 +253,7 @@ private static function serializeParameters(object $value): string
250253 $ value = get_object_vars ($ value );
251254 }
252255
256+ /** @var string $key */
253257 foreach ($ value as $ key => $ item ) {
254258 $ returnValue .= '; ' . self ::serializeKey ($ key );
255259
0 commit comments