Skip to content

Commit

Permalink
Use int as the PHP representation of long fields in generated code (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
stof committed Jun 28, 2023
1 parent 6e674c8 commit 972d2ae
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 26 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

## NOT RELEASED

### BC-BREAK

- The type for `\AsyncAws\S3\Input\PutObjectRequest::getContentLength` and `\AsyncAws\S3\Input\PutObjectRequest::setContentLength` uses `int` instead of `string` to reflect the AWS type.
- The type for `\AsyncAws\S3\Input\UploadPartRequest::getContentLength` and `\AsyncAws\S3\Input\UploadPartRequest::setContentLength` uses `int` instead of `string` to reflect the AWS type.
- The return type for `\AsyncAws\S3\Result\GetObjectOutput::getContentLength` uses `int` instead of `string` to reflect the AWS type.
- The return type for `\AsyncAws\S3\Result\HeadObjectOutput::getContentLength` uses `int` instead of `string` to reflect the AWS type.
- The return type for `\AsyncAws\S3\ValueObject\AwsObject::getSize` uses `int` instead of `string` to reflect the AWS type.
- The return type for `\AsyncAws\S3\ValueObject\Part::getSize` uses `int` instead of `string` to reflect the AWS type.

## 1.14.0

### Added
Expand Down
12 changes: 6 additions & 6 deletions src/Input/PutObjectRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ final class PutObjectRequest extends Input
*
* [^1]: https://www.rfc-editor.org/rfc/rfc9110.html#name-content-length
*
* @var string|null
* @var int|null
*/
private $contentLength;

Expand Down Expand Up @@ -401,7 +401,7 @@ final class PutObjectRequest extends Input
* ContentDisposition?: string,
* ContentEncoding?: string,
* ContentLanguage?: string,
* ContentLength?: string,
* ContentLength?: int,
* ContentMD5?: string,
* ContentType?: string,
* ChecksumAlgorithm?: ChecksumAlgorithm::*,
Expand Down Expand Up @@ -485,7 +485,7 @@ public function __construct(array $input = [])
* ContentDisposition?: string,
* ContentEncoding?: string,
* ContentLanguage?: string,
* ContentLength?: string,
* ContentLength?: int,
* ContentMD5?: string,
* ContentType?: string,
* ChecksumAlgorithm?: ChecksumAlgorithm::*,
Expand Down Expand Up @@ -597,7 +597,7 @@ public function getContentLanguage(): ?string
return $this->contentLanguage;
}

public function getContentLength(): ?string
public function getContentLength(): ?int
{
return $this->contentLength;
}
Expand Down Expand Up @@ -761,7 +761,7 @@ public function request(): Request
$headers['Content-Language'] = $this->contentLanguage;
}
if (null !== $this->contentLength) {
$headers['Content-Length'] = $this->contentLength;
$headers['Content-Length'] = (string) $this->contentLength;
}
if (null !== $this->contentMd5) {
$headers['Content-MD5'] = $this->contentMd5;
Expand Down Expand Up @@ -990,7 +990,7 @@ public function setContentLanguage(?string $value): self
return $this;
}

public function setContentLength(?string $value): self
public function setContentLength(?int $value): self
{
$this->contentLength = $value;

Expand Down
12 changes: 6 additions & 6 deletions src/Input/UploadPartRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ final class UploadPartRequest extends Input
/**
* Size of the body in bytes. This parameter is useful when the size of the body cannot be determined automatically.
*
* @var string|null
* @var int|null
*/
private $contentLength;

Expand Down Expand Up @@ -186,7 +186,7 @@ final class UploadPartRequest extends Input
* @param array{
* Body?: string|resource|(callable(int): string)|iterable<string>,
* Bucket?: string,
* ContentLength?: string,
* ContentLength?: int,
* ContentMD5?: string,
* ChecksumAlgorithm?: ChecksumAlgorithm::*,
* ChecksumCRC32?: string,
Expand Down Expand Up @@ -230,7 +230,7 @@ public function __construct(array $input = [])
* @param array{
* Body?: string|resource|(callable(int): string)|iterable<string>,
* Bucket?: string,
* ContentLength?: string,
* ContentLength?: int,
* ContentMD5?: string,
* ChecksumAlgorithm?: ChecksumAlgorithm::*,
* ChecksumCRC32?: string,
Expand Down Expand Up @@ -294,7 +294,7 @@ public function getChecksumSha256(): ?string
return $this->checksumSha256;
}

public function getContentLength(): ?string
public function getContentLength(): ?int
{
return $this->contentLength;
}
Expand Down Expand Up @@ -355,7 +355,7 @@ public function request(): Request
// Prepare headers
$headers = [];
if (null !== $this->contentLength) {
$headers['Content-Length'] = $this->contentLength;
$headers['Content-Length'] = (string) $this->contentLength;
}
if (null !== $this->contentMd5) {
$headers['Content-MD5'] = $this->contentMd5;
Expand Down Expand Up @@ -482,7 +482,7 @@ public function setChecksumSha256(?string $value): self
return $this;
}

public function setContentLength(?string $value): self
public function setContentLength(?int $value): self
{
$this->contentLength = $value;

Expand Down
2 changes: 1 addition & 1 deletion src/Result/GetObjectOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public function getContentLanguage(): ?string
return $this->contentLanguage;
}

public function getContentLength(): ?string
public function getContentLength(): ?int
{
$this->initialize();

Expand Down
2 changes: 1 addition & 1 deletion src/Result/HeadObjectOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public function getContentLanguage(): ?string
return $this->contentLanguage;
}

public function getContentLength(): ?string
public function getContentLength(): ?int
{
$this->initialize();

Expand Down
2 changes: 1 addition & 1 deletion src/Result/ListObjectsV2Output.php
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private function populateResultObjectList(\SimpleXMLElement $xml): array
'LastModified' => ($v = $item->LastModified) ? new \DateTimeImmutable((string) $v) : null,
'ETag' => ($v = $item->ETag) ? (string) $v : null,
'ChecksumAlgorithm' => !$item->ChecksumAlgorithm ? null : $this->populateResultChecksumAlgorithmList($item->ChecksumAlgorithm),
'Size' => ($v = $item->Size) ? (string) $v : null,
'Size' => ($v = $item->Size) ? (int) (string) $v : null,
'StorageClass' => ($v = $item->StorageClass) ? (string) $v : null,
'Owner' => !$item->Owner ? null : new Owner([
'DisplayName' => ($v = $item->Owner->DisplayName) ? (string) $v : null,
Expand Down
2 changes: 1 addition & 1 deletion src/Result/ListPartsOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private function populateResultParts(\SimpleXMLElement $xml): array
'PartNumber' => ($v = $item->PartNumber) ? (int) (string) $v : null,
'LastModified' => ($v = $item->LastModified) ? new \DateTimeImmutable((string) $v) : null,
'ETag' => ($v = $item->ETag) ? (string) $v : null,
'Size' => ($v = $item->Size) ? (string) $v : null,
'Size' => ($v = $item->Size) ? (int) (string) $v : null,
'ChecksumCRC32' => ($v = $item->ChecksumCRC32) ? (string) $v : null,
'ChecksumCRC32C' => ($v = $item->ChecksumCRC32C) ? (string) $v : null,
'ChecksumSHA1' => ($v = $item->ChecksumSHA1) ? (string) $v : null,
Expand Down
4 changes: 2 additions & 2 deletions src/S3Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ public function putBucketTagging($input): Result
* ContentDisposition?: string,
* ContentEncoding?: string,
* ContentLanguage?: string,
* ContentLength?: string,
* ContentLength?: int,
* ContentMD5?: string,
* ContentType?: string,
* ChecksumAlgorithm?: ChecksumAlgorithm::*,
Expand Down Expand Up @@ -2419,7 +2419,7 @@ public function putObjectTagging($input): PutObjectTaggingOutput
* @param array{
* Body?: string|resource|(callable(int): string)|iterable<string>,
* Bucket: string,
* ContentLength?: string,
* ContentLength?: int,
* ContentMD5?: string,
* ChecksumAlgorithm?: ChecksumAlgorithm::*,
* ChecksumCRC32?: string,
Expand Down
6 changes: 3 additions & 3 deletions src/ValueObject/AwsObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ final class AwsObject
* LastModified?: null|\DateTimeImmutable,
* ETag?: null|string,
* ChecksumAlgorithm?: null|array<ChecksumAlgorithm::*>,
* Size?: null|string,
* Size?: null|int,
* StorageClass?: null|ObjectStorageClass::*,
* Owner?: null|Owner|array,
* } $input
Expand All @@ -83,7 +83,7 @@ public function __construct(array $input)
* LastModified?: null|\DateTimeImmutable,
* ETag?: null|string,
* ChecksumAlgorithm?: null|array<ChecksumAlgorithm::*>,
* Size?: null|string,
* Size?: null|int,
* StorageClass?: null|ObjectStorageClass::*,
* Owner?: null|Owner|array,
* }|AwsObject $input
Expand Down Expand Up @@ -121,7 +121,7 @@ public function getOwner(): ?Owner
return $this->owner;
}

public function getSize(): ?string
public function getSize(): ?int
{
return $this->size;
}
Expand Down
6 changes: 3 additions & 3 deletions src/ValueObject/Part.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ final class Part
* PartNumber?: null|int,
* LastModified?: null|\DateTimeImmutable,
* ETag?: null|string,
* Size?: null|string,
* Size?: null|int,
* ChecksumCRC32?: null|string,
* ChecksumCRC32C?: null|string,
* ChecksumSHA1?: null|string,
Expand All @@ -92,7 +92,7 @@ public function __construct(array $input)
* PartNumber?: null|int,
* LastModified?: null|\DateTimeImmutable,
* ETag?: null|string,
* Size?: null|string,
* Size?: null|int,
* ChecksumCRC32?: null|string,
* ChecksumCRC32C?: null|string,
* ChecksumSHA1?: null|string,
Expand Down Expand Up @@ -139,7 +139,7 @@ public function getPartNumber(): ?int
return $this->partNumber;
}

public function getSize(): ?string
public function getSize(): ?int
{
return $this->size;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Integration/S3ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ public function testGetObject(): void
]);
self::assertEquals('content', $result->getBody()->getContentAsString());
self::assertEquals('bytes', $result->getAcceptRanges());
self::assertSame('7', $result->getContentLength());
self::assertSame(7, $result->getContentLength());
self::assertEquals('"9a0364b9e99bb480dd25e1f0284c8555"', $result->getETag());
self::assertEquals('image/jpg', $result->getContentType());
}
Expand Down Expand Up @@ -490,7 +490,7 @@ public function testHeadObject(): void

$result->resolve();

self::assertSame('7', $result->getContentLength());
self::assertSame(7, $result->getContentLength());
self::assertEquals('"9a0364b9e99bb480dd25e1f0284c8555"', $result->getETag());
}

Expand Down

0 comments on commit 972d2ae

Please sign in to comment.