Skip to content

Commit ea584f9

Browse files
Fixed cyclomatic complexity
1 parent 6e53e0d commit ea584f9

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

app/code/Magento/Newsletter/Model/SubscriptionManager.php

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,14 @@ private function saveSubscriber(
195195
): bool {
196196
$statusChanged = (int)$subscriber->getStatus() !== $status;
197197
$emailChanged = $subscriber->getEmail() !== $customer->getEmail();
198-
if ($subscriber->getId()
199-
&& !$statusChanged
200-
&& (int)$subscriber->getCustomerId() === (int)$customer->getId()
201-
&& (int)$subscriber->getStoreId() === $storeId
202-
&& !$emailChanged
203-
&& $status !== Subscriber::STATUS_NOT_ACTIVE
204-
) {
198+
if ($this->dontNeedToSaveSubscriber(
199+
$subscriber,
200+
$customer,
201+
$statusChanged,
202+
$storeId,
203+
$status,
204+
$emailChanged
205+
)) {
205206
return false;
206207
}
207208

@@ -227,6 +228,32 @@ private function saveSubscriber(
227228
return $status === Subscriber::STATUS_NOT_ACTIVE || $emailChanged;
228229
}
229230

231+
/**
232+
*
233+
* @param Subscriber $subscriber
234+
* @param CustomerInterface $customer
235+
* @param bool $statusChanged
236+
* @param int $storeId
237+
* @param int $status
238+
* @param bool $emailChanged
239+
* @return bool
240+
*/
241+
private function dontNeedToSaveSubscriber(
242+
Subscriber $subscriber,
243+
CustomerInterface $customer,
244+
bool $statusChanged,
245+
int $storeId,
246+
int $status,
247+
bool $emailChanged
248+
): bool {
249+
return $subscriber->getId()
250+
&& !$statusChanged
251+
&& (int)$subscriber->getCustomerId() === (int)$customer->getId()
252+
&& (int)$subscriber->getStoreId() === $storeId
253+
&& !$emailChanged
254+
&& $status !== Subscriber::STATUS_NOT_ACTIVE;
255+
}
256+
230257
/**
231258
* Get new subscription status
232259
*

0 commit comments

Comments
 (0)