Skip to content

Commit

Permalink
[NFC] Code cleanup around comments, strict comparison, formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Apr 11, 2020
1 parent 92fc8db commit f883fde
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 23 deletions.
30 changes: 21 additions & 9 deletions CRM/Member/Form/Membership.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public static function getPriceFieldIDs($params, $priceSet) {
* Form preProcess function.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function preProcess() {
// This string makes up part of the class names, differentiating them (not sure why) from the membership fields.
Expand Down Expand Up @@ -665,9 +666,11 @@ public function buildQuickForm() {
* @param array $files
* @param CRM_Member_Form_Membership $self
*
* @throws CiviCRM_API3_Exception
* @return bool|array
* mixed true or array of errors
*
* @throws \CRM_Core_Exception
* @throws CiviCRM_API3_Exception
*/
public static function formRule($params, $files, $self) {
$errors = [];
Expand Down Expand Up @@ -880,6 +883,9 @@ public static function formRule($params, $files, $self) {

/**
* Process the form submission.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function postProcess() {
if ($this->_action & CRM_Core_Action::DELETE) {
Expand Down Expand Up @@ -925,10 +931,6 @@ private function convertIsOverrideValue() {
/**
* Send email receipt.
*
* @deprecated
* This function is shared with Batch_Entry which has limited overlap
* & needs rationalising.
*
* @param CRM_Core_Form $form
* Form object.
* @param array $formValues
Expand All @@ -938,6 +940,12 @@ private function convertIsOverrideValue() {
*
* @return bool
* true if mail was sent successfully
* @throws \CRM_Core_Exception
*
* @deprecated
* This function is shared with Batch_Entry which has limited overlap
* & needs rationalising.
*
*/
public static function emailReceipt(&$form, &$formValues, &$membership, $customValues = NULL) {
// retrieve 'from email id' for acknowledgement
Expand Down Expand Up @@ -1661,7 +1669,7 @@ public function submit() {
if ($contributionId && !empty($membershipIds)) {
$contributionDetails = CRM_Contribute_BAO_Contribution::getContributionDetails(
CRM_Export_Form_Select::MEMBER_EXPORT, $this->_membershipIDs);
if ($contributionDetails[$membership->id]['contribution_status'] == 'Completed') {
if ($contributionDetails[$membership->id]['contribution_status'] === 'Completed') {
$receiptSend = TRUE;
}
}
Expand Down Expand Up @@ -1703,6 +1711,8 @@ public function submit() {
* @param CRM_Member_DAO_Membership $membership
* Updated membership object
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
protected function updateContributionOnMembershipTypeChange($inputParams, $membership) {
if (Civi::settings()->get('update_contribution_on_membership_type_change') &&
Expand Down Expand Up @@ -1784,7 +1794,7 @@ protected function setUserContext() {
$buttonName = $this->controller->getButtonName();
$session = CRM_Core_Session::singleton();

if ($this->_context == 'standalone') {
if ($this->_context === 'standalone') {
if ($buttonName == $this->getButtonName('upload', 'new')) {
$session->replaceUserContext(CRM_Utils_System::url('civicrm/member/add',
'reset=1&action=add&context=standalone'
Expand Down Expand Up @@ -1890,6 +1900,7 @@ protected function setStatusMessage($membership) {

/**
* @return bool
* @throws \CRM_Core_Exception
*/
protected function isUpdateToExistingRecurringMembership() {
$isRecur = FALSE;
Expand All @@ -1910,6 +1921,7 @@ protected function isUpdateToExistingRecurringMembership() {
* @param \CRM_Member_BAO_Membership $membership
*
* @return bool
* @throws \CRM_Core_Exception
*/
protected function emailMembershipReceipt($formValues, $membership) {
$customValues = $this->getCustomValuesForReceipt($formValues, $membership);
Expand All @@ -1932,7 +1944,7 @@ protected function getCustomValuesForReceipt($formValues, $membership) {
&& !empty($this->_groupTree)
) {
foreach ($this->_groupTree as $groupID => $group) {
if ($groupID == 'info') {
if ($groupID === 'info') {
continue;
}
foreach ($group['fields'] as $k => $field) {
Expand All @@ -1944,7 +1956,7 @@ protected function getCustomValuesForReceipt($formValues, $membership) {

$members = [['member_id', '=', $membership->id, 0, 0]];
// check whether its a test drive
if ($this->_mode == 'test') {
if ($this->_mode === 'test') {
$members[] = ['member_test', '=', 1, 0, 0];
}

Expand Down
40 changes: 26 additions & 14 deletions CRM/Member/Form/MembershipRenewal.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {

/**
* email of the person paying for the membership (used for receipts)
*
* @var string
*/
protected $_memberEmail = NULL;
Expand All @@ -50,6 +51,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {

/**
* email of the person paying for the membership (used for receipts)
*
* @var string
*/
protected $_contributorEmail = NULL;
Expand All @@ -71,6 +73,7 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
/**
* context would be set to standalone if the contact is use is being selected from
* the form rather than in the URL
*
* @var string
*/
public $_context;
Expand Down Expand Up @@ -99,25 +102,27 @@ class CRM_Member_Form_MembershipRenewal extends CRM_Member_Form {
/**
* Set entity fields to be assigned to the form.
*/
protected function setEntityFields() {}
protected function setEntityFields() {
}

/**
* Set the delete message.
*
* We do this from the constructor in order to do a translation.
*/
public function setDeleteMessage() {}
public function setDeleteMessage() {
}

/**
* Set the renewal notification status message.
*/
public function setRenewalMessage() {
$statusMsg = ts('%1 membership for %2 has been renewed.', array(1 => $this->membershipTypeName, 2 => $this->_memberDisplayName));
$statusMsg = ts('%1 membership for %2 has been renewed.', [1 => $this->membershipTypeName, 2 => $this->_memberDisplayName]);

if ($this->isMailSent) {
$statusMsg .= ' ' . ts('A renewal confirmation and receipt has been sent to %1.', array(
1 => $this->_contributorEmail,
));
$statusMsg .= ' ' . ts('A renewal confirmation and receipt has been sent to %1.', [
1 => $this->_contributorEmail,
]);
}
CRM_Core_Session::setStatus($statusMsg, ts('Complete'), 'success');
}
Expand All @@ -135,8 +140,8 @@ public function preProcess() {
parent::preProcess();

$this->assign('endDate', CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership',
$this->_id, 'end_date'
)
$this->_id, 'end_date'
)
));
$this->assign('membershipStatus',
CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus',
Expand Down Expand Up @@ -176,6 +181,7 @@ public function preProcess() {
*
* @return array
* Default values.
* @throws \CRM_Core_Exception
*/
public function setDefaultValues() {

Expand Down Expand Up @@ -211,7 +217,7 @@ public function setDefaultValues() {
$defaults['send_receipt'] = 0;

//set Soft Credit Type to Gift by default
$scTypes = CRM_Core_OptionGroup::values("soft_credit_type");
$scTypes = CRM_Core_OptionGroup::values('soft_credit_type');
$defaults['soft_credit_type_id'] = CRM_Utils_Array::value(ts('Gift'), array_flip($scTypes));

$renewalDate = $defaults['renewal_date'] ?? NULL;
Expand All @@ -226,6 +232,8 @@ public function setDefaultValues() {

/**
* Build the form object.
*
* @throws \CRM_Core_Exception
*/
public function buildQuickForm() {

Expand Down Expand Up @@ -412,6 +420,7 @@ public function buildQuickForm() {
*
* @return bool|array
* mixed true or array of errors
* @throws \CRM_Core_Exception
*/
public static function formRule($params, $files, $self) {
$errors = [];
Expand Down Expand Up @@ -453,6 +462,9 @@ public static function formRule($params, $files, $self) {

/**
* Process the renewal form.
*
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public function postProcess() {
// get the submitted form values.
Expand Down Expand Up @@ -546,7 +558,7 @@ protected function submit() {

$this->_params['contribution_status_id'] = $result['payment_status_id'];
$this->_params['trxn_id'] = $result['trxn_id'];
$this->_params['is_test'] = ($this->_mode == 'live') ? 0 : 1;
$this->_params['is_test'] = ($this->_mode === 'live') ? 0 : 1;
$this->set('params', $this->_params);
$this->assign('trxn_id', $result['trxn_id']);
}
Expand Down Expand Up @@ -661,7 +673,7 @@ protected function sendReceipt($membership) {
// retrieve custom data
$customFields = $customValues = $fo = [];
foreach ($this->_groupTree as $groupID => $group) {
if ($groupID == 'info') {
if ($groupID === 'info') {
continue;
}
foreach ($group['fields'] as $k => $field) {
Expand All @@ -671,7 +683,7 @@ protected function sendReceipt($membership) {
}
$members = [['member_id', '=', $this->_membershipId, 0, 0]];
// check whether its a test drive
if ($this->_mode == 'test') {
if ($this->_mode === 'test') {
$members[] = ['member_test', '=', 1, 0, 0];
}
CRM_Core_BAO_UFGroup::getValues($this->_contactID, $customFields, $customValues, FALSE, $members);
Expand All @@ -697,7 +709,7 @@ protected function sendReceipt($membership) {
$this->assign('is_pay_later', 0);
$this->assign('isPrimary', 1);
$this->assign('receipt_text_renewal', $this->_params['receipt_text']);
if ($this->_mode == 'test') {
if ($this->_mode === 'test') {
$this->assign('action', '1024');
}
}
Expand All @@ -710,7 +722,7 @@ protected function sendReceipt($membership) {
'from' => $receiptFrom,
'toName' => $this->_contributorDisplayName,
'toEmail' => $this->_contributorEmail,
'isTest' => $this->_mode == 'test',
'isTest' => $this->_mode === 'test',
]
);
}
Expand Down

0 comments on commit f883fde

Please sign in to comment.