Skip to content

Commit

Permalink
fix: phpstan analyse
Browse files Browse the repository at this point in the history
  • Loading branch information
TyperEJ committed Nov 21, 2024
1 parent c7d0be9 commit a71b6a5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
6 changes: 3 additions & 3 deletions src/Responses/Chat/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
* @implements ResponseContract<array{id: string, object: string, created: int, model: string, system_fingerprint?: string, choices: array<int, array{index: int, message: array{role: string, content: string|null, function_call?: array{name: string, arguments: string}, tool_calls?: array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>}, finish_reason: string|null}>, usage: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}}>
* @implements ResponseContract<array{id?: string, object: string, created: int, model: string, system_fingerprint?: string, choices: array<int, array{index: int, message: array{role: string, content: string|null, function_call?: array{name: string, arguments: string}, tool_calls?: array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>}, finish_reason: string|null}>, usage?: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}}>
*/
final class CreateResponse implements ResponseContract, ResponseHasMetaInformationContract
{
Expand Down Expand Up @@ -41,7 +41,7 @@ private function __construct(
/**
* Acts as static factory, and returns a new Response instance.
*
* @param array{id: string, object: string, created: int, model: string, system_fingerprint?: string, choices: array<int, array{index: int, message: array{role: string, content: ?string, function_call: ?array{name: string, arguments: string}, tool_calls: ?array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>}, finish_reason: string|null}>, usage: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int, prompt_tokens_details?:array{cached_tokens:int}, completion_tokens_details?:array{audio_tokens?:int, reasoning_tokens:int, accepted_prediction_tokens:int, rejected_prediction_tokens:int}}} $attributes
* @param array{id?: string, object: string, created: int, model: string, system_fingerprint?: string, choices: array<int, array{index: int, message: array{role: string, content: ?string, function_call: ?array{name: string, arguments: string}, tool_calls: ?array<int, array{id: string, type: string, function: array{name: string, arguments: string}}>}, finish_reason: string|null}>, usage?: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int, prompt_tokens_details?:array{cached_tokens:int}, completion_tokens_details?:array{audio_tokens?:int, reasoning_tokens:int, accepted_prediction_tokens:int, rejected_prediction_tokens:int}}} $attributes
*/
public static function from(array $attributes, MetaInformation $meta): self
{
Expand Down Expand Up @@ -76,7 +76,7 @@ public function toArray(): array
static fn (CreateResponseChoice $result): array => $result->toArray(),
$this->choices,
),
'usage' => $this->usage->toArray(),
'usage' => $this->usage?->toArray(),
], fn (mixed $value): bool => ! is_null($value));
}
}
15 changes: 5 additions & 10 deletions src/Responses/Chat/CreateStreamedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use OpenAI\Testing\Responses\Concerns\FakeableForStreamedResponse;

/**
* @implements ResponseContract<array{id: string, object: string, created: int, model: string, choices: array<int, array{index: int, delta: array{role?: string, content?: string}|array{role?: string, content: null, function_call: array{name?: string, arguments?: string}}, finish_reason: string|null}>, usage?: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}}>
* @implements ResponseContract<array{id?: string, object: string, created: int, model: string, choices: array<int, array{index: int, delta: array{role?: string, content?: string}|array{role?: string, content: null, function_call: array{name?: string, arguments?: string}}, finish_reason: string|null}>, usage?: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}}>
*/
final class CreateStreamedResponse implements ResponseContract
{
Expand All @@ -35,7 +35,7 @@ private function __construct(
/**
* Acts as static factory, and returns a new Response instance.
*
* @param array{id: string, object: string, created: int, model: string, choices: array<int, array{index: int, delta: array{role?: string, content?: string}, finish_reason: string|null}>, usage?: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}} $attributes
* @param array{id?: string, object: string, created: int, model: string, choices: array<int, array{index: int, delta: array{role?: string, content?: string}, finish_reason: string|null}>, usage?: array{prompt_tokens: int, completion_tokens: int|null, total_tokens: int}} $attributes
*/
public static function from(array $attributes): self
{
Expand All @@ -58,7 +58,7 @@ public static function from(array $attributes): self
*/
public function toArray(): array
{
$data = [
return array_filter([
'id' => $this->id,
'object' => $this->object,
'created' => $this->created,
Expand All @@ -67,12 +67,7 @@ public function toArray(): array
static fn (CreateStreamedResponseChoice $result): array => $result->toArray(),
$this->choices,
),
];

if ($this->usage instanceof \OpenAI\Responses\Chat\CreateResponseUsage) {
$data['usage'] = $this->usage->toArray();
}

return $data;
'usage' => $this->usage?->toArray(),
], fn (mixed $value): bool => ! is_null($value));
}
}
12 changes: 6 additions & 6 deletions src/Responses/Embeddings/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
* @implements ResponseContract<array{object: string, data: array<int, array{object: string, embedding: array<int, float>, index: int}>, usage: array{prompt_tokens: int, total_tokens: int}}>
* @implements ResponseContract<array{object: string, data: array<int, array{object: string, embedding: array<int, float>, index?: int}>, usage?: array{prompt_tokens: int, total_tokens: int}}>
*/
final class CreateResponse implements ResponseContract, ResponseHasMetaInformationContract
{
/**
* @use ArrayAccessible<array{object: string, data: array<int, array{object: string, embedding: array<int, float>, index: int}>, usage: array{prompt_tokens: int, total_tokens: int}}>
* @use ArrayAccessible<array{object: string, data: array<int, array{object: string, embedding: array<int, float>, index?: int}>, usage?: array{prompt_tokens: int, total_tokens: int}}>
*/
use ArrayAccessible;

Expand All @@ -37,7 +37,7 @@ private function __construct(
/**
* Acts as static factory, and returns a new Response instance.
*
* @param array{object: string, data: array<int, array{object: string, embedding: array<int, float>, index: int}>, usage: array{prompt_tokens: int, total_tokens: int}} $attributes
* @param array{object: string, data: array<int, array{object: string, embedding: array<int, float>, index?: int}>, usage?: array{prompt_tokens: int, total_tokens: int}} $attributes
*/
public static function from(array $attributes, MetaInformation $meta): self
{
Expand All @@ -58,13 +58,13 @@ public static function from(array $attributes, MetaInformation $meta): self
*/
public function toArray(): array
{
return [
return array_filter([
'object' => $this->object,
'data' => array_map(
static fn (CreateResponseEmbedding $result): array => $result->toArray(),
$this->embeddings,
),
'usage' => $this->usage->toArray(),
];
'usage' => $this->usage?->toArray(),
], fn (mixed $value): bool => ! is_null($value));
}
}
8 changes: 4 additions & 4 deletions src/Responses/Embeddings/CreateResponseEmbedding.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private function __construct(
) {}

/**
* @param array{object: string, index: int, embedding: array<int, float>} $attributes
* @param array{object: string, index?: int, embedding: array<int, float>} $attributes
*/
public static function from(array $attributes): self
{
Expand All @@ -28,14 +28,14 @@ public static function from(array $attributes): self
}

/**
* @return array{object: string, index: int, embedding: array<int, float>}
* @return array{object: string, index?: int, embedding: array<int, float>}
*/
public function toArray(): array
{
return [
return array_filter([
'object' => $this->object,
'index' => $this->index,
'embedding' => $this->embedding,
];
], fn (mixed $value): bool => ! is_null($value));
}
}

0 comments on commit a71b6a5

Please sign in to comment.