Skip to content

Commit 4011548

Browse files
committed
chore(OpenAI): fix issue with phpstan ignores
1 parent d4a7d14 commit 4011548

2 files changed

Lines changed: 24 additions & 16 deletions

File tree

src/Actions/Responses/NamespaceToolObjects.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public static function parse(array $toolItems): array
2626
fn (array $tool): FunctionTool|CustomTool => match ($tool['type']) {
2727
'function' => FunctionTool::from($tool),
2828
'custom' => CustomTool::from($tool),
29-
/** @phpstan-ignore-next-line */
30-
default => throw new \InvalidArgumentException("Unknown tool type: {$tool['type']}"),
3129
},
3230
$toolItems,
3331
);

src/Actions/Responses/ToolObjects.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,19 @@
1616
use OpenAI\Responses\Responses\Tool\WebSearchTool;
1717

1818
/**
19-
* @phpstan-type ResponseToolObjectTypes array<int, array{type: string}>
20-
* @phpstan-type ResponseToolObjectReturnType array<int, ComputerUseTool|FileSearchTool|FunctionTool|WebSearchTool|ImageGenerationTool|RemoteMcpTool|CodeInterpreterTool|ToolSearchTool|NamespaceTool|CustomTool>
19+
* @phpstan-import-type CodeInterpreterToolType from CodeInterpreterTool
20+
* @phpstan-import-type ComputerUseToolType from ComputerUseTool
21+
* @phpstan-import-type CustomToolType from CustomTool
22+
* @phpstan-import-type FileSearchToolType from FileSearchTool
23+
* @phpstan-import-type FunctionToolType from FunctionTool
24+
* @phpstan-import-type ImageGenerationToolType from ImageGenerationTool
25+
* @phpstan-import-type NamespaceToolType from NamespaceTool
26+
* @phpstan-import-type RemoteMcpToolType from RemoteMcpTool
27+
* @phpstan-import-type ToolSearchToolType from ToolSearchTool
28+
* @phpstan-import-type WebSearchToolType from WebSearchTool
29+
*
30+
* @phpstan-type ResponseToolObjectTypes array<int, CodeInterpreterToolType|ComputerUseToolType|CustomToolType|FileSearchToolType|FunctionToolType|ImageGenerationToolType|NamespaceToolType|RemoteMcpToolType|ToolSearchToolType|WebSearchToolType>
31+
* @phpstan-type ResponseToolObjectReturnType array<int, CodeInterpreterTool|ComputerUseTool|CustomTool|FileSearchTool|FunctionTool|ImageGenerationTool|NamespaceTool|RemoteMcpTool|ToolSearchTool|WebSearchTool>
2132
*/
2233
final class ToolObjects
2334
{
@@ -28,18 +39,17 @@ final class ToolObjects
2839
public static function parse(array $toolItems): array
2940
{
3041
return array_map(
31-
fn (array $tool): ComputerUseTool|FileSearchTool|FunctionTool|WebSearchTool|ImageGenerationTool|RemoteMcpTool|CodeInterpreterTool|ToolSearchTool|NamespaceTool|CustomTool => match ($tool['type']) {
32-
'file_search' => FileSearchTool::from($tool), // @phpstan-ignore-line
33-
'web_search', 'web_search_preview', 'web_search_preview_2025_03_11' => WebSearchTool::from($tool), // @phpstan-ignore-line
34-
'function' => FunctionTool::from($tool), // @phpstan-ignore-line
35-
'computer_use_preview' => ComputerUseTool::from($tool), // @phpstan-ignore-line
36-
'image_generation' => ImageGenerationTool::from($tool), // @phpstan-ignore-line
37-
'mcp' => RemoteMcpTool::from($tool), // @phpstan-ignore-line
38-
'code_interpreter' => CodeInterpreterTool::from($tool), // @phpstan-ignore-line
39-
'tool_search' => ToolSearchTool::from($tool), // @phpstan-ignore-line
40-
'namespace' => NamespaceTool::from($tool), // @phpstan-ignore-line
41-
'custom' => CustomTool::from($tool), // @phpstan-ignore-line
42-
default => throw new \InvalidArgumentException("Unknown tool type: {$tool['type']}"),
42+
fn (array $tool): CodeInterpreterTool|ComputerUseTool|CustomTool|FileSearchTool|FunctionTool|ImageGenerationTool|NamespaceTool|RemoteMcpTool|ToolSearchTool|WebSearchTool => match ($tool['type']) {
43+
'file_search' => FileSearchTool::from($tool),
44+
'web_search', 'web_search_preview', 'web_search_preview_2025_03_11' => WebSearchTool::from($tool),
45+
'function' => FunctionTool::from($tool),
46+
'computer_use_preview' => ComputerUseTool::from($tool),
47+
'image_generation' => ImageGenerationTool::from($tool),
48+
'mcp' => RemoteMcpTool::from($tool),
49+
'code_interpreter' => CodeInterpreterTool::from($tool),
50+
'tool_search' => ToolSearchTool::from($tool),
51+
'namespace' => NamespaceTool::from($tool),
52+
'custom' => CustomTool::from($tool),
4353
},
4454
$toolItems,
4555
);

0 commit comments

Comments
 (0)