From 032a5f4df33a552bab07644ce82cfde622843e21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Sat, 1 Mar 2025 17:50:53 +0100 Subject: [PATCH] Fix the generator when header is assigned to a required property --- psalm.baseline.xml | 7 +--- .../CodeGenerator/PopulatorGenerator.php | 32 +++++++++---------- src/Service/Route53/CHANGELOG.md | 4 +++ .../src/Result/CreateHostedZoneResponse.php | 2 +- 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/psalm.baseline.xml b/psalm.baseline.xml index 1cf2ae923..ece2ef789 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -246,11 +246,6 @@ ]]> - - - - - $items @@ -331,5 +326,5 @@ ]]> ]]> - + diff --git a/src/CodeGenerator/src/Generator/CodeGenerator/PopulatorGenerator.php b/src/CodeGenerator/src/Generator/CodeGenerator/PopulatorGenerator.php index 86a4af868..3affd7036 100644 --- a/src/CodeGenerator/src/Generator/CodeGenerator/PopulatorGenerator.php +++ b/src/CodeGenerator/src/Generator/CodeGenerator/PopulatorGenerator.php @@ -190,39 +190,39 @@ 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, - ]); + $propertyValue = '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, - ]); + $propertyValue = '(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, - ]); + $propertyValue = '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, - ]); + $propertyValue = '$headers["LOCATION_NAME"][0]'; break; default: throw new \RuntimeException(\sprintf('Type %s is not yet implemented', $memberShape->getType())); } + if (!$member->isRequired()) { + if ('$headers["LOCATION_NAME"][0]' === $propertyValue) { + $propertyValue .= '?? null'; + } else { + $propertyValue = 'isset($headers["LOCATION_NAME"][0]) ? ' . $propertyValue . ' : null'; + } + } + + $body .= strtr('$this->PROPERTY_NAME = ' . $propertyValue . ';' . "\n", [ + 'PROPERTY_NAME' => $propertyName, + 'LOCATION_NAME' => $locationName, + ]); } // This will catch arbitrary values that exists in undefined "headers" diff --git a/src/Service/Route53/CHANGELOG.md b/src/Service/Route53/CHANGELOG.md index 140bd2eff..b45c3cd57 100644 --- a/src/Service/Route53/CHANGELOG.md +++ b/src/Service/Route53/CHANGELOG.md @@ -6,6 +6,10 @@ - AWS api-change: Added `us-isof-east-1` and `us-isof-south-1` regions +### Changed + +- trust AWS's API response: And not check if required headers are present + ## 2.6.0 ### Added diff --git a/src/Service/Route53/src/Result/CreateHostedZoneResponse.php b/src/Service/Route53/src/Result/CreateHostedZoneResponse.php index d2a118e84..712779c49 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 = $this->populateResultHostedZone($data->HostedZone);