Skip to content

Commit 0e824c4

Browse files
committed
review comments
1 parent 13d2386 commit 0e824c4

File tree

1 file changed

+7
-29
lines changed

1 file changed

+7
-29
lines changed

src/SDK/Language/Kotlin.php

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -283,21 +283,10 @@ public function getParamExample(array $param, string $lang = 'kotlin'): string
283283
* Generate Kotlin-style map initialization
284284
*
285285
* @param array $data
286-
* @return string
287-
*/
288-
protected function getKotlinMapExample(array $data): string
289-
{
290-
return $this->getKotlinMapExampleRecursive($data, 0);
291-
}
292-
293-
/**
294-
* Recursive helper for generating Kotlin mapOf() with proper indentation
295-
*
296-
* @param array $data
297286
* @param int $indentLevel Indentation level for nested maps
298287
* @return string
299288
*/
300-
private function getKotlinMapExampleRecursive(array $data, int $indentLevel): string
289+
protected function getKotlinMapExample(array $data, int $indentLevel = 0): string
301290
{
302291
$mapEntries = [];
303292
$baseIndent = str_repeat(' ', $indentLevel + 2);
@@ -312,9 +301,9 @@ private function getKotlinMapExampleRecursive(array $data, int $indentLevel): st
312301
$formattedValue = 'null';
313302
} elseif (is_array($value)) {
314303
// Check if it's an associative array (object) or indexed array
315-
$isObject = array_keys($value) !== range(0, count($value) - 1);
304+
$isObject = !array_is_list($value);
316305
if ($isObject) {
317-
$formattedValue = $this->getKotlinMapExampleRecursive($value, $indentLevel + 1);
306+
$formattedValue = $this->getKotlinMapExample($value, $indentLevel + 1);
318307
} else {
319308
$formattedValue = $this->getArrayExample(json_encode($value), 'kotlin');
320309
}
@@ -336,21 +325,10 @@ private function getKotlinMapExampleRecursive(array $data, int $indentLevel): st
336325
* Generate Java-style map initialization using Map.of()
337326
*
338327
* @param array $data
339-
* @return string
340-
*/
341-
protected function getJavaMapExample(array $data): string
342-
{
343-
return $this->getJavaMapExampleRecursive($data, 0);
344-
}
345-
346-
/**
347-
* Recursive helper for generating Java Map.of() with proper indentation
348-
*
349-
* @param array $data
350328
* @param int $indentLevel Indentation level for nested maps
351329
* @return string
352330
*/
353-
private function getJavaMapExampleRecursive(array $data, int $indentLevel): string
331+
protected function getJavaMapExample(array $data, int $indentLevel = 0): string
354332
{
355333
$mapEntries = [];
356334
$baseIndent = str_repeat(' ', $indentLevel + 2);
@@ -365,9 +343,9 @@ private function getJavaMapExampleRecursive(array $data, int $indentLevel): stri
365343
$formattedValue = 'null';
366344
} elseif (is_array($value)) {
367345
// Check if it's an associative array (object) or indexed array
368-
$isObject = array_keys($value) !== range(0, count($value) - 1);
346+
$isObject = !array_is_list($value);
369347
if ($isObject) {
370-
$formattedValue = $this->getJavaMapExampleRecursive($value, $indentLevel + 1);
348+
$formattedValue = $this->getJavaMapExample($value, $indentLevel + 1);
371349
} else {
372350
$formattedValue = $this->getArrayExample(json_encode($value), 'java');
373351
}
@@ -401,7 +379,7 @@ protected function getArrayExample(string $example, string $lang = 'kotlin'): st
401379
foreach ($decoded as $item) {
402380
if (is_array($item)) {
403381
// Check if it's an associative array (object) or indexed array (nested array)
404-
$isObject = array_keys($item) !== range(0, count($item) - 1);
382+
$isObject = !array_is_list($item);
405383

406384
if ($isObject) {
407385
// It's an object/map, convert it

0 commit comments

Comments
 (0)