Move inline function to a private method

[MAILPOET-2333]
This commit is contained in:
Amine Ben hammou
2019-09-12 21:32:45 +01:00
committed by Jack Kitterhing
parent e48ad229e1
commit e9d12fb40e

View File

@ -90,20 +90,38 @@ class MailPoet {
} }
function getBody($newsletter, $subscriber, $extra_params = []) { function getBody($newsletter, $subscriber, $extra_params = []) {
$_this = $this; if (is_array($newsletter) && is_array($subscriber)) {
$composeBody = function($newsletter, $subscriber, $unsubscribe_url) use($_this) { $body = [];
for ($record = 0; $record < count($newsletter); $record++) {
$body[] = $this->composeBody(
$newsletter[$record],
$this->processSubscriber($subscriber[$record]),
(!empty($extra_params['unsubscribe_url'][$record])) ? $extra_params['unsubscribe_url'][$record] : false
);
}
} else {
$body[] = $this->composeBody(
$newsletter,
$this->processSubscriber($subscriber),
(!empty($extra_params['unsubscribe_url'])) ? $extra_params['unsubscribe_url'] : false
);
}
return $body;
}
private function composeBody($newsletter, $subscriber, $unsubscribe_url) {
$body = [ $body = [
'to' => ([ 'to' => ([
'address' => $subscriber['email'], 'address' => $subscriber['email'],
'name' => $subscriber['name'], 'name' => $subscriber['name'],
]), ]),
'from' => ([ 'from' => ([
'address' => $_this->sender['from_email'], 'address' => $this->sender['from_email'],
'name' => $_this->sender['from_name'], 'name' => $this->sender['from_name'],
]), ]),
'reply_to' => ([ 'reply_to' => ([
'address' => $_this->reply_to['reply_to_email'], 'address' => $this->reply_to['reply_to_email'],
'name' => $_this->reply_to['reply_to_name'], 'name' => $this->reply_to['reply_to_name'],
]), ]),
'subject' => $newsletter['subject'], 'subject' => $newsletter['subject'],
]; ];
@ -117,23 +135,5 @@ class MailPoet {
$body['list_unsubscribe'] = $unsubscribe_url; $body['list_unsubscribe'] = $unsubscribe_url;
} }
return $body; return $body;
};
if (is_array($newsletter) && is_array($subscriber)) {
$body = [];
for ($record = 0; $record < count($newsletter); $record++) {
$body[] = $composeBody(
$newsletter[$record],
$this->processSubscriber($subscriber[$record]),
(!empty($extra_params['unsubscribe_url'][$record])) ? $extra_params['unsubscribe_url'][$record] : false
);
}
} else {
$body[] = $composeBody(
$newsletter,
$this->processSubscriber($subscriber),
(!empty($extra_params['unsubscribe_url'])) ? $extra_params['unsubscribe_url'] : false
);
}
return $body;
} }
} }