Skip to content

Commit ad0f5b9

Browse files
authored
Add strict comparison null !== instead of ! (#1794)
1 parent 19add33 commit ad0f5b9

4 files changed

+124
-89
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Changed
66

7+
- use strict comparison `null !==` instead of `!`
78
- AWS enhancement: Documentation updates.
89

910
## 1.7.1

src/Result/DescribeStackDriftDetectionStatusOutput.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ protected function populateResult(Response $response): void
139139

140140
$this->stackId = (string) $data->StackId;
141141
$this->stackDriftDetectionId = (string) $data->StackDriftDetectionId;
142-
$this->stackDriftStatus = ($v = $data->StackDriftStatus) ? (string) $v : null;
142+
$this->stackDriftStatus = (null !== $v = $data->StackDriftStatus[0]) ? (string) $v : null;
143143
$this->detectionStatus = (string) $data->DetectionStatus;
144-
$this->detectionStatusReason = ($v = $data->DetectionStatusReason) ? (string) $v : null;
145-
$this->driftedStackResourceCount = ($v = $data->DriftedStackResourceCount) ? (int) (string) $v : null;
144+
$this->detectionStatusReason = (null !== $v = $data->DetectionStatusReason[0]) ? (string) $v : null;
145+
$this->driftedStackResourceCount = (null !== $v = $data->DriftedStackResourceCount[0]) ? (int) (string) $v : null;
146146
$this->timestamp = new \DateTimeImmutable((string) $data->Timestamp);
147147
}
148148
}

src/Result/DescribeStackEventsOutput.php

+27-22
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function getStackEvents(bool $currentPageOnly = false): iterable
7373
$page = $this;
7474
while (true) {
7575
$page->initialize();
76-
if ($page->nextToken) {
76+
if (null !== $page->nextToken) {
7777
$input->setNextToken($page->nextToken);
7878

7979
$this->registerPrefetch($nextPage = $client->describeStackEvents($input));
@@ -97,8 +97,31 @@ protected function populateResult(Response $response): void
9797
$data = new \SimpleXMLElement($response->getContent());
9898
$data = $data->DescribeStackEventsResult;
9999

100-
$this->stackEvents = !$data->StackEvents ? [] : $this->populateResultStackEvents($data->StackEvents);
101-
$this->nextToken = ($v = $data->NextToken) ? (string) $v : null;
100+
$this->stackEvents = (0 === ($v = $data->StackEvents)->count()) ? [] : $this->populateResultStackEvents($v);
101+
$this->nextToken = (null !== $v = $data->NextToken[0]) ? (string) $v : null;
102+
}
103+
104+
private function populateResultStackEvent(\SimpleXMLElement $xml): StackEvent
105+
{
106+
return new StackEvent([
107+
'StackId' => (string) $xml->StackId,
108+
'EventId' => (string) $xml->EventId,
109+
'StackName' => (string) $xml->StackName,
110+
'LogicalResourceId' => (null !== $v = $xml->LogicalResourceId[0]) ? (string) $v : null,
111+
'PhysicalResourceId' => (null !== $v = $xml->PhysicalResourceId[0]) ? (string) $v : null,
112+
'ResourceType' => (null !== $v = $xml->ResourceType[0]) ? (string) $v : null,
113+
'Timestamp' => new \DateTimeImmutable((string) $xml->Timestamp),
114+
'ResourceStatus' => (null !== $v = $xml->ResourceStatus[0]) ? (string) $v : null,
115+
'ResourceStatusReason' => (null !== $v = $xml->ResourceStatusReason[0]) ? (string) $v : null,
116+
'ResourceProperties' => (null !== $v = $xml->ResourceProperties[0]) ? (string) $v : null,
117+
'ClientRequestToken' => (null !== $v = $xml->ClientRequestToken[0]) ? (string) $v : null,
118+
'HookType' => (null !== $v = $xml->HookType[0]) ? (string) $v : null,
119+
'HookStatus' => (null !== $v = $xml->HookStatus[0]) ? (string) $v : null,
120+
'HookStatusReason' => (null !== $v = $xml->HookStatusReason[0]) ? (string) $v : null,
121+
'HookInvocationPoint' => (null !== $v = $xml->HookInvocationPoint[0]) ? (string) $v : null,
122+
'HookFailureMode' => (null !== $v = $xml->HookFailureMode[0]) ? (string) $v : null,
123+
'DetailedStatus' => (null !== $v = $xml->DetailedStatus[0]) ? (string) $v : null,
124+
]);
102125
}
103126

104127
/**
@@ -108,25 +131,7 @@ private function populateResultStackEvents(\SimpleXMLElement $xml): array
108131
{
109132
$items = [];
110133
foreach ($xml->member as $item) {
111-
$items[] = new StackEvent([
112-
'StackId' => (string) $item->StackId,
113-
'EventId' => (string) $item->EventId,
114-
'StackName' => (string) $item->StackName,
115-
'LogicalResourceId' => ($v = $item->LogicalResourceId) ? (string) $v : null,
116-
'PhysicalResourceId' => ($v = $item->PhysicalResourceId) ? (string) $v : null,
117-
'ResourceType' => ($v = $item->ResourceType) ? (string) $v : null,
118-
'Timestamp' => new \DateTimeImmutable((string) $item->Timestamp),
119-
'ResourceStatus' => ($v = $item->ResourceStatus) ? (string) $v : null,
120-
'ResourceStatusReason' => ($v = $item->ResourceStatusReason) ? (string) $v : null,
121-
'ResourceProperties' => ($v = $item->ResourceProperties) ? (string) $v : null,
122-
'ClientRequestToken' => ($v = $item->ClientRequestToken) ? (string) $v : null,
123-
'HookType' => ($v = $item->HookType) ? (string) $v : null,
124-
'HookStatus' => ($v = $item->HookStatus) ? (string) $v : null,
125-
'HookStatusReason' => ($v = $item->HookStatusReason) ? (string) $v : null,
126-
'HookInvocationPoint' => ($v = $item->HookInvocationPoint) ? (string) $v : null,
127-
'HookFailureMode' => ($v = $item->HookFailureMode) ? (string) $v : null,
128-
'DetailedStatus' => ($v = $item->DetailedStatus) ? (string) $v : null,
129-
]);
134+
$items[] = $this->populateResultStackEvent($item);
130135
}
131136

132137
return $items;

src/Result/DescribeStacksOutput.php

+93-64
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function getStacks(bool $currentPageOnly = false): iterable
8080
$page = $this;
8181
while (true) {
8282
$page->initialize();
83-
if ($page->nextToken) {
83+
if (null !== $page->nextToken) {
8484
$input->setNextToken($page->nextToken);
8585

8686
$this->registerPrefetch($nextPage = $client->describeStacks($input));
@@ -104,8 +104,8 @@ protected function populateResult(Response $response): void
104104
$data = new \SimpleXMLElement($response->getContent());
105105
$data = $data->DescribeStacksResult;
106106

107-
$this->stacks = !$data->Stacks ? [] : $this->populateResultStacks($data->Stacks);
108-
$this->nextToken = ($v = $data->NextToken) ? (string) $v : null;
107+
$this->stacks = (0 === ($v = $data->Stacks)->count()) ? [] : $this->populateResultStacks($v);
108+
$this->nextToken = (null !== $v = $data->NextToken[0]) ? (string) $v : null;
109109
}
110110

111111
/**
@@ -115,10 +115,7 @@ private function populateResultCapabilities(\SimpleXMLElement $xml): array
115115
{
116116
$items = [];
117117
foreach ($xml->member as $item) {
118-
$a = ($v = $item) ? (string) $v : null;
119-
if (null !== $a) {
120-
$items[] = $a;
121-
}
118+
$items[] = (string) $item;
122119
}
123120

124121
return $items;
@@ -131,123 +128,155 @@ private function populateResultNotificationARNs(\SimpleXMLElement $xml): array
131128
{
132129
$items = [];
133130
foreach ($xml->member as $item) {
134-
$a = ($v = $item) ? (string) $v : null;
135-
if (null !== $a) {
136-
$items[] = $a;
137-
}
131+
$items[] = (string) $item;
138132
}
139133

140134
return $items;
141135
}
142136

137+
private function populateResultOutput(\SimpleXMLElement $xml): Output
138+
{
139+
return new Output([
140+
'OutputKey' => (null !== $v = $xml->OutputKey[0]) ? (string) $v : null,
141+
'OutputValue' => (null !== $v = $xml->OutputValue[0]) ? (string) $v : null,
142+
'Description' => (null !== $v = $xml->Description[0]) ? (string) $v : null,
143+
'ExportName' => (null !== $v = $xml->ExportName[0]) ? (string) $v : null,
144+
]);
145+
}
146+
143147
/**
144148
* @return Output[]
145149
*/
146150
private function populateResultOutputs(\SimpleXMLElement $xml): array
147151
{
148152
$items = [];
149153
foreach ($xml->member as $item) {
150-
$items[] = new Output([
151-
'OutputKey' => ($v = $item->OutputKey) ? (string) $v : null,
152-
'OutputValue' => ($v = $item->OutputValue) ? (string) $v : null,
153-
'Description' => ($v = $item->Description) ? (string) $v : null,
154-
'ExportName' => ($v = $item->ExportName) ? (string) $v : null,
155-
]);
154+
$items[] = $this->populateResultOutput($item);
156155
}
157156

158157
return $items;
159158
}
160159

160+
private function populateResultParameter(\SimpleXMLElement $xml): Parameter
161+
{
162+
return new Parameter([
163+
'ParameterKey' => (null !== $v = $xml->ParameterKey[0]) ? (string) $v : null,
164+
'ParameterValue' => (null !== $v = $xml->ParameterValue[0]) ? (string) $v : null,
165+
'UsePreviousValue' => (null !== $v = $xml->UsePreviousValue[0]) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
166+
'ResolvedValue' => (null !== $v = $xml->ResolvedValue[0]) ? (string) $v : null,
167+
]);
168+
}
169+
161170
/**
162171
* @return Parameter[]
163172
*/
164173
private function populateResultParameters(\SimpleXMLElement $xml): array
165174
{
166175
$items = [];
167176
foreach ($xml->member as $item) {
168-
$items[] = new Parameter([
169-
'ParameterKey' => ($v = $item->ParameterKey) ? (string) $v : null,
170-
'ParameterValue' => ($v = $item->ParameterValue) ? (string) $v : null,
171-
'UsePreviousValue' => ($v = $item->UsePreviousValue) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
172-
'ResolvedValue' => ($v = $item->ResolvedValue) ? (string) $v : null,
173-
]);
177+
$items[] = $this->populateResultParameter($item);
174178
}
175179

176180
return $items;
177181
}
178182

183+
private function populateResultRollbackConfiguration(\SimpleXMLElement $xml): RollbackConfiguration
184+
{
185+
return new RollbackConfiguration([
186+
'RollbackTriggers' => (0 === ($v = $xml->RollbackTriggers)->count()) ? null : $this->populateResultRollbackTriggers($v),
187+
'MonitoringTimeInMinutes' => (null !== $v = $xml->MonitoringTimeInMinutes[0]) ? (int) (string) $v : null,
188+
]);
189+
}
190+
191+
private function populateResultRollbackTrigger(\SimpleXMLElement $xml): RollbackTrigger
192+
{
193+
return new RollbackTrigger([
194+
'Arn' => (string) $xml->Arn,
195+
'Type' => (string) $xml->Type,
196+
]);
197+
}
198+
179199
/**
180200
* @return RollbackTrigger[]
181201
*/
182202
private function populateResultRollbackTriggers(\SimpleXMLElement $xml): array
183203
{
184204
$items = [];
185205
foreach ($xml->member as $item) {
186-
$items[] = new RollbackTrigger([
187-
'Arn' => (string) $item->Arn,
188-
'Type' => (string) $item->Type,
189-
]);
206+
$items[] = $this->populateResultRollbackTrigger($item);
190207
}
191208

192209
return $items;
193210
}
194211

212+
private function populateResultStack(\SimpleXMLElement $xml): Stack
213+
{
214+
return new Stack([
215+
'StackId' => (null !== $v = $xml->StackId[0]) ? (string) $v : null,
216+
'StackName' => (string) $xml->StackName,
217+
'ChangeSetId' => (null !== $v = $xml->ChangeSetId[0]) ? (string) $v : null,
218+
'Description' => (null !== $v = $xml->Description[0]) ? (string) $v : null,
219+
'Parameters' => (0 === ($v = $xml->Parameters)->count()) ? null : $this->populateResultParameters($v),
220+
'CreationTime' => new \DateTimeImmutable((string) $xml->CreationTime),
221+
'DeletionTime' => (null !== $v = $xml->DeletionTime[0]) ? new \DateTimeImmutable((string) $v) : null,
222+
'LastUpdatedTime' => (null !== $v = $xml->LastUpdatedTime[0]) ? new \DateTimeImmutable((string) $v) : null,
223+
'RollbackConfiguration' => 0 === $xml->RollbackConfiguration->count() ? null : $this->populateResultRollbackConfiguration($xml->RollbackConfiguration),
224+
'StackStatus' => (string) $xml->StackStatus,
225+
'StackStatusReason' => (null !== $v = $xml->StackStatusReason[0]) ? (string) $v : null,
226+
'DisableRollback' => (null !== $v = $xml->DisableRollback[0]) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
227+
'NotificationARNs' => (0 === ($v = $xml->NotificationARNs)->count()) ? null : $this->populateResultNotificationARNs($v),
228+
'TimeoutInMinutes' => (null !== $v = $xml->TimeoutInMinutes[0]) ? (int) (string) $v : null,
229+
'Capabilities' => (0 === ($v = $xml->Capabilities)->count()) ? null : $this->populateResultCapabilities($v),
230+
'Outputs' => (0 === ($v = $xml->Outputs)->count()) ? null : $this->populateResultOutputs($v),
231+
'RoleARN' => (null !== $v = $xml->RoleARN[0]) ? (string) $v : null,
232+
'Tags' => (0 === ($v = $xml->Tags)->count()) ? null : $this->populateResultTags($v),
233+
'EnableTerminationProtection' => (null !== $v = $xml->EnableTerminationProtection[0]) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
234+
'ParentId' => (null !== $v = $xml->ParentId[0]) ? (string) $v : null,
235+
'RootId' => (null !== $v = $xml->RootId[0]) ? (string) $v : null,
236+
'DriftInformation' => 0 === $xml->DriftInformation->count() ? null : $this->populateResultStackDriftInformation($xml->DriftInformation),
237+
'RetainExceptOnCreate' => (null !== $v = $xml->RetainExceptOnCreate[0]) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
238+
'DeletionMode' => (null !== $v = $xml->DeletionMode[0]) ? (string) $v : null,
239+
'DetailedStatus' => (null !== $v = $xml->DetailedStatus[0]) ? (string) $v : null,
240+
]);
241+
}
242+
243+
private function populateResultStackDriftInformation(\SimpleXMLElement $xml): StackDriftInformation
244+
{
245+
return new StackDriftInformation([
246+
'StackDriftStatus' => (string) $xml->StackDriftStatus,
247+
'LastCheckTimestamp' => (null !== $v = $xml->LastCheckTimestamp[0]) ? new \DateTimeImmutable((string) $v) : null,
248+
]);
249+
}
250+
195251
/**
196252
* @return Stack[]
197253
*/
198254
private function populateResultStacks(\SimpleXMLElement $xml): array
199255
{
200256
$items = [];
201257
foreach ($xml->member as $item) {
202-
$items[] = new Stack([
203-
'StackId' => ($v = $item->StackId) ? (string) $v : null,
204-
'StackName' => (string) $item->StackName,
205-
'ChangeSetId' => ($v = $item->ChangeSetId) ? (string) $v : null,
206-
'Description' => ($v = $item->Description) ? (string) $v : null,
207-
'Parameters' => !$item->Parameters ? null : $this->populateResultParameters($item->Parameters),
208-
'CreationTime' => new \DateTimeImmutable((string) $item->CreationTime),
209-
'DeletionTime' => ($v = $item->DeletionTime) ? new \DateTimeImmutable((string) $v) : null,
210-
'LastUpdatedTime' => ($v = $item->LastUpdatedTime) ? new \DateTimeImmutable((string) $v) : null,
211-
'RollbackConfiguration' => !$item->RollbackConfiguration ? null : new RollbackConfiguration([
212-
'RollbackTriggers' => !$item->RollbackConfiguration->RollbackTriggers ? null : $this->populateResultRollbackTriggers($item->RollbackConfiguration->RollbackTriggers),
213-
'MonitoringTimeInMinutes' => ($v = $item->RollbackConfiguration->MonitoringTimeInMinutes) ? (int) (string) $v : null,
214-
]),
215-
'StackStatus' => (string) $item->StackStatus,
216-
'StackStatusReason' => ($v = $item->StackStatusReason) ? (string) $v : null,
217-
'DisableRollback' => ($v = $item->DisableRollback) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
218-
'NotificationARNs' => !$item->NotificationARNs ? null : $this->populateResultNotificationARNs($item->NotificationARNs),
219-
'TimeoutInMinutes' => ($v = $item->TimeoutInMinutes) ? (int) (string) $v : null,
220-
'Capabilities' => !$item->Capabilities ? null : $this->populateResultCapabilities($item->Capabilities),
221-
'Outputs' => !$item->Outputs ? null : $this->populateResultOutputs($item->Outputs),
222-
'RoleARN' => ($v = $item->RoleARN) ? (string) $v : null,
223-
'Tags' => !$item->Tags ? null : $this->populateResultTags($item->Tags),
224-
'EnableTerminationProtection' => ($v = $item->EnableTerminationProtection) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
225-
'ParentId' => ($v = $item->ParentId) ? (string) $v : null,
226-
'RootId' => ($v = $item->RootId) ? (string) $v : null,
227-
'DriftInformation' => !$item->DriftInformation ? null : new StackDriftInformation([
228-
'StackDriftStatus' => (string) $item->DriftInformation->StackDriftStatus,
229-
'LastCheckTimestamp' => ($v = $item->DriftInformation->LastCheckTimestamp) ? new \DateTimeImmutable((string) $v) : null,
230-
]),
231-
'RetainExceptOnCreate' => ($v = $item->RetainExceptOnCreate) ? filter_var((string) $v, \FILTER_VALIDATE_BOOLEAN) : null,
232-
'DeletionMode' => ($v = $item->DeletionMode) ? (string) $v : null,
233-
'DetailedStatus' => ($v = $item->DetailedStatus) ? (string) $v : null,
234-
]);
258+
$items[] = $this->populateResultStack($item);
235259
}
236260

237261
return $items;
238262
}
239263

264+
private function populateResultTag(\SimpleXMLElement $xml): Tag
265+
{
266+
return new Tag([
267+
'Key' => (string) $xml->Key,
268+
'Value' => (string) $xml->Value,
269+
]);
270+
}
271+
240272
/**
241273
* @return Tag[]
242274
*/
243275
private function populateResultTags(\SimpleXMLElement $xml): array
244276
{
245277
$items = [];
246278
foreach ($xml->member as $item) {
247-
$items[] = new Tag([
248-
'Key' => (string) $item->Key,
249-
'Value' => (string) $item->Value,
250-
]);
279+
$items[] = $this->populateResultTag($item);
251280
}
252281

253282
return $items;

0 commit comments

Comments
 (0)