Skip to content

Commit 9902d29

Browse files
committed
review comments
1 parent 13d2386 commit 9902d29

File tree

16 files changed

+37
-44
lines changed

16 files changed

+37
-44
lines changed

src/SDK/Language.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,10 @@ abstract public function getParamDefault(array $param): string;
7070

7171
/**
7272
* @param array $param
73+
* @param string $lang Optional language variant (for multi-language SDKs)
7374
* @return string
7475
*/
75-
abstract public function getParamExample(array $param): string;
76+
abstract public function getParamExample(array $param, string $lang = ''): string;
7677

7778
/**
7879
* @param string $key

src/SDK/Language/CLI.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,10 @@ public function getTypeName(array $parameter, array $spec = []): string
377377

378378
/**
379379
* @param array $param
380+
* @param string $lang
380381
* @return string
381382
*/
382-
public function getParamExample(array $param): string
383+
public function getParamExample(array $param, string $lang = ''): string
383384
{
384385
$type = $param['type'] ?? '';
385386
$example = $param['example'] ?? '';

src/SDK/Language/Dart.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,10 @@ public function getParamDefault(array $param): string
234234

235235
/**
236236
* @param array $param
237+
* @param string $lang
237238
* @return string
238239
*/
239-
public function getParamExample(array $param): string
240+
public function getParamExample(array $param, string $lang = ''): string
240241
{
241242
$type = $param['type'] ?? '';
242243
$example = $param['example'] ?? '';

src/SDK/Language/Deno.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,10 @@ public function getTypeName(array $parameter, array $spec = []): string
181181

182182
/**
183183
* @param array $param
184+
* @param string $lang
184185
* @return string
185186
*/
186-
public function getParamExample(array $param): string
187+
public function getParamExample(array $param, string $lang = ''): string
187188
{
188189
$type = $param['type'] ?? '';
189190
$example = $param['example'] ?? '';

src/SDK/Language/DotNet.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,10 @@ public function getParamDefault(array $param): string
261261

262262
/**
263263
* @param array $param
264+
* @param string $lang
264265
* @return string
265266
*/
266-
public function getParamExample(array $param): string
267+
public function getParamExample(array $param, string $lang = ''): string
267268
{
268269
$type = $param['type'] ?? '';
269270
$example = $param['example'] ?? '';

src/SDK/Language/Go.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,10 @@ public function getParamDefault(array $param): string
238238

239239
/**
240240
* @param array $param
241+
* @param string $lang
241242
* @return string
242243
*/
243-
public function getParamExample(array $param): string
244+
public function getParamExample(array $param, string $lang = ''): string
244245
{
245246
$type = $param['type'] ?? '';
246247
$example = $param['example'] ?? '';

src/SDK/Language/GraphQL.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,10 @@ public function getParamDefault(array $param): string
128128

129129
/**
130130
* @param array $param
131+
* @param string $lang
131132
* @return string
132133
*/
133-
public function getParamExample(array $param): string
134+
public function getParamExample(array $param, string $lang = ''): string
134135
{
135136
$type = $param['type'] ?? '';
136137
$example = $param['example'] ?? '';

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

src/SDK/Language/Node.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ public function getReturn(array $method, array $spec): string
140140

141141
/**
142142
* @param array $param
143+
* @param string $lang
143144
* @return string
144145
*/
145-
public function getParamExample(array $param): string
146+
public function getParamExample(array $param, string $lang = ''): string
146147
{
147148
$type = $param['type'] ?? '';
148149
$example = $param['example'] ?? '';

src/SDK/Language/PHP.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,10 @@ public function getParamDefault(array $param): string
355355

356356
/**
357357
* @param array $param
358+
* @param string $lang
358359
* @return string
359360
*/
360-
public function getParamExample(array $param): string
361+
public function getParamExample(array $param, string $lang = ''): string
361362
{
362363
$type = $param['type'] ?? '';
363364
$example = $param['example'] ?? '';

0 commit comments

Comments
 (0)