Skip to content

Commit 4718c47

Browse files
authored
Fix the generator when header is assigned to a required property (#1851)
1 parent 24c8c84 commit 4718c47

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

psalm.baseline.xml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,6 @@
246246
<code><![CDATA[list<Reason::*>]]></code>
247247
</MoreSpecificReturnType>
248248
</file>
249-
<file src="src/Service/Route53/src/Result/CreateHostedZoneResponse.php">
250-
<PossiblyNullPropertyAssignmentValue>
251-
<code><![CDATA[$headers['location'][0] ?? null]]></code>
252-
</PossiblyNullPropertyAssignmentValue>
253-
</file>
254249
<file src="src/Service/S3/src/Result/ListObjectsV2Output.php">
255250
<LessSpecificReturnStatement>
256251
<code>$items</code>
@@ -331,5 +326,5 @@
331326
<code><![CDATA[list<KeyAgreementAlgorithmSpec::*>]]></code>
332327
<code><![CDATA[list<SigningAlgorithmSpec::*>]]></code>
333328
</MoreSpecificReturnType>
334-
</file>
329+
</file>
335330
</files>

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/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- AWS api-change: Added `us-isof-east-1` and `us-isof-south-1` regions
88

9+
### Changed
10+
11+
- trust AWS's API response: And not check if required headers are present
12+
913
## 2.6.0
1014

1115
### Added

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)