From 20f485059ed5bbc8795ad3cfd7bea0b02eef2373 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 28 Apr 2021 15:36:47 +1200 Subject: [PATCH] [REF] Minor code cleanup Minor code cleanups - use strict, declare exceptions, use use statement --- CRM/Core/BAO/ActionSchedule.php | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/CRM/Core/BAO/ActionSchedule.php b/CRM/Core/BAO/ActionSchedule.php index 7cfb0ab07687..b57abb0a2cac 100644 --- a/CRM/Core/BAO/ActionSchedule.php +++ b/CRM/Core/BAO/ActionSchedule.php @@ -15,6 +15,8 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ +use Civi\ActionSchedule\Event\MappingRegisterEvent; + /** * This class contains functions for managing Scheduled Reminders */ @@ -35,26 +37,24 @@ public static function getMappings($filters = NULL) { if ($_action_mapping === NULL) { $event = \Civi::dispatcher() ->dispatch('civi.actionSchedule.getMappings', - new \Civi\ActionSchedule\Event\MappingRegisterEvent()); + new MappingRegisterEvent()); $_action_mapping = $event->getMappings(); } if (empty($filters)) { return $_action_mapping; } - elseif (isset($filters['id'])) { - return [ - $filters['id'] => $_action_mapping[$filters['id']], - ]; - } - else { - throw new CRM_Core_Exception("getMappings() called with unsupported filter: " . implode(', ', array_keys($filters))); + if (isset($filters['id'])) { + return [$filters['id'] => $_action_mapping[$filters['id']]]; } + throw new CRM_Core_Exception("getMappings() called with unsupported filter: " . implode(', ', array_keys($filters))); } /** * @param string|int $id + * * @return \Civi\ActionSchedule\Mapping|NULL + * @throws \CRM_Core_Exception */ public static function getMapping($id) { $mappings = self::getMappings(); @@ -283,11 +283,11 @@ public static function sendMailings($mappingID, $now) { ->context('contactId', $dao->contactID) ->context('actionSearchResult', (object) $dao->toArray()); foreach ($tokenProcessor->evaluate()->getRows() as $tokenRow) { - if ($actionSchedule->mode == 'SMS' or $actionSchedule->mode == 'User_Preference') { + if ($actionSchedule->mode === 'SMS' || $actionSchedule->mode === 'User_Preference') { CRM_Utils_Array::extend($errors, self::sendReminderSms($tokenRow, $actionSchedule, $dao->contactID)); } - if ($actionSchedule->mode == 'Email' or $actionSchedule->mode == 'User_Preference') { + if ($actionSchedule->mode === 'Email' || $actionSchedule->mode === 'User_Preference') { CRM_Utils_Array::extend($errors, self::sendReminderEmail($tokenRow, $actionSchedule, $dao->contactID)); } // insert activity log record if needed @@ -485,6 +485,7 @@ protected static function createMailingActivity($tokenRow, $mapping, $contactID, /** * @param \Civi\ActionSchedule\MappingInterface $mapping * @param \CRM_Core_DAO_ActionSchedule $actionSchedule + * * @return string */ protected static function prepareMailingQuery($mapping, $actionSchedule) { @@ -574,8 +575,10 @@ protected static function sendReminderSms($tokenRow, $schedule, $toContactID) { /** * @param CRM_Core_DAO_ActionSchedule $actionSchedule + * * @return string * Ex: "Alice ". + * @throws \CRM_Core_Exception */ protected static function pickFromEmail($actionSchedule) { $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); @@ -684,7 +687,7 @@ protected static function pickSmsPhoneNumber($smsToContactId) { * @return array * array(mixed $value => string $label). */ - public static function getAdditionalRecipients() { + public static function getAdditionalRecipients(): array { return [ 'manual' => ts('Choose Recipient(s)'), 'group' => ts('Select Group'),