Refactor
This commit is contained in:
parent
88d5d4a126
commit
bde36ee056
1 changed files with 20 additions and 12 deletions
|
@ -15,18 +15,7 @@ readonly final class AddRandomCtaToDailyEmail {
|
|||
}
|
||||
|
||||
public function __invoke(DailyEmail $email): void {
|
||||
if (!$email->isNew()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($email->get('field_daily_email_cta')->getValue() !== []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$body = $email->get('body')->value;
|
||||
assert(is_string($body));
|
||||
|
||||
if (str_contains(haystack: $body, needle: 'P.S.')) {
|
||||
if (!$this->shouldUpdate($email)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -51,4 +40,23 @@ readonly final class AddRandomCtaToDailyEmail {
|
|||
return Ctas::fromNodes($ctaNodes);
|
||||
}
|
||||
|
||||
private function shouldUpdate(DailyEmail $email): bool {
|
||||
if (!$email->isNew()) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if ($email->get('field_daily_email_cta')->getValue() !== []) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
$body = $email->get('body')->value;
|
||||
assert(is_string($body));
|
||||
|
||||
if (str_contains(haystack: $body, needle: 'P.S.')) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue