Skip to content

Commit

Permalink
[REF] Minor code cleanup
Browse files Browse the repository at this point in the history
Minor code cleanups - use strict, declare exceptions, use use statement
  • Loading branch information
eileenmcnaughton committed Apr 28, 2021
1 parent a886fea commit 20f4850
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions CRM/Core/BAO/ActionSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/

use Civi\ActionSchedule\Event\MappingRegisterEvent;

/**
* This class contains functions for managing Scheduled Reminders
*/
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -574,8 +575,10 @@ protected static function sendReminderSms($tokenRow, $schedule, $toContactID) {

/**
* @param CRM_Core_DAO_ActionSchedule $actionSchedule
*
* @return string
* Ex: "Alice <[email protected]>".
* @throws \CRM_Core_Exception
*/
protected static function pickFromEmail($actionSchedule) {
$domainValues = CRM_Core_BAO_Domain::getNameAndEmail();
Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 20f4850

Please sign in to comment.