diff --git a/src/CodeGenerator/src/Generator/CodeGenerator/PopulatorGenerator.php b/src/CodeGenerator/src/Generator/CodeGenerator/PopulatorGenerator.php index 12388d5e9..92b615c48 100644 --- a/src/CodeGenerator/src/Generator/CodeGenerator/PopulatorGenerator.php +++ b/src/CodeGenerator/src/Generator/CodeGenerator/PopulatorGenerator.php @@ -190,39 +190,36 @@ private function generatePopulator(Operation $operation, StructureShape $shape, $memberShape = $member->getShape(); switch ($memberShape->getType()) { case 'timestamp': - $body .= strtr('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? new \DateTimeImmutable($headers["LOCATION_NAME"][0]) : null;' . "\n", [ - 'PROPERTY_NAME' => $propertyName, - 'LOCATION_NAME' => $locationName, - ]); + $input = 'new \DateTimeImmutable($headers["LOCATION_NAME"][0])'; break; case 'integer': case 'long': - $body .= strtr('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? (int) $headers["LOCATION_NAME"][0] : null;' . "\n", [ - 'PROPERTY_NAME' => $propertyName, - 'LOCATION_NAME' => $locationName, - ]); + $input = '(int) $headers["LOCATION_NAME"][0]'; break; case 'boolean': $this->requirementsRegistry->addRequirement('ext-filter'); - $body .= strtr('$this->PROPERTY_NAME = isset($headers["LOCATION_NAME"][0]) ? filter_var($headers["LOCATION_NAME"][0], FILTER_VALIDATE_BOOLEAN) : null;' . "\n", [ - 'PROPERTY_NAME' => $propertyName, - 'LOCATION_NAME' => $locationName, - ]); + $input = 'filter_var($headers["LOCATION_NAME"][0], FILTER_VALIDATE_BOOLEAN)'; break; case 'string': - $body .= strtr('$this->PROPERTY_NAME = $headers["LOCATION_NAME"][0] ?? null;' . "\n", [ - 'PROPERTY_NAME' => $propertyName, - 'LOCATION_NAME' => $locationName, - ]); + $input = '$headers["LOCATION_NAME"][0]'; break; default: throw new \RuntimeException(sprintf('Type %s is not yet implemented', $memberShape->getType())); } + + if (!$member->isRequired()) { + $input = 'isset($headers["LOCATION_NAME"][0]) ? ' . $input . ' : null'; + } + + $body .= strtr('$this->PROPERTY_NAME = ' . $input . ";\n", [ + 'PROPERTY_NAME' => $propertyName, + 'LOCATION_NAME' => $locationName, + ]); } // This will catch arbitrary values that exists in undefined "headers" diff --git a/src/Service/Route53/src/Result/CreateHostedZoneResponse.php b/src/Service/Route53/src/Result/CreateHostedZoneResponse.php index a3a28c726..fad5d8d01 100644 --- a/src/Service/Route53/src/Result/CreateHostedZoneResponse.php +++ b/src/Service/Route53/src/Result/CreateHostedZoneResponse.php @@ -90,7 +90,7 @@ protected function populateResult(Response $response): void { $headers = $response->getHeaders(); - $this->location = $headers['location'][0] ?? null; + $this->location = $headers['location'][0]; $data = new \SimpleXMLElement($response->getContent()); $this->hostedZone = new HostedZone([