Skip to content

Commit 99a1c57

Browse files
authored
Remove reference $fn in PopulateResult (#678)
* Remove reference $fn in PopulateResult * Split populateResponse in XML services * Add docblock * Better fix nullable map value * Fix phpstan
1 parent 746b69c commit 99a1c57

File tree

2 files changed

+54
-38
lines changed

2 files changed

+54
-38
lines changed

src/Result/ListLayerVersionsResponse.php

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use AsyncAws\Core\Response;
66
use AsyncAws\Core\Result;
7+
use AsyncAws\Lambda\Enum\Runtime;
78
use AsyncAws\Lambda\Input\ListLayerVersionsRequest;
89
use AsyncAws\Lambda\LambdaClient;
910
use AsyncAws\Lambda\ValueObject\LayerVersionsListItem;
@@ -112,34 +113,44 @@ public function getNextMarker(): ?string
112113
protected function populateResult(Response $response): void
113114
{
114115
$data = $response->toArray();
115-
$fn = [];
116-
$fn['list-LayerVersionsList'] = static function (array $json) use (&$fn): array {
117-
$items = [];
118-
foreach ($json as $item) {
119-
$items[] = new LayerVersionsListItem([
120-
'LayerVersionArn' => isset($item['LayerVersionArn']) ? (string) $item['LayerVersionArn'] : null,
121-
'Version' => isset($item['Version']) ? (string) $item['Version'] : null,
122-
'Description' => isset($item['Description']) ? (string) $item['Description'] : null,
123-
'CreatedDate' => isset($item['CreatedDate']) ? (string) $item['CreatedDate'] : null,
124-
'CompatibleRuntimes' => empty($item['CompatibleRuntimes']) ? [] : $fn['list-CompatibleRuntimes']($item['CompatibleRuntimes']),
125-
'LicenseInfo' => isset($item['LicenseInfo']) ? (string) $item['LicenseInfo'] : null,
126-
]);
127-
}
128116

129-
return $items;
130-
};
131-
$fn['list-CompatibleRuntimes'] = static function (array $json) use (&$fn): array {
132-
$items = [];
133-
foreach ($json as $item) {
134-
$a = isset($item) ? (string) $item : null;
135-
if (null !== $a) {
136-
$items[] = $a;
137-
}
117+
$this->NextMarker = isset($data['NextMarker']) ? (string) $data['NextMarker'] : null;
118+
$this->LayerVersions = empty($data['LayerVersions']) ? [] : $this->populateResultLayerVersionsList($data['LayerVersions']);
119+
}
120+
121+
/**
122+
* @return list<Runtime::*>
123+
*/
124+
private function populateResultCompatibleRuntimes(array $json): array
125+
{
126+
$items = [];
127+
foreach ($json as $item) {
128+
$a = isset($item) ? (string) $item : null;
129+
if (null !== $a) {
130+
$items[] = $a;
138131
}
132+
}
139133

140-
return $items;
141-
};
142-
$this->NextMarker = isset($data['NextMarker']) ? (string) $data['NextMarker'] : null;
143-
$this->LayerVersions = empty($data['LayerVersions']) ? [] : $fn['list-LayerVersionsList']($data['LayerVersions']);
134+
return $items;
135+
}
136+
137+
/**
138+
* @return LayerVersionsListItem[]
139+
*/
140+
private function populateResultLayerVersionsList(array $json): array
141+
{
142+
$items = [];
143+
foreach ($json as $item) {
144+
$items[] = new LayerVersionsListItem([
145+
'LayerVersionArn' => isset($item['LayerVersionArn']) ? (string) $item['LayerVersionArn'] : null,
146+
'Version' => isset($item['Version']) ? (string) $item['Version'] : null,
147+
'Description' => isset($item['Description']) ? (string) $item['Description'] : null,
148+
'CreatedDate' => isset($item['CreatedDate']) ? (string) $item['CreatedDate'] : null,
149+
'CompatibleRuntimes' => empty($item['CompatibleRuntimes']) ? [] : $this->populateResultCompatibleRuntimes($item['CompatibleRuntimes']),
150+
'LicenseInfo' => isset($item['LicenseInfo']) ? (string) $item['LicenseInfo'] : null,
151+
]);
152+
}
153+
154+
return $items;
144155
}
145156
}

src/Result/PublishLayerVersionResponse.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,7 @@ public function getVersion(): ?string
113113
protected function populateResult(Response $response): void
114114
{
115115
$data = $response->toArray();
116-
$fn = [];
117-
$fn['list-CompatibleRuntimes'] = static function (array $json) use (&$fn): array {
118-
$items = [];
119-
foreach ($json as $item) {
120-
$a = isset($item) ? (string) $item : null;
121-
if (null !== $a) {
122-
$items[] = $a;
123-
}
124-
}
125116

126-
return $items;
127-
};
128117
$this->Content = empty($data['Content']) ? null : new LayerVersionContentOutput([
129118
'Location' => isset($data['Content']['Location']) ? (string) $data['Content']['Location'] : null,
130119
'CodeSha256' => isset($data['Content']['CodeSha256']) ? (string) $data['Content']['CodeSha256'] : null,
@@ -135,7 +124,23 @@ protected function populateResult(Response $response): void
135124
$this->Description = isset($data['Description']) ? (string) $data['Description'] : null;
136125
$this->CreatedDate = isset($data['CreatedDate']) ? (string) $data['CreatedDate'] : null;
137126
$this->Version = isset($data['Version']) ? (string) $data['Version'] : null;
138-
$this->CompatibleRuntimes = empty($data['CompatibleRuntimes']) ? [] : $fn['list-CompatibleRuntimes']($data['CompatibleRuntimes']);
127+
$this->CompatibleRuntimes = empty($data['CompatibleRuntimes']) ? [] : $this->populateResultCompatibleRuntimes($data['CompatibleRuntimes']);
139128
$this->LicenseInfo = isset($data['LicenseInfo']) ? (string) $data['LicenseInfo'] : null;
140129
}
130+
131+
/**
132+
* @return list<Runtime::*>
133+
*/
134+
private function populateResultCompatibleRuntimes(array $json): array
135+
{
136+
$items = [];
137+
foreach ($json as $item) {
138+
$a = isset($item) ? (string) $item : null;
139+
if (null !== $a) {
140+
$items[] = $a;
141+
}
142+
}
143+
144+
return $items;
145+
}
141146
}

0 commit comments

Comments
 (0)