Skip to content

Commit fb76c99

Browse files
committed
refactor: removes array_values and supresses phpstan errors
1 parent 07df1e7 commit fb76c99

File tree

5 files changed

+32
-26
lines changed

5 files changed

+32
-26
lines changed

src/Providers/DTO/ProviderModelsMetadata.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
* @phpstan-type ProviderModelsMetadataArrayShape array{
2222
* provider: ProviderMetadataArrayShape,
23-
* models: array<int, ModelMetadataArrayShape>
23+
* models: list<ModelMetadataArrayShape>
2424
* }
2525
*
2626
* @extends AbstractDataValueObject<ProviderModelsMetadataArrayShape>
@@ -108,10 +108,12 @@ public static function getJsonSchema(): array
108108
*/
109109
public function toArray(): array
110110
{
111+
/** @phpstan-ignore-next-line return.type (array_map doesn't guarantee list, validation will be added later) */
111112
return [
112113
self::KEY_PROVIDER => $this->provider->toArray(),
113-
self::KEY_MODELS => array_values(
114-
array_map(static fn(ModelMetadata $model): array => $model->toArray(), $this->models)
114+
self::KEY_MODELS => array_map(
115+
static fn(ModelMetadata $model): array => $model->toArray(),
116+
$this->models
115117
),
116118
];
117119
}

src/Providers/Models/DTO/ModelConfig.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,19 @@
2020
* @phpstan-import-type ToolArrayShape from Tool
2121
*
2222
* @phpstan-type ModelConfigArrayShape array{
23-
* outputModalities?: array<int, string>,
23+
* outputModalities?: list<string>,
2424
* systemInstruction?: string,
2525
* candidateCount?: int,
2626
* maxTokens?: int,
2727
* temperature?: float,
2828
* topP?: float,
2929
* topK?: int,
30-
* stopSequences?: array<int, string>,
30+
* stopSequences?: list<string>,
3131
* presencePenalty?: float,
3232
* frequencyPenalty?: float,
3333
* logprobs?: bool,
3434
* topLogprobs?: int,
35-
* tools?: array<int, ToolArrayShape>,
35+
* tools?: list<ToolArrayShape>,
3636
* outputMimeType?: string,
3737
* outputSchema?: array<string, mixed>,
3838
* customOptions?: array<string, mixed>
@@ -653,12 +653,12 @@ public function toArray(): array
653653
$data = [];
654654

655655
if ($this->outputModalities !== null) {
656-
$data[self::KEY_OUTPUT_MODALITIES] = array_values(array_map(
656+
$data[self::KEY_OUTPUT_MODALITIES] = array_map(
657657
static function (ModalityEnum $modality): string {
658658
return $modality->value;
659659
},
660660
$this->outputModalities
661-
));
661+
);
662662
}
663663

664664
if ($this->systemInstruction !== null) {
@@ -686,7 +686,7 @@ static function (ModalityEnum $modality): string {
686686
}
687687

688688
if ($this->stopSequences !== null) {
689-
$data[self::KEY_STOP_SEQUENCES] = array_values($this->stopSequences);
689+
$data[self::KEY_STOP_SEQUENCES] = $this->stopSequences;
690690
}
691691

692692
if ($this->presencePenalty !== null) {
@@ -706,9 +706,9 @@ static function (ModalityEnum $modality): string {
706706
}
707707

708708
if ($this->tools !== null) {
709-
$data[self::KEY_TOOLS] = array_values(array_map(static function (Tool $tool): array {
709+
$data[self::KEY_TOOLS] = array_map(static function (Tool $tool): array {
710710
return $tool->toArray();
711-
}, $this->tools));
711+
}, $this->tools);
712712
}
713713

714714
if ($this->outputMimeType !== null) {
@@ -721,6 +721,7 @@ static function (ModalityEnum $modality): string {
721721

722722
$data[self::KEY_CUSTOM_OPTIONS] = $this->customOptions;
723723

724+
/** @phpstan-ignore-next-line return.type (array_map doesn't guarantee list, validation will be added later) */
724725
return $data;
725726
}
726727

@@ -765,7 +766,7 @@ public static function fromArray(array $array): self
765766
}
766767

767768
if (isset($array[self::KEY_STOP_SEQUENCES])) {
768-
$config->setStopSequences(array_values($array[self::KEY_STOP_SEQUENCES]));
769+
$config->setStopSequences($array[self::KEY_STOP_SEQUENCES]);
769770
}
770771

771772
if (isset($array[self::KEY_PRESENCE_PENALTY])) {

src/Providers/Models/DTO/ModelMetadata.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
* @phpstan-type ModelMetadataArrayShape array{
2121
* id: string,
2222
* name: string,
23-
* supportedCapabilities: array<int, string>,
24-
* supportedOptions: array<int, SupportedOptionArrayShape>
23+
* supportedCapabilities: list<string>,
24+
* supportedOptions: list<SupportedOptionArrayShape>
2525
* }
2626
*
2727
* @extends AbstractDataValueObject<ModelMetadataArrayShape>
@@ -164,17 +164,18 @@ public static function getJsonSchema(): array
164164
*/
165165
public function toArray(): array
166166
{
167+
/** @phpstan-ignore-next-line return.type (array_map doesn't guarantee list, validation will be added later) */
167168
return [
168169
self::KEY_ID => $this->id,
169170
self::KEY_NAME => $this->name,
170-
self::KEY_SUPPORTED_CAPABILITIES => array_values(array_map(
171+
self::KEY_SUPPORTED_CAPABILITIES => array_map(
171172
static fn(CapabilityEnum $capability): string => $capability->value,
172173
$this->supportedCapabilities
173-
)),
174-
self::KEY_SUPPORTED_OPTIONS => array_values(array_map(
174+
),
175+
self::KEY_SUPPORTED_OPTIONS => array_map(
175176
static fn(SupportedOption $option): array => $option->toArray(),
176177
$this->supportedOptions
177-
)),
178+
),
178179
];
179180
}
180181

src/Providers/Models/DTO/ModelRequirements.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
* @phpstan-import-type RequiredOptionArrayShape from RequiredOption
1919
*
2020
* @phpstan-type ModelRequirementsArrayShape array{
21-
* requiredCapabilities: array<int, string>,
22-
* requiredOptions: array<int, RequiredOptionArrayShape>
21+
* requiredCapabilities: list<string>,
22+
* requiredOptions: list<RequiredOptionArrayShape>
2323
* }
2424
*
2525
* @extends AbstractDataValueObject<ModelRequirementsArrayShape>
@@ -114,15 +114,16 @@ public static function getJsonSchema(): array
114114
*/
115115
public function toArray(): array
116116
{
117+
/** @phpstan-ignore-next-line return.type (array_map doesn't guarantee list, validation will be added later) */
117118
return [
118-
self::KEY_REQUIRED_CAPABILITIES => array_values(array_map(
119+
self::KEY_REQUIRED_CAPABILITIES => array_map(
119120
static fn(CapabilityEnum $capability): string => $capability->value,
120121
$this->requiredCapabilities
121-
)),
122-
self::KEY_REQUIRED_OPTIONS => array_values(array_map(
122+
),
123+
self::KEY_REQUIRED_OPTIONS => array_map(
123124
static fn(RequiredOption $option): array => $option->toArray(),
124125
$this->requiredOptions
125-
)),
126+
),
126127
];
127128
}
128129

src/Providers/Models/DTO/SupportedOption.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @phpstan-type SupportedOptionArrayShape array{
1818
* name: string,
19-
* supportedValues?: array<int, mixed>
19+
* supportedValues?: list<mixed>
2020
* }
2121
*
2222
* @extends AbstractDataValueObject<SupportedOptionArrayShape>
@@ -139,9 +139,10 @@ public function toArray(): array
139139
];
140140

141141
if ($this->supportedValues !== null) {
142-
$data[self::KEY_SUPPORTED_VALUES] = array_values($this->supportedValues);
142+
$data[self::KEY_SUPPORTED_VALUES] = $this->supportedValues;
143143
}
144144

145+
/** @phpstan-ignore-next-line return.type (array doesn't guarantee list, validation will be added later) */
145146
return $data;
146147
}
147148

0 commit comments

Comments
 (0)