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 4f6ab2a commit 4533682
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 74 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## NOT RELEASED

### Changed

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

## 1.5.3

### Changed
Expand Down
17 changes: 11 additions & 6 deletions src/Result/CreateAccessKeyResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,17 @@ protected function populateResult(Response $response): void
$data = new \SimpleXMLElement($response->getContent());
$data = $data->CreateAccessKeyResult;

$this->accessKey = new AccessKey([
'UserName' => (string) $data->AccessKey->UserName,
'AccessKeyId' => (string) $data->AccessKey->AccessKeyId,
'Status' => (string) $data->AccessKey->Status,
'SecretAccessKey' => (string) $data->AccessKey->SecretAccessKey,
'CreateDate' => ($v = $data->AccessKey->CreateDate) ? new \DateTimeImmutable((string) $v) : null,
$this->accessKey = $this->populateResultAccessKey($data->AccessKey);
}

private function populateResultAccessKey(\SimpleXMLElement $xml): AccessKey
{
return new AccessKey([
'UserName' => (string) $xml->UserName,
'AccessKeyId' => (string) $xml->AccessKeyId,
'Status' => (string) $xml->Status,
'SecretAccessKey' => (string) $xml->SecretAccessKey,
'CreateDate' => (null !== $v = $xml->CreateDate[0]) ? new \DateTimeImmutable((string) $v) : null,
]);
}
}
21 changes: 13 additions & 8 deletions src/Result/CreateServiceSpecificCredentialResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@ protected function populateResult(Response $response): void
$data = new \SimpleXMLElement($response->getContent());
$data = $data->CreateServiceSpecificCredentialResult;

$this->serviceSpecificCredential = !$data->ServiceSpecificCredential ? null : new ServiceSpecificCredential([
'CreateDate' => new \DateTimeImmutable((string) $data->ServiceSpecificCredential->CreateDate),
'ServiceName' => (string) $data->ServiceSpecificCredential->ServiceName,
'ServiceUserName' => (string) $data->ServiceSpecificCredential->ServiceUserName,
'ServicePassword' => (string) $data->ServiceSpecificCredential->ServicePassword,
'ServiceSpecificCredentialId' => (string) $data->ServiceSpecificCredential->ServiceSpecificCredentialId,
'UserName' => (string) $data->ServiceSpecificCredential->UserName,
'Status' => (string) $data->ServiceSpecificCredential->Status,
$this->serviceSpecificCredential = 0 === $data->ServiceSpecificCredential->count() ? null : $this->populateResultServiceSpecificCredential($data->ServiceSpecificCredential);
}

private function populateResultServiceSpecificCredential(\SimpleXMLElement $xml): ServiceSpecificCredential
{
return new ServiceSpecificCredential([
'CreateDate' => new \DateTimeImmutable((string) $xml->CreateDate),
'ServiceName' => (string) $xml->ServiceName,
'ServiceUserName' => (string) $xml->ServiceUserName,
'ServicePassword' => (string) $xml->ServicePassword,
'ServiceSpecificCredentialId' => (string) $xml->ServiceSpecificCredentialId,
'UserName' => (string) $xml->UserName,
'Status' => (string) $xml->Status,
]);
}
}
47 changes: 31 additions & 16 deletions src/Result/CreateUserResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,22 @@ protected function populateResult(Response $response): void
$data = new \SimpleXMLElement($response->getContent());
$data = $data->CreateUserResult;

$this->user = !$data->User ? null : new User([
'Path' => (string) $data->User->Path,
'UserName' => (string) $data->User->UserName,
'UserId' => (string) $data->User->UserId,
'Arn' => (string) $data->User->Arn,
'CreateDate' => new \DateTimeImmutable((string) $data->User->CreateDate),
'PasswordLastUsed' => ($v = $data->User->PasswordLastUsed) ? new \DateTimeImmutable((string) $v) : null,
'PermissionsBoundary' => !$data->User->PermissionsBoundary ? null : new AttachedPermissionsBoundary([
'PermissionsBoundaryType' => ($v = $data->User->PermissionsBoundary->PermissionsBoundaryType) ? (string) $v : null,
'PermissionsBoundaryArn' => ($v = $data->User->PermissionsBoundary->PermissionsBoundaryArn) ? (string) $v : null,
]),
'Tags' => !$data->User->Tags ? null : $this->populateResultTagListType($data->User->Tags),
$this->user = 0 === $data->User->count() ? null : $this->populateResultUser($data->User);
}

private function populateResultAttachedPermissionsBoundary(\SimpleXMLElement $xml): AttachedPermissionsBoundary
{
return new AttachedPermissionsBoundary([
'PermissionsBoundaryType' => (null !== $v = $xml->PermissionsBoundaryType[0]) ? (string) $v : null,
'PermissionsBoundaryArn' => (null !== $v = $xml->PermissionsBoundaryArn[0]) ? (string) $v : null,
]);
}

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

Expand All @@ -54,12 +58,23 @@ private function populateResultTagListType(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml->member as $item) {
$items[] = new Tag([
'Key' => (string) $item->Key,
'Value' => (string) $item->Value,
]);
$items[] = $this->populateResultTag($item);
}

return $items;
}

private function populateResultUser(\SimpleXMLElement $xml): User
{
return new User([
'Path' => (string) $xml->Path,
'UserName' => (string) $xml->UserName,
'UserId' => (string) $xml->UserId,
'Arn' => (string) $xml->Arn,
'CreateDate' => new \DateTimeImmutable((string) $xml->CreateDate),
'PasswordLastUsed' => (null !== $v = $xml->PasswordLastUsed[0]) ? new \DateTimeImmutable((string) $v) : null,
'PermissionsBoundary' => 0 === $xml->PermissionsBoundary->count() ? null : $this->populateResultAttachedPermissionsBoundary($xml->PermissionsBoundary),
'Tags' => (0 === ($v = $xml->Tags)->count()) ? null : $this->populateResultTagListType($v),
]);
}
}
47 changes: 31 additions & 16 deletions src/Result/GetUserResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ protected function populateResult(Response $response): void
$data = new \SimpleXMLElement($response->getContent());
$data = $data->GetUserResult;

$this->user = new User([
'Path' => (string) $data->User->Path,
'UserName' => (string) $data->User->UserName,
'UserId' => (string) $data->User->UserId,
'Arn' => (string) $data->User->Arn,
'CreateDate' => new \DateTimeImmutable((string) $data->User->CreateDate),
'PasswordLastUsed' => ($v = $data->User->PasswordLastUsed) ? new \DateTimeImmutable((string) $v) : null,
'PermissionsBoundary' => !$data->User->PermissionsBoundary ? null : new AttachedPermissionsBoundary([
'PermissionsBoundaryType' => ($v = $data->User->PermissionsBoundary->PermissionsBoundaryType) ? (string) $v : null,
'PermissionsBoundaryArn' => ($v = $data->User->PermissionsBoundary->PermissionsBoundaryArn) ? (string) $v : null,
]),
'Tags' => !$data->User->Tags ? null : $this->populateResultTagListType($data->User->Tags),
$this->user = $this->populateResultUser($data->User);
}

private function populateResultAttachedPermissionsBoundary(\SimpleXMLElement $xml): AttachedPermissionsBoundary
{
return new AttachedPermissionsBoundary([
'PermissionsBoundaryType' => (null !== $v = $xml->PermissionsBoundaryType[0]) ? (string) $v : null,
'PermissionsBoundaryArn' => (null !== $v = $xml->PermissionsBoundaryArn[0]) ? (string) $v : null,
]);
}

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

Expand All @@ -69,12 +73,23 @@ private function populateResultTagListType(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml->member as $item) {
$items[] = new Tag([
'Key' => (string) $item->Key,
'Value' => (string) $item->Value,
]);
$items[] = $this->populateResultTag($item);
}

return $items;
}

private function populateResultUser(\SimpleXMLElement $xml): User
{
return new User([
'Path' => (string) $xml->Path,
'UserName' => (string) $xml->UserName,
'UserId' => (string) $xml->UserId,
'Arn' => (string) $xml->Arn,
'CreateDate' => new \DateTimeImmutable((string) $xml->CreateDate),
'PasswordLastUsed' => (null !== $v = $xml->PasswordLastUsed[0]) ? new \DateTimeImmutable((string) $v) : null,
'PermissionsBoundary' => 0 === $xml->PermissionsBoundary->count() ? null : $this->populateResultAttachedPermissionsBoundary($xml->PermissionsBoundary),
'Tags' => (0 === ($v = $xml->Tags)->count()) ? null : $this->populateResultTagListType($v),
]);
}
}
23 changes: 14 additions & 9 deletions src/Result/ListServiceSpecificCredentialsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,19 @@ protected function populateResult(Response $response): void
$data = new \SimpleXMLElement($response->getContent());
$data = $data->ListServiceSpecificCredentialsResult;

$this->serviceSpecificCredentials = !$data->ServiceSpecificCredentials ? [] : $this->populateResultServiceSpecificCredentialsListType($data->ServiceSpecificCredentials);
$this->serviceSpecificCredentials = (0 === ($v = $data->ServiceSpecificCredentials)->count()) ? [] : $this->populateResultServiceSpecificCredentialsListType($v);
}

private function populateResultServiceSpecificCredentialMetadata(\SimpleXMLElement $xml): ServiceSpecificCredentialMetadata
{
return new ServiceSpecificCredentialMetadata([
'UserName' => (string) $xml->UserName,
'Status' => (string) $xml->Status,
'ServiceUserName' => (string) $xml->ServiceUserName,
'CreateDate' => new \DateTimeImmutable((string) $xml->CreateDate),
'ServiceSpecificCredentialId' => (string) $xml->ServiceSpecificCredentialId,
'ServiceName' => (string) $xml->ServiceName,
]);
}

/**
Expand All @@ -40,14 +52,7 @@ private function populateResultServiceSpecificCredentialsListType(\SimpleXMLElem
{
$items = [];
foreach ($xml->member as $item) {
$items[] = new ServiceSpecificCredentialMetadata([
'UserName' => (string) $item->UserName,
'Status' => (string) $item->Status,
'ServiceUserName' => (string) $item->ServiceUserName,
'CreateDate' => new \DateTimeImmutable((string) $item->CreateDate),
'ServiceSpecificCredentialId' => (string) $item->ServiceSpecificCredentialId,
'ServiceName' => (string) $item->ServiceName,
]);
$items[] = $this->populateResultServiceSpecificCredentialMetadata($item);
}

return $items;
Expand Down
53 changes: 34 additions & 19 deletions src/Result/ListUsersResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,24 @@ protected function populateResult(Response $response): void
$data = $data->ListUsersResult;

$this->users = $this->populateResultUserListType($data->Users);
$this->isTruncated = ($v = $data->IsTruncated) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null;
$this->marker = ($v = $data->Marker) ? (string) $v : null;
$this->isTruncated = (null !== $v = $data->IsTruncated[0]) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null;
$this->marker = (null !== $v = $data->Marker[0]) ? (string) $v : null;
}

private function populateResultAttachedPermissionsBoundary(\SimpleXMLElement $xml): AttachedPermissionsBoundary
{
return new AttachedPermissionsBoundary([
'PermissionsBoundaryType' => (null !== $v = $xml->PermissionsBoundaryType[0]) ? (string) $v : null,
'PermissionsBoundaryArn' => (null !== $v = $xml->PermissionsBoundaryArn[0]) ? (string) $v : null,
]);
}

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

/**
Expand All @@ -128,35 +144,34 @@ private function populateResultTagListType(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml->member as $item) {
$items[] = new Tag([
'Key' => (string) $item->Key,
'Value' => (string) $item->Value,
]);
$items[] = $this->populateResultTag($item);
}

return $items;
}

private function populateResultUser(\SimpleXMLElement $xml): User
{
return new User([
'Path' => (string) $xml->Path,
'UserName' => (string) $xml->UserName,
'UserId' => (string) $xml->UserId,
'Arn' => (string) $xml->Arn,
'CreateDate' => new \DateTimeImmutable((string) $xml->CreateDate),
'PasswordLastUsed' => (null !== $v = $xml->PasswordLastUsed[0]) ? new \DateTimeImmutable((string) $v) : null,
'PermissionsBoundary' => 0 === $xml->PermissionsBoundary->count() ? null : $this->populateResultAttachedPermissionsBoundary($xml->PermissionsBoundary),
'Tags' => (0 === ($v = $xml->Tags)->count()) ? null : $this->populateResultTagListType($v),
]);
}

/**
* @return User[]
*/
private function populateResultUserListType(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml->member as $item) {
$items[] = new User([
'Path' => (string) $item->Path,
'UserName' => (string) $item->UserName,
'UserId' => (string) $item->UserId,
'Arn' => (string) $item->Arn,
'CreateDate' => new \DateTimeImmutable((string) $item->CreateDate),
'PasswordLastUsed' => ($v = $item->PasswordLastUsed) ? new \DateTimeImmutable((string) $v) : null,
'PermissionsBoundary' => !$item->PermissionsBoundary ? null : new AttachedPermissionsBoundary([
'PermissionsBoundaryType' => ($v = $item->PermissionsBoundary->PermissionsBoundaryType) ? (string) $v : null,
'PermissionsBoundaryArn' => ($v = $item->PermissionsBoundary->PermissionsBoundaryArn) ? (string) $v : null,
]),
'Tags' => !$item->Tags ? null : $this->populateResultTagListType($item->Tags),
]);
$items[] = $this->populateResultUser($item);
}

return $items;
Expand Down

0 comments on commit 4533682

Please sign in to comment.