Skip to content

Commit 7aac71c

Browse files
authored
Use int as the PHP representation of long fields in generated code (#1471)
* Use int as the PHP representation of long fields in generated code * Add changelog entries for signature changes affecting strict types * Remove generator hacks needed for endpoint shapes to force the type Now that long fields are always defined as integer, we don't need such hacks anymore
1 parent f4f7972 commit 7aac71c

File tree

140 files changed

+507
-409
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+507
-409
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ private function generateProperties(StructureShape $shape, ClassBuilder $classBu
123123
$this->objectGenerator->generate($memberShape, $forEndpoint);
124124
if ($forEndpoint && 'endpoints' === $propertyName) {
125125
$forEndpoint = false;
126-
$returnType = 'array';
127126
}
128127
}
129128
if (!empty($memberShape->getEnum())) {

src/CodeGenerator/src/Generator/CodeGenerator/TypeGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ private function getNativePhpType(string $parameterType): string
187187
case 'structure':
188188
case 'map':
189189
return 'array';
190-
case 'long':
191190
case 'string':
192191
case 'blob':
193192
return 'string';
193+
case 'long':
194194
case 'integer':
195195
return 'int';
196196
case 'float':

src/CodeGenerator/src/Generator/InputGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,8 @@ private function stringify(string $variable, Member $member, string $part): stri
514514
case 'boolean':
515515
return $variable . ' ? "true" : "false"';
516516
case 'string':
517-
case 'long':
518517
return $variable;
518+
case 'long':
519519
case 'integer':
520520
return '(string) ' . $variable;
521521
}

src/CodeGenerator/src/Generator/ObjectGenerator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ private function namedConstructor(StructureShape $shape, ClassBuilder $classBuil
219219
*/
220220
private function addProperties(StructureShape $shape, ClassBuilder $classBuilder, bool $forEndpoint): void
221221
{
222-
$forEndpointProps = $forEndpoint ? ['address' => false, 'cachePeriodInMinutes' => false] : ['address' => true, 'cachePeriodInMinutes' => true];
222+
$forEndpointProps = $forEndpoint ? ['address' => false, 'cachePeriodInMinutes' => false] : [];
223223
foreach ($shape->getMembers() as $member) {
224224
$nullable = $returnType = null;
225225
$memberShape = $member->getShape();
@@ -231,9 +231,6 @@ private function addProperties(StructureShape $shape, ClassBuilder $classBuilder
231231
[$returnType, $parameterType, $memberClassNames] = $this->typeGenerator->getPhpType($memberShape);
232232
if ($forEndpoint && isset($forEndpointProps[$propertyName])) {
233233
$forEndpointProps[$propertyName] = true;
234-
if ('cachePeriodInMinutes' === $propertyName) {
235-
$returnType = $parameterType = 'int';
236-
}
237234
}
238235
foreach ($memberClassNames as $memberClassName) {
239236
$classBuilder->addUse($memberClassName->getFqdn());

src/CodeGenerator/src/Generator/ResponseParser/RestJsonParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ private function parseElement(string $input, Shape $shape, bool $required, bool
164164

165165
switch ($shape->getType()) {
166166
case 'string':
167-
case 'long':
168167
return $this->parseResponseString($input, $required);
168+
case 'long':
169169
case 'integer':
170170
return $this->parseResponseInteger($input, $required);
171171
case 'float':

src/CodeGenerator/src/Generator/ResponseParser/RestXmlParser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ private function parseXmlElement(string $input, Shape $shape, bool $required, bo
162162

163163
switch ($shape->getType()) {
164164
case 'string':
165-
case 'long':
166165
return $this->parseXmlResponseString($input, $required);
166+
case 'long':
167167
case 'integer':
168168
return $this->parseXmlResponseInteger($input, $required);
169169
case 'float':

src/Service/AppSync/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
## NOT RELEASED
44

5+
### BC-BREAK
6+
7+
- The type for `\AsyncAws\AppSync\Input\UpdateApiKeyRequest::setExpires` and `\AsyncAws\AppSync\Input\UpdateApiKeyRequest::getExpires` uses `int` instead of `string` to reflect the AWS type.
8+
- The return type for the methods `getDeletes` and `getExpires` of `\AsyncAws\AppSync\ValueObject\ApiKey` uses `int` instead of `string` to reflect the AWS type.
9+
- The return type for `\AsyncAws\AppSync\ValueObject\CachingConfig::getTtl` uses `int` instead of `string` to reflect the AWS type.
10+
- The return type for the methods `getBaseTableTtl` and `getDeltaSyncTableTtl` of `\AsyncAws\AppSync\ValueObject\DeltaSyncConfig` uses `int` instead of `string` to reflect the AWS type.
11+
512
## 1.1.0
613

714
### Added

src/Service/AppSync/src/AppSyncClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public function startSchemaCreation($input): StartSchemaCreationResponse
267267
* apiId: string,
268268
* id: string,
269269
* description?: string,
270-
* expires?: string,
270+
* expires?: int,
271271
* '@region'?: string|null,
272272
* }|UpdateApiKeyRequest $input
273273
*

src/Service/AppSync/src/Input/UpdateApiKeyRequest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final class UpdateApiKeyRequest extends Input
3838
* From the update time, the time after which the API key expires. The date is represented as seconds since the epoch.
3939
* For more information, see .
4040
*
41-
* @var string|null
41+
* @var int|null
4242
*/
4343
private $expires;
4444

@@ -47,7 +47,7 @@ final class UpdateApiKeyRequest extends Input
4747
* apiId?: string,
4848
* id?: string,
4949
* description?: string,
50-
* expires?: string,
50+
* expires?: int,
5151
* '@region'?: string|null,
5252
* } $input
5353
*/
@@ -65,7 +65,7 @@ public function __construct(array $input = [])
6565
* apiId?: string,
6666
* id?: string,
6767
* description?: string,
68-
* expires?: string,
68+
* expires?: int,
6969
* '@region'?: string|null,
7070
* }|UpdateApiKeyRequest $input
7171
*/
@@ -84,7 +84,7 @@ public function getDescription(): ?string
8484
return $this->description;
8585
}
8686

87-
public function getExpires(): ?string
87+
public function getExpires(): ?int
8888
{
8989
return $this->expires;
9090
}
@@ -139,7 +139,7 @@ public function setDescription(?string $value): self
139139
return $this;
140140
}
141141

142-
public function setExpires(?string $value): self
142+
public function setExpires(?int $value): self
143143
{
144144
$this->expires = $value;
145145

src/Service/AppSync/src/Result/CreateResolverResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ private function populateResultAppSyncRuntime(array $json): AppSyncRuntime
4343
private function populateResultCachingConfig(array $json): CachingConfig
4444
{
4545
return new CachingConfig([
46-
'ttl' => (string) $json['ttl'],
46+
'ttl' => (int) $json['ttl'],
4747
'cachingKeys' => !isset($json['cachingKeys']) ? null : $this->populateResultCachingKeys($json['cachingKeys']),
4848
]);
4949
}

0 commit comments

Comments
 (0)