Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NFC] Code cleanup, docblocks, strict comparison, type hints #20240

Merged
merged 1 commit into from
May 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 27 additions & 18 deletions CRM/Admin/Form/ScheduleReminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CRM_Admin_Form_ScheduleReminders extends CRM_Admin_Form {
* Scheduled Reminder ID.
* @var int
*/
public $_id = NULL;
public $_id;

public $_freqUnits;

Expand All @@ -40,19 +40,22 @@ public function getComponentID() {
/**
* @param mixed $compId
*/
public function setComponentID($compId) {
public function setComponentID($compId): void {
$this->_compId = $compId;
}

/**
* Build the form object.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function buildQuickForm() {
public function buildQuickForm(): void {
parent::buildQuickForm();
$this->_mappingID = $mappingID = NULL;
$providersCount = CRM_SMS_BAO_Provider::activeProviderCount();
$this->setContext();
$isEvent = $this->getContext() == 'event';
$isEvent = $this->getContext() === 'event';

if ($isEvent) {
$this->setComponentID(CRM_Utils_Request::retrieve('compId', 'Integer', $this));
Expand Down Expand Up @@ -295,8 +298,11 @@ public function buildQuickForm() {
*
* @return array|bool
* True if no errors, else array of errors
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public static function formRule($fields, $files, $self) {
public static function formRule(array $fields, $files, $self) {
$errors = [];
if ((array_key_exists(1, $fields['entity']) && $fields['entity'][1][0] === 0) ||
(array_key_exists(2, $fields['entity']) && $fields['entity'][2][0] == 0)
Expand All @@ -306,17 +312,17 @@ public static function formRule($fields, $files, $self) {

$mode = CRM_Utils_Array::value('mode', $fields, FALSE);
if (!empty($fields['is_active']) &&
CRM_Utils_System::isNull($fields['subject']) && (!$mode || $mode != 'SMS')
CRM_Utils_System::isNull($fields['subject']) && (!$mode || $mode !== 'SMS')
) {
$errors['subject'] = ts('Subject is a required field.');
}
if (!empty($fields['is_active']) &&
CRM_Utils_System::isNull(trim(strip_tags($fields['html_message']))) && (!$mode || $mode != 'SMS')
CRM_Utils_System::isNull(trim(strip_tags($fields['html_message']))) && (!$mode || $mode !== 'SMS')
) {
$errors['html_message'] = ts('The HTML message is a required field.');
}

if (!empty($mode) && ($mode == 'SMS' || $mode == 'User_Preference') && !empty($fields['is_active']) &&
if (!empty($mode) && ($mode === 'SMS' || $mode === 'User_Preference') && !empty($fields['is_active']) &&
CRM_Utils_System::isNull(trim(strip_tags($fields['sms_text_message'])))
) {
$errors['sms_text_message'] = ts('The SMS message is a required field.');
Expand Down Expand Up @@ -428,7 +434,7 @@ public function postProcess() {
// delete reminder
CRM_Core_BAO_ActionSchedule::del($this->_id);
CRM_Core_Session::setStatus(ts('Selected Reminder has been deleted.'), ts('Record Deleted'), 'success');
if ($this->getContext() == 'event' && $this->getComponentID()) {
if ($this->getContext() === 'event' && $this->getComponentID()) {
$url = CRM_Utils_System::url('civicrm/event/manage/reminder',
"reset=1&action=browse&id=" . $this->getComponentID() . "&component=" . $this->getContext() . "&setTab=1"
);
Expand Down Expand Up @@ -459,7 +465,7 @@ public function postProcess() {
);
}

if ($this->getContext() == 'event' && $this->getComponentID()) {
if ($this->getContext() === 'event' && $this->getComponentID()) {
$url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=browse&id=" . $this->getComponentID() . "&component=" . $this->getContext() . "&setTab=1");
$session = CRM_Core_Session::singleton();
$session->pushUserContext($url);
Expand All @@ -471,7 +477,10 @@ public function postProcess() {
/**
* @param array $values
* The submitted form values.
*
* @return CRM_Core_DAO_ActionSchedule
* @throws \CiviCRM_API3_Exception
* @throws \Civi\API\Exception\UnauthorizedException
*/
public function parseActionSchedule($values) {
$params = [];
Expand Down Expand Up @@ -513,7 +522,7 @@ public function parseActionSchedule($values) {
$params['absolute_date'] = 'null';
}
foreach ($moreKeys as $mkey) {
if ($params['absolute_date'] != 'null' && CRM_Utils_String::startsWith($mkey, 'start_action')) {
if ($params['absolute_date'] !== 'null' && CRM_Utils_String::startsWith($mkey, 'start_action')) {
$params[$mkey] = 'null';
continue;
}
Expand All @@ -524,11 +533,11 @@ public function parseActionSchedule($values) {
$params['sms_body_text'] = $values['sms_text_message'] ?? NULL;
$params['body_html'] = $values['html_message'] ?? NULL;

if (CRM_Utils_Array::value('recipient', $values) == 'manual') {
if (CRM_Utils_Array::value('recipient', $values) === 'manual') {
$params['recipient_manual'] = $values['recipient_manual_id'] ?? NULL;
$params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null';
}
elseif (CRM_Utils_Array::value('recipient', $values) == 'group') {
elseif (CRM_Utils_Array::value('recipient', $values) === 'group') {
$params['group_id'] = $values['group_id'];
$params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null';
}
Expand Down Expand Up @@ -585,10 +594,10 @@ public function parseActionSchedule($values) {

$modePrefixes = ['Mail' => NULL, 'SMS' => 'SMS'];

if ($params['mode'] == 'Email' || empty($params['sms_provider_id'])) {
if ($params['mode'] === 'Email' || empty($params['sms_provider_id'])) {
unset($modePrefixes['SMS']);
}
elseif ($params['mode'] == 'SMS') {
elseif ($params['mode'] === 'SMS') {
unset($modePrefixes['Mail']);
}

Expand All @@ -614,7 +623,7 @@ public function parseActionSchedule($values) {

if (!empty($composeParams[$prefix . 'updateTemplate'])) {
$templateParams = ['is_active' => TRUE];
if ($prefix == 'SMS') {
if ($prefix === 'SMS') {
$templateParams += [
'msg_text' => $params['sms_body_text'],
'is_sms' => TRUE,
Expand All @@ -634,7 +643,7 @@ public function parseActionSchedule($values) {

if (!empty($composeParams[$prefix . 'saveTemplate'])) {
$templateParams = ['is_active' => TRUE];
if ($prefix == 'SMS') {
if ($prefix === 'SMS') {
$templateParams += [
'msg_text' => $params['sms_body_text'],
'is_sms' => TRUE,
Expand All @@ -652,7 +661,7 @@ public function parseActionSchedule($values) {
$msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams);
}

if ($prefix == 'SMS') {
if ($prefix === 'SMS') {
if (isset($msgTemplate->id)) {
$params['sms_template_id'] = $msgTemplate->id;
}
Expand Down