Skip to content

Commit a16cf86

Browse files
committed
Fix the generator when header is assigned to a required property
1 parent 24c8c84 commit a16cf86

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/CodeGenerator/src/Generator/CodeGenerator/PopulatorGenerator.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,39 +190,39 @@ private function generatePopulator(Operation $operation, StructureShape $shape,
190190
$memberShape = $member->getShape();
191191
switch ($memberShape->getType()) {
192192
case 'timestamp':
193-
$body .= strtr('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? new \DateTimeImmutable($headers["LOCATION_NAME"][0]) : null;' . "\n", [
194-
'PROPERTY_NAME' => $propertyName,
195-
'LOCATION_NAME' => $locationName,
196-
]);
193+
$propertyValue = 'new \DateTimeImmutable($headers["LOCATION_NAME"][0])';
197194

198195
break;
199196
case 'integer':
200197
case 'long':
201-
$body .= strtr('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? (int) $headers["LOCATION_NAME"][0] : null;' . "\n", [
202-
'PROPERTY_NAME' => $propertyName,
203-
'LOCATION_NAME' => $locationName,
204-
]);
198+
$propertyValue = '(int) $headers["LOCATION_NAME"][0]';
205199

206200
break;
207201
case 'boolean':
208202
$this->requirementsRegistry->addRequirement('ext-filter');
209203

210-
$body .= strtr('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? filter_var($headers["LOCATION_NAME"][0], FILTER_VALIDATE_BOOLEAN) : null;' . "\n", [
211-
'PROPERTY_NAME' => $propertyName,
212-
'LOCATION_NAME' => $locationName,
213-
]);
204+
$propertyValue = 'filter_var($headers["LOCATION_NAME"][0], FILTER_VALIDATE_BOOLEAN)';
214205

215206
break;
216207
case 'string':
217-
$body .= strtr('$this->PROPERTY_NAME = $headers["LOCATION_NAME"][0] ?? null;' . "\n", [
218-
'PROPERTY_NAME' => $propertyName,
219-
'LOCATION_NAME' => $locationName,
220-
]);
208+
$propertyValue = '$headers["LOCATION_NAME"][0]';
221209

222210
break;
223211
default:
224212
throw new \RuntimeException(\sprintf('Type %s is not yet implemented', $memberShape->getType()));
225213
}
214+
if (!$member->isRequired()) {
215+
if ('$headers["LOCATION_NAME"][0]' === $propertyValue) {
216+
$propertyValue .= '?? null';
217+
} else {
218+
$propertyValue = 'isset($headers["LOCATION_NAME"][0]) ? ' . $propertyValue . ' : null';
219+
}
220+
}
221+
222+
$body .= strtr('$this->PROPERTY_NAME = ' . $propertyValue . ';' . "\n", [
223+
'PROPERTY_NAME' => $propertyName,
224+
'LOCATION_NAME' => $locationName,
225+
]);
226226
}
227227

228228
// This will catch arbitrary values that exists in undefined "headers"

src/Service/Route53/src/Result/CreateHostedZoneResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected function populateResult(Response $response): void
9090
{
9191
$headers = $response->getHeaders();
9292

93-
$this->location = $headers['location'][0] ?? null;
93+
$this->location = $headers['location'][0];
9494

9595
$data = new \SimpleXMLElement($response->getContent());
9696
$this->hostedZone = $this->populateResultHostedZone($data->HostedZone);

0 commit comments

Comments
 (0)