Skip to content

Commit dd263ac

Browse files
committed
Fixed all PHPStan Errors and all other tests Pass 100%
1 parent 63c8c7c commit dd263ac

File tree

4 files changed

+46
-35
lines changed

4 files changed

+46
-35
lines changed

src/Responses/Responses/CreateResponse.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ final class CreateResponse implements ResponseContract, ResponseHasMetaInformati
2424
use Fakeable;
2525
use HasMetaInformation;
2626

27+
/**
28+
* @param array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}> $output
29+
* @param array<mixed> $reasoning
30+
* @param array{format: array{type: string}} $text
31+
* @param array<mixed> $tools
32+
* @param array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int} $usage
33+
*/
2734
private function __construct(
2835
public readonly string $id,
2936
public readonly string $object,
@@ -45,16 +52,13 @@ private function __construct(
4552
public readonly array $tools,
4653
public readonly ?float $topP,
4754
public readonly string $truncation,
55+
public readonly array $usage,
4856
public readonly ?string $user,
49-
public array $metadata,
50-
public readonly CreateResponseUsage $usage,
5157
private readonly MetaInformation $meta,
5258
) {}
5359

5460
/**
55-
* Acts as static factory, and returns a new Response instance.
56-
*
57-
* @param array{id: string, object: string, created_at: int, status: string, error: ?object, incomplete_details: object|null, instructions: ?string, max_output_tokens: ?int, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: ?string, reasoning: array<mixed>, store: bool, temperature: ?float, text: array{format: array{type: string}}, tool_choice: string, tools: array<mixed>, top_p: ?float, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: ?string, metadata?: array<string, string>} $attributes
61+
* @param array{id: string, object: string, created_at: int, status: string, error: object|null, incomplete_details: object|null, instructions: string|null, max_output_tokens: int|null, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: string|null, reasoning: array<mixed>, store: bool, temperature: float|null, text: array{format: array{type: string}}, tool_choice: string, tools: array<mixed>, top_p: float|null, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: string|null, metadata?: array<string, string>} $attributes
5862
*/
5963
public static function from(array $attributes, MetaInformation $meta): self
6064
{
@@ -79,15 +83,14 @@ public static function from(array $attributes, MetaInformation $meta): self
7983
$attributes['tools'],
8084
$attributes['top_p'],
8185
$attributes['truncation'],
82-
$attributes['user'],
83-
$attributes['metadata'] ?? [],
84-
CreateResponseUsage::from($attributes['usage']),
86+
$attributes['usage'],
87+
$attributes['user'] ?? null,
8588
$meta,
8689
);
8790
}
8891

8992
/**
90-
* {@inheritDoc}
93+
* @return array{id: string, object: string, created_at: int, status: string, error: object|null, incomplete_details: object|null, instructions: string|null, max_output_tokens: int|null, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: string|null, reasoning: array<mixed>, store: bool, temperature: float|null, text: array{format: array{type: string}}, tool_choice: string, tools: array<mixed>, top_p: float|null, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: string|null, metadata?: array<string, string>}
9194
*/
9295
public function toArray(): array
9396
{
@@ -112,9 +115,8 @@ public function toArray(): array
112115
'tools' => $this->tools,
113116
'top_p' => $this->topP,
114117
'truncation' => $this->truncation,
118+
'usage' => $this->usage,
115119
'user' => $this->user,
116-
'metadata' => $this->metadata,
117-
'usage' => $this->usage->toArray(),
118120
];
119121
}
120122
}

src/Responses/Responses/ListInputItems.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ final class ListInputItems implements ResponseContract, ResponseHasMetaInformati
2424
use Fakeable;
2525
use HasMetaInformation;
2626

27+
/**
28+
* @param array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}> $data
29+
*/
2730
private function __construct(
2831
public readonly string $object,
2932
public readonly array $data,
@@ -40,14 +43,9 @@ private function __construct(
4043
*/
4144
public static function from(array $attributes, MetaInformation $meta): self
4245
{
43-
$data = array_map(fn (array $result): ResponseObject => ResponseObject::from(
44-
$result,
45-
$meta,
46-
), $attributes['data']);
47-
4846
return new self(
4947
$attributes['object'],
50-
$data,
48+
$attributes['data'],
5149
$attributes['first_id'],
5250
$attributes['last_id'],
5351
$attributes['has_more'],
@@ -62,10 +60,7 @@ public function toArray(): array
6260
{
6361
return [
6462
'object' => $this->object,
65-
'data' => array_map(
66-
static fn (ResponseObject $result): array => $result->toArray(),
67-
$this->data,
68-
),
63+
'data' => $this->data,
6964
'first_id' => $this->firstId,
7065
'last_id' => $this->lastId,
7166
'has_more' => $this->hasMore,

src/Responses/Responses/ResponseObject.php

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use OpenAI\Testing\Responses\Concerns\Fakeable;
1313

1414
/**
15-
* @implements ResponseContract<array{id: string, object: string, created_at: int, status: string, error: object|null, incomplete_details: object|null, instructions: string|null, max_output_tokens: int|null, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: string|null, reasoning: array<mixed>, store: bool, temperature: float|null, text: object{format: array{type: string}}, tool_choice: string, tools: array<mixed>, top_p: float|null, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: string|null, metadata?: array<string, string>}>
15+
* @implements ResponseContract<array{id: string, object: string, created_at: int, status: string, error: object|null, incomplete_details: object|null, instructions: string|null, max_output_tokens: int|null, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: string|null, reasoning: array<mixed>, store: bool, temperature: float|null, text: array{format: array{type: string}}, tool_choice: string, tools: array<mixed>, top_p: float|null, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: string|null, metadata?: array<string, string>}>
1616
*/
1717
final class ResponseObject implements ResponseContract, ResponseHasMetaInformationContract
1818
{
@@ -24,12 +24,19 @@ final class ResponseObject implements ResponseContract, ResponseHasMetaInformati
2424
use Fakeable;
2525
use HasMetaInformation;
2626

27+
/**
28+
* @param array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}> $output
29+
* @param array<string, mixed> $reasoning
30+
* @param array{format: array{type: string}} $text
31+
* @param array<mixed> $tools
32+
* @param array<string, string> $metadata
33+
*/
2734
private function __construct(
2835
public readonly string $id,
2936
public readonly string $object,
3037
public readonly int $createdAt,
3138
public readonly string $status,
32-
public readonly object $error,
39+
public readonly ?object $error,
3340
public readonly ?object $incompleteDetails,
3441
public readonly ?string $instructions,
3542
public readonly ?int $maxOutputTokens,
@@ -47,12 +54,13 @@ private function __construct(
4754
public readonly string $truncation,
4855
public readonly ?string $user,
4956
public array $metadata,
50-
public readonly CreateResponseUsage $usage,
57+
/** @var array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int} */
58+
public readonly array $usage,
5159
private readonly MetaInformation $meta,
5260
) {}
5361

5462
/**
55-
* @param array{id: string, object: string, created_at: int, status: string, error: ?object, incomplete_details: object|null, instructions: ?string, max_output_tokens: ?int, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: ?string, reasoning: array<mixed>, store: bool, temperature: ?float, text: array{format: array{type: string}}, tool_choice: string, tools: array<mixed>, top_p: ?float, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: ?string, metadata?: array<string, string>} $attributes
63+
* @param array{id: string, object: string, created_at: int, status: string, error: object|null, incomplete_details: object|null, instructions: string|null, max_output_tokens: int|null, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: string|null, reasoning: array<mixed>, store: bool, temperature: float|null, text: array{format: array{type: string}}, tool_choice: string, tools: array<mixed>, top_p: float|null, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: string|null, metadata?: array<string, string>} $attributes
5664
*/
5765
public static function from(array $attributes, MetaInformation $meta): self
5866
{
@@ -79,13 +87,13 @@ public static function from(array $attributes, MetaInformation $meta): self
7987
$attributes['truncation'],
8088
$attributes['user'],
8189
$attributes['metadata'] ?? [],
82-
CreateResponseUsage::from($attributes['usage']),
90+
$attributes['usage'],
8391
$meta,
8492
);
8593
}
8694

8795
/**
88-
* {@inheritDoc}
96+
* @return array{id: string, object: string, created_at: int, status: string, error: object|null, incomplete_details: object|null, instructions: string|null, max_output_tokens: int|null, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: string|null, reasoning: array<mixed>, store: bool, temperature: float|null, text: array{format: array{type: string}}, tool_choice: string, tools: array<mixed>, top_p: float|null, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: string|null, metadata: array<string, string>}
8997
*/
9098
public function toArray(): array
9199
{
@@ -112,7 +120,7 @@ public function toArray(): array
112120
'truncation' => $this->truncation,
113121
'user' => $this->user,
114122
'metadata' => $this->metadata,
115-
'usage' => $this->usage->toArray(),
123+
'usage' => $this->usage,
116124
];
117125
}
118126
}

src/Responses/Responses/RetrieveResponse.php

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ final class RetrieveResponse implements ResponseContract, ResponseHasMetaInforma
2424
use Fakeable;
2525
use HasMetaInformation;
2626

27+
/**
28+
* @param array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}> $output
29+
* @param array<mixed> $reasoning
30+
* @param array{format: array{type: string}} $text
31+
* @param array<mixed> $tools
32+
* @param array<string, string> $metadata
33+
* @param array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int} $usage
34+
*/
2735
private function __construct(
2836
public readonly string $id,
2937
public readonly string $object,
@@ -47,14 +55,12 @@ private function __construct(
4755
public readonly string $truncation,
4856
public readonly ?string $user,
4957
public array $metadata,
50-
public readonly CreateResponseUsage $usage,
58+
public readonly array $usage,
5159
private readonly MetaInformation $meta,
5260
) {}
5361

5462
/**
55-
* Acts as static factory, and returns a new Response instance.
56-
*
57-
* @param array{id: string, object: string, created_at: int, status: string, error: object|null, incomplete_details: object|null, instructions: ?string, max_output_tokens: ?int, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: ?string, reasoning: array<mixed>, store: bool, temperature: ?float, text: array{format: array{type: string}}, tool_choice: string, tools: array<mixed>, top_p: ?float, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: ?string, metadata?: array<string, string>} $attributes
63+
* @param array{id: string, object: string, created_at: int, status: string, error: object|null, incomplete_details: object|null, instructions: string|null, max_output_tokens: int|null, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: string|null, reasoning: array<mixed>, store: bool, temperature: float|null, text: array{format: array{type: string}}, tool_choice: string, tools: array<mixed>, top_p: float|null, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: string|null, metadata?: array<string, string>} $attributes
5864
*/
5965
public static function from(array $attributes, MetaInformation $meta): self
6066
{
@@ -81,13 +87,13 @@ public static function from(array $attributes, MetaInformation $meta): self
8187
$attributes['truncation'],
8288
$attributes['user'],
8389
$attributes['metadata'] ?? [],
84-
CreateResponseUsage::from($attributes['usage']),
90+
$attributes['usage'],
8591
$meta,
8692
);
8793
}
8894

8995
/**
90-
* {@inheritDoc}
96+
* @return array{id: string, object: string, created_at: int, status: string, error: object|null, incomplete_details: object|null, instructions: string|null, max_output_tokens: int|null, model: string, output: array<int, array{type: string, id: string, status: string, role: string, content: array<int, array{type: string, text: string, annotations: array<mixed>}>}>, parallel_tool_calls: bool, previous_response_id: string|null, reasoning: array<mixed>, store: bool, temperature: float|null, text: array{format: array{type: string}}, tool_choice: string, tools: array<mixed>, top_p: float|null, truncation: string, usage: array{input_tokens: int, input_tokens_details: array<string, int>, output_tokens: int, output_tokens_details: array<string, int>, total_tokens: int}, user: string|null, metadata: array<string, string>}
9197
*/
9298
public function toArray(): array
9399
{
@@ -114,7 +120,7 @@ public function toArray(): array
114120
'truncation' => $this->truncation,
115121
'user' => $this->user,
116122
'metadata' => $this->metadata,
117-
'usage' => $this->usage->toArray(),
123+
'usage' => $this->usage,
118124
];
119125
}
120126
}

0 commit comments

Comments
 (0)