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 c756ece commit 80c2e57
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

### Changed

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

## 1.22.1
Expand Down
2 changes: 1 addition & 1 deletion src/Signer/SignerV4.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ private function buildCanonicalQuery(Request $request): string
$query = $request->getQuery();

unset($query['X-Amz-Signature']);
if (!$query) {
if (empty($query)) {
return '';
}

Expand Down
30 changes: 20 additions & 10 deletions src/Sts/Result/AssumeRoleResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
36 changes: 23 additions & 13 deletions src/Sts/Result/AssumeRoleWithWebIdentityResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
6 changes: 3 additions & 3 deletions src/Sts/Result/GetCallerIdentityResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 80c2e57

Please sign in to comment.