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

REF - Simplify inline conditionals with Elvis #27141

Merged
merged 4 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ public static function createEmailActivity($sourceContactID, $subject, $html, $t
$details = "-ALTERNATIVE ITEM 0-\n{$html}{$additionalDetails}\n-ALTERNATIVE ITEM 1-\n{$text}{$additionalDetails}\n-ALTERNATIVE END-\n";
}
else {
$details = $html ? $html : $text;
$details = $html ?: $text;
$details .= $additionalDetails;
}

Expand Down Expand Up @@ -1703,7 +1703,7 @@ public static function getParentActivity($activityId) {
'parent_id'
);

$parentActivities[$activityId] = $parentId ? $parentId : FALSE;
$parentActivities[$activityId] = $parentId ?: FALSE;
}

return $parentActivities[$activityId];
Expand Down
4 changes: 2 additions & 2 deletions CRM/Admin/Form/RelationshipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ public function postProcess() {
$params['contact_type_a'] = $cTypeA[0];
$params['contact_type_b'] = $cTypeB[0];

$params['contact_sub_type_a'] = $cTypeA[1] ? $cTypeA[1] : 'null';
$params['contact_sub_type_b'] = $cTypeB[1] ? $cTypeB[1] : 'null';
$params['contact_sub_type_a'] = $cTypeA[1] ?: 'null';
$params['contact_sub_type_b'] = $cTypeB[1] ?: 'null';

if (!strlen(trim($params['label_b_a'] ?? ''))) {
$params['label_b_a'] = $params['label_a_b'] ?? NULL;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Campaign/Form/Survey/Results.php
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public function postProcess() {
$activityStatus = array_flip($activityStatus);
$this->_params = [
'name' => "survey_{$survey->id}",
'title' => $params['report_title'] ? $params['report_title'] : $this->_values['title'],
'title' => $params['report_title'] ?: $this->_values['title'],
'status_id_op' => 'eq',
// reserved status
'status_id_value' => $activityStatus['Scheduled'],
Expand Down
4 changes: 2 additions & 2 deletions CRM/Campaign/Form/Survey/TabHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public static function getCurrentTab($tabs) {
}
}

$current = $current ? $current : 'main';
$current = $current ?: 'main';
return $current;
}

Expand Down Expand Up @@ -166,7 +166,7 @@ public static function getNextTab(&$form) {
}
}

$next = $next ? $next : 'main';
$next = $next ?: 'main';
return $next;
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ public static function processImage() {
$cid = CRM_Utils_Request::retrieve('cid', 'Positive');
// retrieve contact id in case of Profile context
$id = CRM_Utils_Request::retrieve('id', 'Positive');
$cid = $cid ? $cid : $id;
$cid = $cid ?: $id;
if ($action & CRM_Core_Action::DELETE) {
if (CRM_Utils_Request::retrieve('confirmed', 'Boolean')) {
CRM_Contact_BAO_Contact::deleteContactImage($cid);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/BAO/Relationship.php
Original file line number Diff line number Diff line change
Expand Up @@ -2040,7 +2040,7 @@ public static function buildOptions($fieldName, $context = NULL, $props = []) {
*/
public static function isCurrentEmployerNeedingToBeCleared($params, $relationshipId, $updatedRelTypeID = NULL) {
$existingTypeID = (int) CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Relationship', $relationshipId, 'relationship_type_id');
$updatedRelTypeID = $updatedRelTypeID ? $updatedRelTypeID : $existingTypeID;
$updatedRelTypeID = $updatedRelTypeID ?: $existingTypeID;
$currentEmployerID = (int) civicrm_api3('Contact', 'getvalue', ['return' => 'current_employer_id', 'id' => $params['contact_id_a']]);

if ($currentEmployerID !== (int) $params['contact_id_b'] || !self::isRelationshipTypeCurrentEmployer($existingTypeID)) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contact/Form/Task/EmailTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ protected function createEmailActivity($sourceContactID, $subject, $html, $text,
$details = "-ALTERNATIVE ITEM 0-\n{$html}{$additionalDetails}\n-ALTERNATIVE ITEM 1-\n{$text}{$additionalDetails}\n-ALTERNATIVE END-\n";
}
else {
$details = $html ? $html : $text;
$details = $html ?: $text;
$details .= $additionalDetails;
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/AdditionalInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public static function processNote($params, $contactID, $contributionID, $contri
$noteID = [];
if ($contributionNoteID) {
$noteID = ["id" => $contributionNoteID];
$noteParams['note'] = $noteParams['note'] ? $noteParams['note'] : "null";
$noteParams['note'] = $noteParams['note'] ?: "null";
}
CRM_Core_BAO_Note::add($noteParams, $noteID);
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/ContributionBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ public function getTemplateFileName() {
*/
public function overrideExtraTemplateFileName() {
$fileName = $this->checkTemplateFileExists('extra.');
return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
return $fileName ?: parent::overrideExtraTemplateFileName();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Contribute/Form/ContributionPage/TabHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static function getCurrentTab($tabs) {
}
}

$current = $current ? $current : 'settings';
$current = $current ?: 'settings';
return $current;
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/BAO/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static function defaultContactCountryName() {
public static function defaultCurrencySymbol($defaultCurrency = NULL) {
static $cachedSymbol = NULL;
if (!$cachedSymbol || $defaultCurrency) {
$currency = $defaultCurrency ? $defaultCurrency : Civi::settings()->get('defaultCurrency');
$currency = $defaultCurrency ?: Civi::settings()->get('defaultCurrency');
if ($currency) {
$currencySymbols = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'currency', [
'labelColumn' => 'symbol',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/BAO/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public static function getGroupId() {
$title, 'id', 'title', TRUE
);
}
return $groupID ? $groupID : FALSE;
return $groupID ?: FALSE;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ public function &add(
// Fudge some extra types that quickform doesn't support
$inputType = $type;
if ($type == 'wysiwyg' || in_array($type, self::$html5Types)) {
$attributes = ($attributes ? $attributes : []) + ['class' => ''];
$attributes = ($attributes ?: []) + ['class' => ''];
$attributes['class'] = ltrim($attributes['class'] . " crm-form-$type");
if ($type == 'wysiwyg' && isset($attributes['preset'])) {
$attributes['data-preset'] = $attributes['preset'];
Expand Down Expand Up @@ -1397,7 +1397,7 @@ public function get_template_vars($name = NULL) {
*/
public function &addRadio($name, $title, $values, $attributes = [], $separator = NULL, $required = FALSE, $optionAttributes = []) {
$options = [];
$attributes = $attributes ? $attributes : [];
$attributes = $attributes ?: [];
$allowClear = !empty($attributes['allowClear']);
unset($attributes['allowClear']);
$attributes['id_suffix'] = $name;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/I18n.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ public static function getContactDefaultLanguage() {
*/
public static function getLocale() {
global $tsLocale;
return $tsLocale ? $tsLocale : 'en_US';
return $tsLocale ?: 'en_US';
}

/**
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Lock.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function acquire($timeout = NULL) {
$query = "SELECT GET_LOCK( %1, %2 )";
$params = [
1 => [$this->_id, 'String'],
2 => [$timeout ? $timeout : $this->_timeout, 'Integer'],
2 => [$timeout ?: $this->_timeout, 'Integer'],
];
$res = CRM_Core_DAO::singleValueQuery($query, $params);
if ($res) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ public static function fillComponentIds(&$menu, $path) {
'id', 'name'
);
}
$menu[$path]['component_id'] = $componentId ? $componentId : NULL;
$menu[$path]['component_id'] = $componentId ?: NULL;
$cache[$compPath] = $menu[$path]['component_id'];
}
}
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/Page/AJAX/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public static function getLocBlock() {
}
$fld = "address[1][{$element}]";
$value = $location['address'][1][$element] ?? NULL;
$value = $value ? $value : "";
$value = $value ?: "";
$result[str_replace([
'][',
'[',
Expand All @@ -244,7 +244,7 @@ public static function getLocBlock() {
for ($i = 1; $i < 3; $i++) {
$fld = "{$block}[{$i}][{$element}]";
$value = $location[$block][$i][$element] ?? NULL;
$value = $value ? $value : "";
$value = $value ?: "";
$result[str_replace([
'][',
'[',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Payment/PayPalIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public function getInput(&$input) {
];
foreach ($lookup as $name => $paypalName) {
$value = $this->retrieve($paypalName, 'String', FALSE);
$input[$name] = $value ? $value : NULL;
$input[$name] = $value ?: NULL;
}

$input['is_test'] = $this->retrieve('test_ipn', 'Integer', FALSE);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Payment/PayPalProIPN.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ public function getInput(&$input) {
];
foreach ($lookup as $name => $paypalName) {
$value = $this->retrieve($paypalName, 'String', FALSE);
$input[$name] = $value ? $value : NULL;
$input[$name] = $value ?: NULL;
}

$input['is_test'] = $this->retrieve('test_ipn', 'Integer', FALSE);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/PseudoConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ public static function &countryIsoCode($id = FALSE) {
*/
public static function allGroup($groupType = NULL, $excludeHidden = TRUE) {
$condition = CRM_Contact_BAO_Group::groupTypeCondition($groupType, $excludeHidden);
$groupKey = ($groupType ? $groupType : 'null') . !empty($excludeHidden);
$groupKey = ($groupType ?: 'null') . !empty($excludeHidden);

if (!isset(Civi::$statics[__CLASS__]['groups']['allGroup'][$groupKey])) {
self::populate(Civi::$statics[__CLASS__]['groups']['allGroup'][$groupKey], 'CRM_Contact_DAO_Group', FALSE, 'title', 'is_active', $condition);
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/Selector/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ class CRM_Core_Selector_Controller {
public function __construct($object, $pageID, $sortID, $action, $store = NULL, $output = self::TEMPLATE, $prefix = NULL, $case = NULL) {

$this->_object = $object;
$this->_pageID = $pageID ? $pageID : 1;
$this->_sortID = $sortID ? $sortID : NULL;
$this->_pageID = $pageID ?: 1;
$this->_sortID = $sortID ?: NULL;
$this->_action = $action;
$this->_store = $store;
$this->_output = $output;
Expand Down
4 changes: 2 additions & 2 deletions CRM/Core/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public function timer($name, $expire) {
$ts = $this->get($name, 'timer');
if (!$ts || $ts < time() - $expire) {
$this->set($name, time(), 'timer');
return $ts ? $ts : 'not set';
return $ts ?: 'not set';
}
return FALSE;
}
Expand Down Expand Up @@ -502,7 +502,7 @@ public static function setStatus($text, $title = '', $type = 'alert', $options =
'text' => $text,
'title' => $title,
'type' => $type,
'options' => $options ? $options : NULL,
'options' => $options ?: NULL,
];
}
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Event/Form/ManageEvent/TabHeader.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public static function getCurrentTab($tabs) {
}
}

$current = $current ? $current : 'settings';
$current = $current ?: 'settings';
return $current;
}

Expand Down
4 changes: 2 additions & 2 deletions CRM/Event/Form/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ public function checkTemplateFileExists($suffix = NULL) {
*/
public function getTemplateFileName() {
$fileName = $this->checkTemplateFileExists();
return $fileName ? $fileName : parent::getTemplateFileName();
return $fileName ?: parent::getTemplateFileName();
}

/**
Expand All @@ -1136,7 +1136,7 @@ public function getTemplateFileName() {
*/
public function overrideExtraTemplateFileName() {
$fileName = $this->checkTemplateFileExists('extra.');
return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
return $fileName ?: parent::overrideExtraTemplateFileName();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions CRM/Event/PseudoConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public static function &participantStatus($id = NULL, $cond = NULL, $retColumn =
self::$participantStatus = [];
}

$index = $cond ? $cond : 'No Condition';
$index = $cond ?: 'No Condition';
$index = "{$index}_{$retColumn}";
if (empty(self::$participantStatus[$index])) {
self::$participantStatus[$index] = [];
Expand Down Expand Up @@ -183,7 +183,7 @@ public static function &participantStatusClass() {
* array reference of all participant roles if any
*/
public static function &participantRole($id = NULL, $cond = NULL) {
$index = $cond ? $cond : 'No Condition';
$index = $cond ?: 'No Condition';
if (empty(self::$participantRole[$index])) {
self::$participantRole[$index] = [];

Expand Down
2 changes: 1 addition & 1 deletion CRM/Logging/ReportDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ public function getLimit($rowCount = self::ROW_COUNT_LIMIT) {
unset($_POST['crmPID_B'], $_POST['crmPID']);
}

$pageId = $pageId ? $pageId : 1;
$pageId = $pageId ?: 1;
$offset = ($pageId - 1) * $rowCount;

$offset = CRM_Utils_Type::escape($offset, 'Int');
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/PseudoConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public static function mailingTypes() {
* array reference of all mailing components
*/
public static function &component($type = NULL) {
$name = $type ? $type : 'ALL';
$name = $type ?: 'ALL';

if (!self::$component || !array_key_exists($name, self::$component)) {
if (!self::$component) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Mailing/Selector/Browse.php
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
$actionMask,
[
'mid' => $row['id'],
'hashOrMid' => $hash ? $hash : $row['id'],
'hashOrMid' => $hash ?: $row['id'],
],
"more",
FALSE,
Expand Down
2 changes: 1 addition & 1 deletion CRM/PCP/Page/PCPInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function run() {
}

$this->assign('honor', $honor);
$this->assign('total', $totalAmount ? $totalAmount : '0.0');
$this->assign('total', $totalAmount ?: '0.0');
$this->assign('achieved', $achieved <= 100 ? $achieved : 100);

if ($achieved <= 100) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Pledge/BAO/Pledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ public static function updatePledgeStatus(array $params): array {
// 2. send acknowledgement mail
if ($toEmail && !($doNotEmail || $onHold)) {
// assign value to template
$template->assign('amount_paid', $details['amount_paid'] ? $details['amount_paid'] : 0);
$template->assign('amount_paid', $details['amount_paid'] ?: 0);
$template->assign('next_payment', $details['scheduled_date']);
$template->assign('amount_due', $details['amount_due']);
$template->assign('checksumValue', $details['checksumValue']);
Expand Down
6 changes: 3 additions & 3 deletions CRM/Profile/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ public function buildQuickForm(): void {
$return = TRUE;
if (!$statusMessage) {
$statusMessage = ts("This profile is configured for contact type '%1'. It cannot be used to edit contacts of other types.",
[1 => $profileSubType ? $profileSubType : $profileType]);
[1 => $profileSubType ?: $profileType]);
}
}
}
Expand Down Expand Up @@ -1367,7 +1367,7 @@ public function checkTemplateFileExists($suffix = NULL) {
*/
public function getTemplateFileName() {
$fileName = $this->checkTemplateFileExists();
return $fileName ? $fileName : parent::getTemplateFileName();
return $fileName ?: parent::getTemplateFileName();
}

/**
Expand All @@ -1378,7 +1378,7 @@ public function getTemplateFileName() {
*/
public function overrideExtraTemplateFileName() {
$fileName = $this->checkTemplateFileExists('extra.');
return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
return $fileName ?: parent::overrideExtraTemplateFileName();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions CRM/Profile/Page/Dynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public function checkTemplateFileExists($suffix = NULL) {
*/
public function getTemplateFileName() {
$fileName = $this->checkTemplateFileExists();
return $fileName ? $fileName : parent::getTemplateFileName();
return $fileName ?: parent::getTemplateFileName();
}

/**
Expand All @@ -431,7 +431,7 @@ public function getTemplateFileName() {
*/
public function overrideExtraTemplateFileName() {
$fileName = $this->checkTemplateFileExists('extra.');
return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
return $fileName ?: parent::overrideExtraTemplateFileName();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions CRM/Profile/Page/Listings.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ public function checkTemplateFileExists($suffix = NULL) {
*/
public function getTemplateFileName() {
$fileName = $this->checkTemplateFileExists();
return $fileName ? $fileName : parent::getTemplateFileName();
return $fileName ?: parent::getTemplateFileName();
}

/**
Expand All @@ -494,7 +494,7 @@ public function getTemplateFileName() {
*/
public function overrideExtraTemplateFileName() {
$fileName = $this->checkTemplateFileExists('extra.');
return $fileName ? $fileName : parent::overrideExtraTemplateFileName();
return $fileName ?: parent::overrideExtraTemplateFileName();
}

}
Loading