Skip to content

Commit c7d4a88

Browse files
committed
chore: use [] checks instead of count with zero on array
1 parent f48a0bc commit c7d4a88

File tree

12 files changed

+16
-16
lines changed

12 files changed

+16
-16
lines changed

src/Bridge/Anthropic/Contract/AssistantMessageNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
5858
'type' => 'tool_use',
5959
'id' => $toolCall->id,
6060
'name' => $toolCall->name,
61-
'input' => 0 !== \count($toolCall->arguments) ? $toolCall->arguments : new \stdClass(),
61+
'input' => [] !== $toolCall->arguments ? $toolCall->arguments : new \stdClass(),
6262
];
6363
}, $data->toolCalls),
6464
];

src/Bridge/Anthropic/ResponseConverter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function convert(ResponseInterface $response, array $options = []): LlmRe
4242

4343
$data = $response->toArray();
4444

45-
if (!isset($data['content']) || 0 === \count($data['content'])) {
45+
if (!isset($data['content']) || [] === $data['content']) {
4646
throw new RuntimeException('Response does not contain any content');
4747
}
4848

@@ -53,11 +53,11 @@ public function convert(ResponseInterface $response, array $options = []): LlmRe
5353
}
5454
}
5555

56-
if (!isset($data['content'][0]['text']) && 0 === \count($toolCalls)) {
56+
if (!isset($data['content'][0]['text']) && [] === $toolCalls) {
5757
throw new RuntimeException('Response content does not contain any text nor tool calls.');
5858
}
5959

60-
if (0 !== \count($toolCalls)) {
60+
if ([] !== $toolCalls) {
6161
return new ToolCallResponse(...$toolCalls);
6262
}
6363

src/Bridge/Bedrock/Anthropic/ClaudeHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function convert(InvokeModelResponse $bedrockResponse): LlmResponse
6666
{
6767
$data = json_decode($bedrockResponse->getBody(), true, 512, \JSON_THROW_ON_ERROR);
6868

69-
if (!isset($data['content']) || 0 === \count($data['content'])) {
69+
if (!isset($data['content']) || [] === $data['content']) {
7070
throw new RuntimeException('Response does not contain any content');
7171
}
7272

@@ -80,7 +80,7 @@ public function convert(InvokeModelResponse $bedrockResponse): LlmResponse
8080
$toolCalls[] = new ToolCall($content['id'], $content['name'], $content['input']);
8181
}
8282
}
83-
if (0 !== \count($toolCalls)) {
83+
if ([] !== $toolCalls) {
8484
return new ToolCallResponse(...$toolCalls);
8585
}
8686

src/Bridge/Bedrock/Nova/Contract/AssistantMessageNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
5757
'toolUse' => [
5858
'toolUseId' => $toolCall->id,
5959
'name' => $toolCall->name,
60-
'input' => 0 !== \count($toolCall->arguments) ? $toolCall->arguments : new \stdClass(),
60+
'input' => [] !== $toolCall->arguments ? $toolCall->arguments : new \stdClass(),
6161
],
6262
];
6363
}, $data->toolCalls),

src/Bridge/Bedrock/Nova/NovaHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function convert(InvokeModelResponse $bedrockResponse): LlmResponse
6767
{
6868
$data = json_decode($bedrockResponse->getBody(), true, 512, \JSON_THROW_ON_ERROR);
6969

70-
if (!isset($data['output']) || 0 === \count($data['output'])) {
70+
if (!isset($data['output']) || [] === $data['output']) {
7171
throw new RuntimeException('Response does not contain any content');
7272
}
7373

@@ -81,7 +81,7 @@ public function convert(InvokeModelResponse $bedrockResponse): LlmResponse
8181
$toolCalls[] = new ToolCall($content['toolUse']['toolUseId'], $content['toolUse']['name'], $content['toolUse']['input']);
8282
}
8383
}
84-
if (0 !== \count($toolCalls)) {
84+
if ([] !== $toolCalls) {
8585
return new ToolCallResponse(...$toolCalls);
8686
}
8787

src/Bridge/HuggingFace/ModelClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private function getPayload(array|string $payload, array $options): array
7777
if (\is_string($payload) || !(isset($payload['body']) || isset($payload['json']))) {
7878
$payload = ['json' => ['inputs' => $payload]];
7979

80-
if (0 !== \count($options)) {
80+
if ([] !== $options) {
8181
$payload['json']['parameters'] = $options;
8282
}
8383
}

src/Contract/JsonSchema/Factory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function buildProperties(string $className): ?array
9090
*/
9191
private function convertTypes(array $elements): ?array
9292
{
93-
if (0 === \count($elements)) {
93+
if ([] === $elements) {
9494
return null;
9595
}
9696

src/Message/AssistantMessage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ public function getId(): Uuid
4343

4444
public function hasToolCalls(): bool
4545
{
46-
return null !== $this->toolCalls && 0 !== \count($this->toolCalls);
46+
return null !== $this->toolCalls && [] !== $this->toolCalls;
4747
}
4848
}

src/Response/Choice.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public function getToolCalls(): array
4545

4646
public function hasToolCall(): bool
4747
{
48-
return 0 !== \count($this->toolCalls);
48+
return [] !== $this->toolCalls;
4949
}
5050
}

src/Response/ChoiceResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final class ChoiceResponse extends BaseResponse
2525

2626
public function __construct(Choice ...$choices)
2727
{
28-
if (0 === \count($choices)) {
28+
if ([] === $choices) {
2929
throw new InvalidArgumentException('Response must have at least one choice.');
3030
}
3131

0 commit comments

Comments
 (0)