From bde36ee056585aa0d0fb87baa1d9810bdca074dd Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Tue, 24 Jun 2025 00:59:50 +0100 Subject: [PATCH] Refactor --- .../src/Action/AddRandomCtaToDailyEmail.php | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/modules/opd_daily_emails/src/Action/AddRandomCtaToDailyEmail.php b/modules/opd_daily_emails/src/Action/AddRandomCtaToDailyEmail.php index f750402c9..36caeb86b 100644 --- a/modules/opd_daily_emails/src/Action/AddRandomCtaToDailyEmail.php +++ b/modules/opd_daily_emails/src/Action/AddRandomCtaToDailyEmail.php @@ -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; + } + }