Skip to content

Commit

Permalink
Add strict comparison null !== instead of ! (#1794)
Browse files Browse the repository at this point in the history
  • Loading branch information
jderusse authored Nov 12, 2024
1 parent b1598b5 commit fdabb07
Show file tree
Hide file tree
Showing 16 changed files with 380 additions and 247 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

- AWS api-change: Add support for the new optional bucket-region and prefix query parameters in the ListBuckets API. For ListBuckets requests that express pagination, Amazon S3 will now return both the bucket names and associated AWS regions in the response.

### Changed

- use strict comparison `null !==` instead of `!`

## 2.4.0

### Added
Expand Down
4 changes: 2 additions & 2 deletions src/Exception/InvalidObjectStateException.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function populateResult(ResponseInterface $response): void
if (0 < $data->Error->count()) {
$data = $data->Error;
}
$this->storageClass = ($v = $data->StorageClass) ? (string) $v : null;
$this->accessTier = ($v = $data->AccessTier) ? (string) $v : null;
$this->storageClass = (null !== $v = $data->StorageClass[0]) ? (string) $v : null;
$this->accessTier = (null !== $v = $data->AccessTier[0]) ? (string) $v : null;
}
}
16 changes: 8 additions & 8 deletions src/Result/CompleteMultipartUploadOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ protected function populateResult(Response $response): void
$this->requestCharged = $headers['x-amz-request-charged'][0] ?? null;

$data = new \SimpleXMLElement($response->getContent());
$this->location = ($v = $data->Location) ? (string) $v : null;
$this->bucket = ($v = $data->Bucket) ? (string) $v : null;
$this->key = ($v = $data->Key) ? (string) $v : null;
$this->etag = ($v = $data->ETag) ? (string) $v : null;
$this->checksumCrc32 = ($v = $data->ChecksumCRC32) ? (string) $v : null;
$this->checksumCrc32C = ($v = $data->ChecksumCRC32C) ? (string) $v : null;
$this->checksumSha1 = ($v = $data->ChecksumSHA1) ? (string) $v : null;
$this->checksumSha256 = ($v = $data->ChecksumSHA256) ? (string) $v : null;
$this->location = (null !== $v = $data->Location[0]) ? (string) $v : null;
$this->bucket = (null !== $v = $data->Bucket[0]) ? (string) $v : null;
$this->key = (null !== $v = $data->Key[0]) ? (string) $v : null;
$this->etag = (null !== $v = $data->ETag[0]) ? (string) $v : null;
$this->checksumCrc32 = (null !== $v = $data->ChecksumCRC32[0]) ? (string) $v : null;
$this->checksumCrc32C = (null !== $v = $data->ChecksumCRC32C[0]) ? (string) $v : null;
$this->checksumSha1 = (null !== $v = $data->ChecksumSHA1[0]) ? (string) $v : null;
$this->checksumSha256 = (null !== $v = $data->ChecksumSHA256[0]) ? (string) $v : null;
}
}
19 changes: 12 additions & 7 deletions src/Result/CopyObjectOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,18 @@ protected function populateResult(Response $response): void
$this->requestCharged = $headers['x-amz-request-charged'][0] ?? null;

$data = new \SimpleXMLElement($response->getContent());
$this->copyObjectResult = new CopyObjectResult([
'ETag' => ($v = $data->ETag) ? (string) $v : null,
'LastModified' => ($v = $data->LastModified) ? new \DateTimeImmutable((string) $v) : null,
'ChecksumCRC32' => ($v = $data->ChecksumCRC32) ? (string) $v : null,
'ChecksumCRC32C' => ($v = $data->ChecksumCRC32C) ? (string) $v : null,
'ChecksumSHA1' => ($v = $data->ChecksumSHA1) ? (string) $v : null,
'ChecksumSHA256' => ($v = $data->ChecksumSHA256) ? (string) $v : null,
$this->copyObjectResult = $this->populateResultCopyObjectResult($data);
}

private function populateResultCopyObjectResult(\SimpleXMLElement $xml): CopyObjectResult
{
return new CopyObjectResult([
'ETag' => (null !== $v = $xml->ETag[0]) ? (string) $v : null,
'LastModified' => (null !== $v = $xml->LastModified[0]) ? new \DateTimeImmutable((string) $v) : null,
'ChecksumCRC32' => (null !== $v = $xml->ChecksumCRC32[0]) ? (string) $v : null,
'ChecksumCRC32C' => (null !== $v = $xml->ChecksumCRC32C[0]) ? (string) $v : null,
'ChecksumSHA1' => (null !== $v = $xml->ChecksumSHA1[0]) ? (string) $v : null,
'ChecksumSHA256' => (null !== $v = $xml->ChecksumSHA256[0]) ? (string) $v : null,
]);
}
}
6 changes: 3 additions & 3 deletions src/Result/CreateMultipartUploadOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ protected function populateResult(Response $response): void
$this->checksumAlgorithm = $headers['x-amz-checksum-algorithm'][0] ?? null;

$data = new \SimpleXMLElement($response->getContent());
$this->bucket = ($v = $data->Bucket) ? (string) $v : null;
$this->key = ($v = $data->Key) ? (string) $v : null;
$this->uploadId = ($v = $data->UploadId) ? (string) $v : null;
$this->bucket = (null !== $v = $data->Bucket[0]) ? (string) $v : null;
$this->key = (null !== $v = $data->Key[0]) ? (string) $v : null;
$this->uploadId = (null !== $v = $data->UploadId[0]) ? (string) $v : null;
}
}
38 changes: 24 additions & 14 deletions src/Result/DeleteObjectsOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,18 @@ protected function populateResult(Response $response): void
$this->requestCharged = $headers['x-amz-request-charged'][0] ?? null;

$data = new \SimpleXMLElement($response->getContent());
$this->deleted = !$data->Deleted ? [] : $this->populateResultDeletedObjects($data->Deleted);
$this->errors = !$data->Error ? [] : $this->populateResultErrors($data->Error);
$this->deleted = (0 === ($v = $data->Deleted)->count()) ? [] : $this->populateResultDeletedObjects($v);
$this->errors = (0 === ($v = $data->Error)->count()) ? [] : $this->populateResultErrors($v);
}

private function populateResultDeletedObject(\SimpleXMLElement $xml): DeletedObject
{
return new DeletedObject([
'Key' => (null !== $v = $xml->Key[0]) ? (string) $v : null,
'VersionId' => (null !== $v = $xml->VersionId[0]) ? (string) $v : null,
'DeleteMarker' => (null !== $v = $xml->DeleteMarker[0]) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
'DeleteMarkerVersionId' => (null !== $v = $xml->DeleteMarkerVersionId[0]) ? (string) $v : null,
]);
}

/**
Expand All @@ -78,30 +88,30 @@ private function populateResultDeletedObjects(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml as $item) {
$items[] = new DeletedObject([
'Key' => ($v = $item->Key) ? (string) $v : null,
'VersionId' => ($v = $item->VersionId) ? (string) $v : null,
'DeleteMarker' => ($v = $item->DeleteMarker) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
'DeleteMarkerVersionId' => ($v = $item->DeleteMarkerVersionId) ? (string) $v : null,
]);
$items[] = $this->populateResultDeletedObject($item);
}

return $items;
}

private function populateResultError(\SimpleXMLElement $xml): Error
{
return new Error([
'Key' => (null !== $v = $xml->Key[0]) ? (string) $v : null,
'VersionId' => (null !== $v = $xml->VersionId[0]) ? (string) $v : null,
'Code' => (null !== $v = $xml->Code[0]) ? (string) $v : null,
'Message' => (null !== $v = $xml->Message[0]) ? (string) $v : null,
]);
}

/**
* @return Error[]
*/
private function populateResultErrors(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml as $item) {
$items[] = new Error([
'Key' => ($v = $item->Key) ? (string) $v : null,
'VersionId' => ($v = $item->VersionId) ? (string) $v : null,
'Code' => ($v = $item->Code) ? (string) $v : null,
'Message' => ($v = $item->Message) ? (string) $v : null,
]);
$items[] = $this->populateResultError($item);
}

return $items;
Expand Down
43 changes: 18 additions & 25 deletions src/Result/GetBucketCorsOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getCorsRules(): array
protected function populateResult(Response $response): void
{
$data = new \SimpleXMLElement($response->getContent());
$this->corsRules = !$data->CORSRule ? [] : $this->populateResultCORSRules($data->CORSRule);
$this->corsRules = (0 === ($v = $data->CORSRule)->count()) ? [] : $this->populateResultCORSRules($v);
}

/**
Expand All @@ -39,10 +39,7 @@ private function populateResultAllowedHeaders(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml as $item) {
$a = ($v = $item) ? (string) $v : null;
if (null !== $a) {
$items[] = $a;
}
$items[] = (string) $item;
}

return $items;
Expand All @@ -55,10 +52,7 @@ private function populateResultAllowedMethods(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml as $item) {
$a = ($v = $item) ? (string) $v : null;
if (null !== $a) {
$items[] = $a;
}
$items[] = (string) $item;
}

return $items;
Expand All @@ -71,30 +65,32 @@ private function populateResultAllowedOrigins(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml as $item) {
$a = ($v = $item) ? (string) $v : null;
if (null !== $a) {
$items[] = $a;
}
$items[] = (string) $item;
}

return $items;
}

private function populateResultCORSRule(\SimpleXMLElement $xml): CORSRule
{
return new CORSRule([
'ID' => (null !== $v = $xml->ID[0]) ? (string) $v : null,
'AllowedHeaders' => (0 === ($v = $xml->AllowedHeader)->count()) ? null : $this->populateResultAllowedHeaders($v),
'AllowedMethods' => $this->populateResultAllowedMethods($xml->AllowedMethod),
'AllowedOrigins' => $this->populateResultAllowedOrigins($xml->AllowedOrigin),
'ExposeHeaders' => (0 === ($v = $xml->ExposeHeader)->count()) ? null : $this->populateResultExposeHeaders($v),
'MaxAgeSeconds' => (null !== $v = $xml->MaxAgeSeconds[0]) ? (int) (string) $v : null,
]);
}

/**
* @return CORSRule[]
*/
private function populateResultCORSRules(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml as $item) {
$items[] = new CORSRule([
'ID' => ($v = $item->ID) ? (string) $v : null,
'AllowedHeaders' => !$item->AllowedHeader ? null : $this->populateResultAllowedHeaders($item->AllowedHeader),
'AllowedMethods' => $this->populateResultAllowedMethods($item->AllowedMethod),
'AllowedOrigins' => $this->populateResultAllowedOrigins($item->AllowedOrigin),
'ExposeHeaders' => !$item->ExposeHeader ? null : $this->populateResultExposeHeaders($item->ExposeHeader),
'MaxAgeSeconds' => ($v = $item->MaxAgeSeconds) ? (int) (string) $v : null,
]);
$items[] = $this->populateResultCORSRule($item);
}

return $items;
Expand All @@ -107,10 +103,7 @@ private function populateResultExposeHeaders(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml as $item) {
$a = ($v = $item) ? (string) $v : null;
if (null !== $a) {
$items[] = $a;
}
$items[] = (string) $item;
}

return $items;
Expand Down
33 changes: 24 additions & 9 deletions src/Result/GetBucketEncryptionOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,29 @@ public function getServerSideEncryptionConfiguration(): ?ServerSideEncryptionCon
protected function populateResult(Response $response): void
{
$data = new \SimpleXMLElement($response->getContent());
$this->serverSideEncryptionConfiguration = new ServerSideEncryptionConfiguration([
'Rules' => $this->populateResultServerSideEncryptionRules($data->Rule),
$this->serverSideEncryptionConfiguration = $this->populateResultServerSideEncryptionConfiguration($data);
}

private function populateResultServerSideEncryptionByDefault(\SimpleXMLElement $xml): ServerSideEncryptionByDefault
{
return new ServerSideEncryptionByDefault([
'SSEAlgorithm' => (string) $xml->SSEAlgorithm,
'KMSMasterKeyID' => (null !== $v = $xml->KMSMasterKeyID[0]) ? (string) $v : null,
]);
}

private function populateResultServerSideEncryptionConfiguration(\SimpleXMLElement $xml): ServerSideEncryptionConfiguration
{
return new ServerSideEncryptionConfiguration([
'Rules' => $this->populateResultServerSideEncryptionRules($xml->Rule),
]);
}

private function populateResultServerSideEncryptionRule(\SimpleXMLElement $xml): ServerSideEncryptionRule
{
return new ServerSideEncryptionRule([
'ApplyServerSideEncryptionByDefault' => 0 === $xml->ApplyServerSideEncryptionByDefault->count() ? null : $this->populateResultServerSideEncryptionByDefault($xml->ApplyServerSideEncryptionByDefault),
'BucketKeyEnabled' => (null !== $v = $xml->BucketKeyEnabled[0]) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
]);
}

Expand All @@ -37,13 +58,7 @@ private function populateResultServerSideEncryptionRules(\SimpleXMLElement $xml)
{
$items = [];
foreach ($xml as $item) {
$items[] = new ServerSideEncryptionRule([
'ApplyServerSideEncryptionByDefault' => !$item->ApplyServerSideEncryptionByDefault ? null : new ServerSideEncryptionByDefault([
'SSEAlgorithm' => (string) $item->ApplyServerSideEncryptionByDefault->SSEAlgorithm,
'KMSMasterKeyID' => ($v = $item->ApplyServerSideEncryptionByDefault->KMSMasterKeyID) ? (string) $v : null,
]),
'BucketKeyEnabled' => ($v = $item->BucketKeyEnabled) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
]);
$items[] = $this->populateResultServerSideEncryptionRule($item);
}

return $items;
Expand Down
43 changes: 29 additions & 14 deletions src/Result/GetObjectAclOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,27 @@ protected function populateResult(Response $response): void
$this->requestCharged = $headers['x-amz-request-charged'][0] ?? null;

$data = new \SimpleXMLElement($response->getContent());
$this->owner = !$data->Owner ? null : new Owner([
'DisplayName' => ($v = $data->Owner->DisplayName) ? (string) $v : null,
'ID' => ($v = $data->Owner->ID) ? (string) $v : null,
$this->owner = 0 === $data->Owner->count() ? null : $this->populateResultOwner($data->Owner);
$this->grants = (0 === ($v = $data->AccessControlList)->count()) ? [] : $this->populateResultGrants($v);
}

private function populateResultGrant(\SimpleXMLElement $xml): Grant
{
return new Grant([
'Grantee' => 0 === $xml->Grantee->count() ? null : $this->populateResultGrantee($xml->Grantee),
'Permission' => (null !== $v = $xml->Permission[0]) ? (string) $v : null,
]);
}

private function populateResultGrantee(\SimpleXMLElement $xml): Grantee
{
return new Grantee([
'DisplayName' => (null !== $v = $xml->DisplayName[0]) ? (string) $v : null,
'EmailAddress' => (null !== $v = $xml->EmailAddress[0]) ? (string) $v : null,
'ID' => (null !== $v = $xml->ID[0]) ? (string) $v : null,
'Type' => (string) ($xml->attributes('xsi', true)['type'][0] ?? null),
'URI' => (null !== $v = $xml->URI[0]) ? (string) $v : null,
]);
$this->grants = !$data->AccessControlList ? [] : $this->populateResultGrants($data->AccessControlList);
}

/**
Expand All @@ -78,18 +94,17 @@ private function populateResultGrants(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml->Grant as $item) {
$items[] = new Grant([
'Grantee' => !$item->Grantee ? null : new Grantee([
'DisplayName' => ($v = $item->Grantee->DisplayName) ? (string) $v : null,
'EmailAddress' => ($v = $item->Grantee->EmailAddress) ? (string) $v : null,
'ID' => ($v = $item->Grantee->ID) ? (string) $v : null,
'Type' => (string) ($item->Grantee->attributes('xsi', true)['type'][0] ?? null),
'URI' => ($v = $item->Grantee->URI) ? (string) $v : null,
]),
'Permission' => ($v = $item->Permission) ? (string) $v : null,
]);
$items[] = $this->populateResultGrant($item);
}

return $items;
}

private function populateResultOwner(\SimpleXMLElement $xml): Owner
{
return new Owner([
'DisplayName' => (null !== $v = $xml->DisplayName[0]) ? (string) $v : null,
'ID' => (null !== $v = $xml->ID[0]) ? (string) $v : null,
]);
}
}
13 changes: 9 additions & 4 deletions src/Result/GetObjectTaggingOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,22 @@ protected function populateResult(Response $response): void
$this->tagSet = $this->populateResultTagSet($data->TagSet);
}

private function populateResultTag(\SimpleXMLElement $xml): Tag
{
return new Tag([
'Key' => (string) $xml->Key,
'Value' => (string) $xml->Value,
]);
}

/**
* @return Tag[]
*/
private function populateResultTagSet(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml->Tag as $item) {
$items[] = new Tag([
'Key' => (string) $item->Key,
'Value' => (string) $item->Value,
]);
$items[] = $this->populateResultTag($item);
}

return $items;
Expand Down
Loading

0 comments on commit fdabb07

Please sign in to comment.