From 80c2e5740989b1449ff48fc24b4122fe699e60f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Deruss=C3=A9?= Date: Tue, 12 Nov 2024 16:05:15 +0100 Subject: [PATCH] Add strict comparison `null !==` instead of `!` (#1794) --- CHANGELOG.md | 1 + src/Signer/SignerV4.php | 2 +- src/Sts/Result/AssumeRoleResponse.php | 30 ++++++++++------ .../AssumeRoleWithWebIdentityResponse.php | 36 ++++++++++++------- src/Sts/Result/GetCallerIdentityResponse.php | 6 ++-- 5 files changed, 48 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 282c71f..af91d0f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ ### Changed +- use strict comparison `null !==` instead of `!` - Fix CS ## 1.22.1 diff --git a/src/Signer/SignerV4.php b/src/Signer/SignerV4.php index 84875e2..6029990 100644 --- a/src/Signer/SignerV4.php +++ b/src/Signer/SignerV4.php @@ -317,7 +317,7 @@ private function buildCanonicalQuery(Request $request): string $query = $request->getQuery(); unset($query['X-Amz-Signature']); - if (!$query) { + if (empty($query)) { return ''; } diff --git a/src/Sts/Result/AssumeRoleResponse.php b/src/Sts/Result/AssumeRoleResponse.php index cb4ac1c..335d40c 100644 --- a/src/Sts/Result/AssumeRoleResponse.php +++ b/src/Sts/Result/AssumeRoleResponse.php @@ -94,17 +94,27 @@ protected function populateResult(Response $response): void $data = new \SimpleXMLElement($response->getContent()); $data = $data->AssumeRoleResult; - $this->credentials = !$data->Credentials ? null : new Credentials([ - 'AccessKeyId' => (string) $data->Credentials->AccessKeyId, - 'SecretAccessKey' => (string) $data->Credentials->SecretAccessKey, - 'SessionToken' => (string) $data->Credentials->SessionToken, - 'Expiration' => new \DateTimeImmutable((string) $data->Credentials->Expiration), + $this->credentials = 0 === $data->Credentials->count() ? null : $this->populateResultCredentials($data->Credentials); + $this->assumedRoleUser = 0 === $data->AssumedRoleUser->count() ? null : $this->populateResultAssumedRoleUser($data->AssumedRoleUser); + $this->packedPolicySize = (null !== $v = $data->PackedPolicySize[0]) ? (int) (string) $v : null; + $this->sourceIdentity = (null !== $v = $data->SourceIdentity[0]) ? (string) $v : null; + } + + private function populateResultAssumedRoleUser(\SimpleXMLElement $xml): AssumedRoleUser + { + return new AssumedRoleUser([ + 'AssumedRoleId' => (string) $xml->AssumedRoleId, + 'Arn' => (string) $xml->Arn, ]); - $this->assumedRoleUser = !$data->AssumedRoleUser ? null : new AssumedRoleUser([ - 'AssumedRoleId' => (string) $data->AssumedRoleUser->AssumedRoleId, - 'Arn' => (string) $data->AssumedRoleUser->Arn, + } + + private function populateResultCredentials(\SimpleXMLElement $xml): Credentials + { + return new Credentials([ + 'AccessKeyId' => (string) $xml->AccessKeyId, + 'SecretAccessKey' => (string) $xml->SecretAccessKey, + 'SessionToken' => (string) $xml->SessionToken, + 'Expiration' => new \DateTimeImmutable((string) $xml->Expiration), ]); - $this->packedPolicySize = ($v = $data->PackedPolicySize) ? (int) (string) $v : null; - $this->sourceIdentity = ($v = $data->SourceIdentity) ? (string) $v : null; } } diff --git a/src/Sts/Result/AssumeRoleWithWebIdentityResponse.php b/src/Sts/Result/AssumeRoleWithWebIdentityResponse.php index 6eb1094..5e6c1f8 100644 --- a/src/Sts/Result/AssumeRoleWithWebIdentityResponse.php +++ b/src/Sts/Result/AssumeRoleWithWebIdentityResponse.php @@ -147,20 +147,30 @@ protected function populateResult(Response $response): void $data = new \SimpleXMLElement($response->getContent()); $data = $data->AssumeRoleWithWebIdentityResult; - $this->credentials = !$data->Credentials ? null : new Credentials([ - 'AccessKeyId' => (string) $data->Credentials->AccessKeyId, - 'SecretAccessKey' => (string) $data->Credentials->SecretAccessKey, - 'SessionToken' => (string) $data->Credentials->SessionToken, - 'Expiration' => new \DateTimeImmutable((string) $data->Credentials->Expiration), + $this->credentials = 0 === $data->Credentials->count() ? null : $this->populateResultCredentials($data->Credentials); + $this->subjectFromWebIdentityToken = (null !== $v = $data->SubjectFromWebIdentityToken[0]) ? (string) $v : null; + $this->assumedRoleUser = 0 === $data->AssumedRoleUser->count() ? null : $this->populateResultAssumedRoleUser($data->AssumedRoleUser); + $this->packedPolicySize = (null !== $v = $data->PackedPolicySize[0]) ? (int) (string) $v : null; + $this->provider = (null !== $v = $data->Provider[0]) ? (string) $v : null; + $this->audience = (null !== $v = $data->Audience[0]) ? (string) $v : null; + $this->sourceIdentity = (null !== $v = $data->SourceIdentity[0]) ? (string) $v : null; + } + + private function populateResultAssumedRoleUser(\SimpleXMLElement $xml): AssumedRoleUser + { + return new AssumedRoleUser([ + 'AssumedRoleId' => (string) $xml->AssumedRoleId, + 'Arn' => (string) $xml->Arn, ]); - $this->subjectFromWebIdentityToken = ($v = $data->SubjectFromWebIdentityToken) ? (string) $v : null; - $this->assumedRoleUser = !$data->AssumedRoleUser ? null : new AssumedRoleUser([ - 'AssumedRoleId' => (string) $data->AssumedRoleUser->AssumedRoleId, - 'Arn' => (string) $data->AssumedRoleUser->Arn, + } + + private function populateResultCredentials(\SimpleXMLElement $xml): Credentials + { + return new Credentials([ + 'AccessKeyId' => (string) $xml->AccessKeyId, + 'SecretAccessKey' => (string) $xml->SecretAccessKey, + 'SessionToken' => (string) $xml->SessionToken, + 'Expiration' => new \DateTimeImmutable((string) $xml->Expiration), ]); - $this->packedPolicySize = ($v = $data->PackedPolicySize) ? (int) (string) $v : null; - $this->provider = ($v = $data->Provider) ? (string) $v : null; - $this->audience = ($v = $data->Audience) ? (string) $v : null; - $this->sourceIdentity = ($v = $data->SourceIdentity) ? (string) $v : null; } } diff --git a/src/Sts/Result/GetCallerIdentityResponse.php b/src/Sts/Result/GetCallerIdentityResponse.php index 1be6711..9c59292 100644 --- a/src/Sts/Result/GetCallerIdentityResponse.php +++ b/src/Sts/Result/GetCallerIdentityResponse.php @@ -62,8 +62,8 @@ protected function populateResult(Response $response): void $data = new \SimpleXMLElement($response->getContent()); $data = $data->GetCallerIdentityResult; - $this->userId = ($v = $data->UserId) ? (string) $v : null; - $this->account = ($v = $data->Account) ? (string) $v : null; - $this->arn = ($v = $data->Arn) ? (string) $v : null; + $this->userId = (null !== $v = $data->UserId[0]) ? (string) $v : null; + $this->account = (null !== $v = $data->Account[0]) ? (string) $v : null; + $this->arn = (null !== $v = $data->Arn[0]) ? (string) $v : null; } }