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 7f84c77 commit ce65007
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 121 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: This release adds support for TLSA, SSHFP, SVCB, and HTTPS record types.

### Changed

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

## 2.4.0

### Added
Expand Down
7 changes: 2 additions & 5 deletions src/Exception/InvalidChangeBatchException.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected function populateResult(ResponseInterface $response): void
if (0 < $data->Error->count()) {
$data = $data->Error;
}
$this->messages = !$data->messages ? [] : $this->populateResultErrorMessages($data->messages);
$this->messages = (0 === ($v = $data->messages)->count()) ? [] : $this->populateResultErrorMessages($v);
}

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

return $items;
Expand Down
15 changes: 10 additions & 5 deletions src/Result/ChangeResourceRecordSetsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,16 @@ public function getChangeInfo(): ChangeInfo
protected function populateResult(Response $response): void
{
$data = new \SimpleXMLElement($response->getContent());
$this->changeInfo = new ChangeInfo([
'Id' => (string) $data->ChangeInfo->Id,
'Status' => (string) $data->ChangeInfo->Status,
'SubmittedAt' => new \DateTimeImmutable((string) $data->ChangeInfo->SubmittedAt),
'Comment' => ($v = $data->ChangeInfo->Comment) ? (string) $v : null,
$this->changeInfo = $this->populateResultChangeInfo($data->ChangeInfo);
}

private function populateResultChangeInfo(\SimpleXMLElement $xml): ChangeInfo
{
return new ChangeInfo([
'Id' => (string) $xml->Id,
'Status' => (string) $xml->Status,
'SubmittedAt' => new \DateTimeImmutable((string) $xml->SubmittedAt),
'Comment' => (null !== $v = $xml->Comment[0]) ? (string) $v : null,
]);
}
}
89 changes: 58 additions & 31 deletions src/Result/CreateHostedZoneResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,34 +93,28 @@ protected function populateResult(Response $response): void
$this->location = $headers['location'][0] ?? null;

$data = new \SimpleXMLElement($response->getContent());
$this->hostedZone = new HostedZone([
'Id' => (string) $data->HostedZone->Id,
'Name' => (string) $data->HostedZone->Name,
'CallerReference' => (string) $data->HostedZone->CallerReference,
'Config' => !$data->HostedZone->Config ? null : new HostedZoneConfig([
'Comment' => ($v = $data->HostedZone->Config->Comment) ? (string) $v : null,
'PrivateZone' => ($v = $data->HostedZone->Config->PrivateZone) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
]),
'ResourceRecordSetCount' => ($v = $data->HostedZone->ResourceRecordSetCount) ? (int) (string) $v : null,
'LinkedService' => !$data->HostedZone->LinkedService ? null : new LinkedService([
'ServicePrincipal' => ($v = $data->HostedZone->LinkedService->ServicePrincipal) ? (string) $v : null,
'Description' => ($v = $data->HostedZone->LinkedService->Description) ? (string) $v : null,
]),
]);
$this->changeInfo = new ChangeInfo([
'Id' => (string) $data->ChangeInfo->Id,
'Status' => (string) $data->ChangeInfo->Status,
'SubmittedAt' => new \DateTimeImmutable((string) $data->ChangeInfo->SubmittedAt),
'Comment' => ($v = $data->ChangeInfo->Comment) ? (string) $v : null,
]);
$this->delegationSet = new DelegationSet([
'Id' => ($v = $data->DelegationSet->Id) ? (string) $v : null,
'CallerReference' => ($v = $data->DelegationSet->CallerReference) ? (string) $v : null,
'NameServers' => $this->populateResultDelegationSetNameServers($data->DelegationSet->NameServers),
$this->hostedZone = $this->populateResultHostedZone($data->HostedZone);
$this->changeInfo = $this->populateResultChangeInfo($data->ChangeInfo);
$this->delegationSet = $this->populateResultDelegationSet($data->DelegationSet);
$this->vpc = 0 === $data->VPC->count() ? null : $this->populateResultVPC($data->VPC);
}

private function populateResultChangeInfo(\SimpleXMLElement $xml): ChangeInfo
{
return new ChangeInfo([
'Id' => (string) $xml->Id,
'Status' => (string) $xml->Status,
'SubmittedAt' => new \DateTimeImmutable((string) $xml->SubmittedAt),
'Comment' => (null !== $v = $xml->Comment[0]) ? (string) $v : null,
]);
$this->vpc = !$data->VPC ? null : new VPC([
'VPCRegion' => ($v = $data->VPC->VPCRegion) ? (string) $v : null,
'VPCId' => ($v = $data->VPC->VPCId) ? (string) $v : null,
}

private function populateResultDelegationSet(\SimpleXMLElement $xml): DelegationSet
{
return new DelegationSet([
'Id' => (null !== $v = $xml->Id[0]) ? (string) $v : null,
'CallerReference' => (null !== $v = $xml->CallerReference[0]) ? (string) $v : null,
'NameServers' => $this->populateResultDelegationSetNameServers($xml->NameServers),
]);
}

Expand All @@ -131,12 +125,45 @@ private function populateResultDelegationSetNameServers(\SimpleXMLElement $xml):
{
$items = [];
foreach ($xml->NameServer as $item) {
$a = ($v = $item) ? (string) $v : null;
if (null !== $a) {
$items[] = $a;
}
$items[] = (string) $item;
}

return $items;
}

private function populateResultHostedZone(\SimpleXMLElement $xml): HostedZone
{
return new HostedZone([
'Id' => (string) $xml->Id,
'Name' => (string) $xml->Name,
'CallerReference' => (string) $xml->CallerReference,
'Config' => 0 === $xml->Config->count() ? null : $this->populateResultHostedZoneConfig($xml->Config),
'ResourceRecordSetCount' => (null !== $v = $xml->ResourceRecordSetCount[0]) ? (int) (string) $v : null,
'LinkedService' => 0 === $xml->LinkedService->count() ? null : $this->populateResultLinkedService($xml->LinkedService),
]);
}

private function populateResultHostedZoneConfig(\SimpleXMLElement $xml): HostedZoneConfig
{
return new HostedZoneConfig([
'Comment' => (null !== $v = $xml->Comment[0]) ? (string) $v : null,
'PrivateZone' => (null !== $v = $xml->PrivateZone[0]) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
]);
}

private function populateResultLinkedService(\SimpleXMLElement $xml): LinkedService
{
return new LinkedService([
'ServicePrincipal' => (null !== $v = $xml->ServicePrincipal[0]) ? (string) $v : null,
'Description' => (null !== $v = $xml->Description[0]) ? (string) $v : null,
]);
}

private function populateResultVPC(\SimpleXMLElement $xml): VPC
{
return new VPC([
'VPCRegion' => (null !== $v = $xml->VPCRegion[0]) ? (string) $v : null,
'VPCId' => (null !== $v = $xml->VPCId[0]) ? (string) $v : null,
]);
}
}
15 changes: 10 additions & 5 deletions src/Result/DeleteHostedZoneResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,16 @@ public function getChangeInfo(): ChangeInfo
protected function populateResult(Response $response): void
{
$data = new \SimpleXMLElement($response->getContent());
$this->changeInfo = new ChangeInfo([
'Id' => (string) $data->ChangeInfo->Id,
'Status' => (string) $data->ChangeInfo->Status,
'SubmittedAt' => new \DateTimeImmutable((string) $data->ChangeInfo->SubmittedAt),
'Comment' => ($v = $data->ChangeInfo->Comment) ? (string) $v : null,
$this->changeInfo = $this->populateResultChangeInfo($data->ChangeInfo);
}

private function populateResultChangeInfo(\SimpleXMLElement $xml): ChangeInfo
{
return new ChangeInfo([
'Id' => (string) $xml->Id,
'Status' => (string) $xml->Status,
'SubmittedAt' => new \DateTimeImmutable((string) $xml->SubmittedAt),
'Comment' => (null !== $v = $xml->Comment[0]) ? (string) $v : null,
]);
}
}
51 changes: 33 additions & 18 deletions src/Result/ListHostedZonesByNameResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,37 +130,52 @@ protected function populateResult(Response $response): void
{
$data = new \SimpleXMLElement($response->getContent());
$this->hostedZones = $this->populateResultHostedZones($data->HostedZones);
$this->dnsName = ($v = $data->DNSName) ? (string) $v : null;
$this->hostedZoneId = ($v = $data->HostedZoneId) ? (string) $v : null;
$this->dnsName = (null !== $v = $data->DNSName[0]) ? (string) $v : null;
$this->hostedZoneId = (null !== $v = $data->HostedZoneId[0]) ? (string) $v : null;
$this->isTruncated = filter_var((string) $data->IsTruncated, \FILTER_VALIDATE_BOOLEAN);
$this->nextDnsName = ($v = $data->NextDNSName) ? (string) $v : null;
$this->nextHostedZoneId = ($v = $data->NextHostedZoneId) ? (string) $v : null;
$this->nextDnsName = (null !== $v = $data->NextDNSName[0]) ? (string) $v : null;
$this->nextHostedZoneId = (null !== $v = $data->NextHostedZoneId[0]) ? (string) $v : null;
$this->maxItems = (string) $data->MaxItems;
}

private function populateResultHostedZone(\SimpleXMLElement $xml): HostedZone
{
return new HostedZone([
'Id' => (string) $xml->Id,
'Name' => (string) $xml->Name,
'CallerReference' => (string) $xml->CallerReference,
'Config' => 0 === $xml->Config->count() ? null : $this->populateResultHostedZoneConfig($xml->Config),
'ResourceRecordSetCount' => (null !== $v = $xml->ResourceRecordSetCount[0]) ? (int) (string) $v : null,
'LinkedService' => 0 === $xml->LinkedService->count() ? null : $this->populateResultLinkedService($xml->LinkedService),
]);
}

private function populateResultHostedZoneConfig(\SimpleXMLElement $xml): HostedZoneConfig
{
return new HostedZoneConfig([
'Comment' => (null !== $v = $xml->Comment[0]) ? (string) $v : null,
'PrivateZone' => (null !== $v = $xml->PrivateZone[0]) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
]);
}

/**
* @return HostedZone[]
*/
private function populateResultHostedZones(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml->HostedZone as $item) {
$items[] = new HostedZone([
'Id' => (string) $item->Id,
'Name' => (string) $item->Name,
'CallerReference' => (string) $item->CallerReference,
'Config' => !$item->Config ? null : new HostedZoneConfig([
'Comment' => ($v = $item->Config->Comment) ? (string) $v : null,
'PrivateZone' => ($v = $item->Config->PrivateZone) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
]),
'ResourceRecordSetCount' => ($v = $item->ResourceRecordSetCount) ? (int) (string) $v : null,
'LinkedService' => !$item->LinkedService ? null : new LinkedService([
'ServicePrincipal' => ($v = $item->LinkedService->ServicePrincipal) ? (string) $v : null,
'Description' => ($v = $item->LinkedService->Description) ? (string) $v : null,
]),
]);
$items[] = $this->populateResultHostedZone($item);
}

return $items;
}

private function populateResultLinkedService(\SimpleXMLElement $xml): LinkedService
{
return new LinkedService([
'ServicePrincipal' => (null !== $v = $xml->ServicePrincipal[0]) ? (string) $v : null,
'Description' => (null !== $v = $xml->Description[0]) ? (string) $v : null,
]);
}
}
45 changes: 30 additions & 15 deletions src/Result/ListHostedZonesResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,33 +147,48 @@ protected function populateResult(Response $response): void
$this->hostedZones = $this->populateResultHostedZones($data->HostedZones);
$this->marker = (string) $data->Marker;
$this->isTruncated = filter_var((string) $data->IsTruncated, \FILTER_VALIDATE_BOOLEAN);
$this->nextMarker = ($v = $data->NextMarker) ? (string) $v : null;
$this->nextMarker = (null !== $v = $data->NextMarker[0]) ? (string) $v : null;
$this->maxItems = (string) $data->MaxItems;
}

private function populateResultHostedZone(\SimpleXMLElement $xml): HostedZone
{
return new HostedZone([
'Id' => (string) $xml->Id,
'Name' => (string) $xml->Name,
'CallerReference' => (string) $xml->CallerReference,
'Config' => 0 === $xml->Config->count() ? null : $this->populateResultHostedZoneConfig($xml->Config),
'ResourceRecordSetCount' => (null !== $v = $xml->ResourceRecordSetCount[0]) ? (int) (string) $v : null,
'LinkedService' => 0 === $xml->LinkedService->count() ? null : $this->populateResultLinkedService($xml->LinkedService),
]);
}

private function populateResultHostedZoneConfig(\SimpleXMLElement $xml): HostedZoneConfig
{
return new HostedZoneConfig([
'Comment' => (null !== $v = $xml->Comment[0]) ? (string) $v : null,
'PrivateZone' => (null !== $v = $xml->PrivateZone[0]) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
]);
}

/**
* @return HostedZone[]
*/
private function populateResultHostedZones(\SimpleXMLElement $xml): array
{
$items = [];
foreach ($xml->HostedZone as $item) {
$items[] = new HostedZone([
'Id' => (string) $item->Id,
'Name' => (string) $item->Name,
'CallerReference' => (string) $item->CallerReference,
'Config' => !$item->Config ? null : new HostedZoneConfig([
'Comment' => ($v = $item->Config->Comment) ? (string) $v : null,
'PrivateZone' => ($v = $item->Config->PrivateZone) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
]),
'ResourceRecordSetCount' => ($v = $item->ResourceRecordSetCount) ? (int) (string) $v : null,
'LinkedService' => !$item->LinkedService ? null : new LinkedService([
'ServicePrincipal' => ($v = $item->LinkedService->ServicePrincipal) ? (string) $v : null,
'Description' => ($v = $item->LinkedService->Description) ? (string) $v : null,
]),
]);
$items[] = $this->populateResultHostedZone($item);
}

return $items;
}

private function populateResultLinkedService(\SimpleXMLElement $xml): LinkedService
{
return new LinkedService([
'ServicePrincipal' => (null !== $v = $xml->ServicePrincipal[0]) ? (string) $v : null,
'Description' => (null !== $v = $xml->Description[0]) ? (string) $v : null,
]);
}
}
Loading

0 comments on commit ce65007

Please sign in to comment.