Skip to content

Commit 03ea521

Browse files
author
klapaudius
committed
Refactor schema processing for array properties.
Extracted logic for handling array schema display into a dedicated `getArraySchemaDisplay` method to improve code clarity and maintainability. Updated conditionals for better null safety and simplified array checks.
1 parent 3a1c8b1 commit 03ea521

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/Command/TestMcpToolCommand.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function displaySchema(ToolInterface $tool): void
187187
protected function getSchemaDisplayMessages(array $schema, string $indent = ''): array
188188
{
189189
$messages = [];
190-
if (isset($schema['properties']) && is_array($schema['properties'])) {
190+
if (is_array($schema['properties'] ?? null)) {
191191
foreach ($schema['properties'] as $propName => $propSchema) {
192192
$type = $propSchema['type'] ?? 'any';
193193
$description = $propSchema['description'] ?? '';
@@ -204,19 +204,24 @@ protected function getSchemaDisplayMessages(array $schema, string $indent = ''):
204204

205205
// If this is an array with items
206206
if ($type === 'array' && isset($propSchema['items'])) {
207-
$itemType = $propSchema['items']['type'] ?? 'any';
208-
$messages[] = "{$indent} Items: {$itemType}";
209-
if (isset($propSchema['items']['properties'])) {
210-
$messages[] = "{$indent} Item Properties:";
211-
$messages = array_merge($messages, $this->getSchemaDisplayMessages($propSchema['items'], $indent.' '));
212-
}
207+
$this->getArraySchemaDisplay($propSchema, $indent, $messages);
213208
}
214209
}
215210
}
216211

217212
return $messages;
218213
}
219214

215+
private function getArraySchemaDisplay(mixed $propSchema, string $indent, array &$messages): void
216+
{
217+
$itemType = $propSchema['items']['type'] ?? 'any';
218+
$messages[] = "{$indent} Items: {$itemType}";
219+
if (isset($propSchema['items']['properties'])) {
220+
$messages[] = "{$indent} Item Properties:";
221+
$messages = array_merge($messages, $this->getSchemaDisplayMessages($propSchema['items'], $indent . ' '));
222+
}
223+
}
224+
220225
public function getInputDataFromOption(): ?array
221226
{
222227
// If input is provided as an option, use that

0 commit comments

Comments
 (0)