Skip to content

Commit

Permalink
[REF] Swap CRM_Utils_Array::value for ??
Browse files Browse the repository at this point in the history
PHP 7 finally has a built-in language construct that does basically the same thing as this homebrew function.
  • Loading branch information
colemanw committed Aug 9, 2019
1 parent a0b0155 commit e22cbd1
Show file tree
Hide file tree
Showing 273 changed files with 759 additions and 765 deletions.
2 changes: 1 addition & 1 deletion CRM/ACL/Form/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ public function postProcess() {
}
else {
$params = $this->controller->exportValues($this->_name);
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['is_active'] = $params['is_active'] ?? FALSE;
$params['deny'] = 0;
$params['entity_table'] = 'civicrm_acl_role';

Expand Down
16 changes: 8 additions & 8 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ public static function create(&$params) {
$assignmentParams = ['activity_id' => $activityId];

if (is_array($params['assignee_contact_id'])) {
if (CRM_Utils_Array::value('deleteActivityAssignment', $params, TRUE)) {
if (!empty($params['deleteActivityAssignment'])) {
// first delete existing assignments if any
self::deleteActivityContact($activityId, $assigneeID);
}
Expand Down Expand Up @@ -416,7 +416,7 @@ public static function create(&$params) {
}
}
else {
if (CRM_Utils_Array::value('deleteActivityAssignment', $params, TRUE)) {
if (!empty($params['deleteActivityAssignment'])) {
self::deleteActivityContact($activityId, $assigneeID);
}
}
Expand All @@ -433,7 +433,7 @@ public static function create(&$params) {
$targetParams = ['activity_id' => $activityId];
$resultTarget = [];
if (is_array($params['target_contact_id'])) {
if (CRM_Utils_Array::value('deleteActivityTarget', $params, TRUE)) {
if (!empty($params['deleteActivityTarget'])) {
// first delete existing targets if any
self::deleteActivityContact($activityId, $targetID);
}
Expand Down Expand Up @@ -469,7 +469,7 @@ public static function create(&$params) {
}
}
else {
if (CRM_Utils_Array::value('deleteActivityTarget', $params, TRUE)) {
if (!empty($params['deleteActivityTarget'])) {
self::deleteActivityContact($activityId, $targetID);
}
}
Expand Down Expand Up @@ -764,13 +764,13 @@ public static function getActivities($params) {
'activity_id' => $activity['id'],
'activity_date_time' => CRM_Utils_Array::value('activity_date_time', $activity),
'subject' => CRM_Utils_Array::value('subject', $activity),
'assignee_contact_name' => CRM_Utils_Array::value('assignee_contact_sort_name', $activity, []),
'assignee_contact_name' => $activity['assignee_contact_sort_name'] ?? [],
'source_contact_id' => CRM_Utils_Array::value('source_contact_id', $activity),
'source_contact_name' => CRM_Utils_Array::value('source_contact_sort_name', $activity),
];
$activities[$id]['activity_type_name'] = CRM_Core_PseudoConstant::getName('CRM_Activity_BAO_Activity', 'activity_type_id', $activity['activity_type_id']);
$activities[$id]['activity_type'] = CRM_Core_PseudoConstant::getLabel('CRM_Activity_BAO_Activity', 'activity_type_id', $activity['activity_type_id']);
$activities[$id]['target_contact_count'] = CRM_Utils_Array::value('target_contact_count', $activity, 0);
$activities[$id]['target_contact_count'] = $activity['target_contact_count'] ?? 0;
if (!empty($activity['target_contact_count'])) {
$displayedTarget = civicrm_api3('ActivityContact', 'get', [
'activity_id' => $id,
Expand Down Expand Up @@ -1329,7 +1329,7 @@ public static function sendSMS(
$smsProviderParams['To'] = '';
}

$doNotSms = CRM_Utils_Array::value('do_not_sms', $contact, 0);
$doNotSms = $contact['do_not_sms'] ?? 0;

if ($doNotSms) {
$errMsgs[] = PEAR::raiseError('Contact Does not accept SMS', NULL, PEAR_ERROR_RETURN);
Expand Down Expand Up @@ -2427,7 +2427,7 @@ protected static function getActivityParamsForDashboardFunctions($params) {
'activity_date_time' => CRM_Utils_Array::value('activity_date_time', $params),
'check_permissions' => 1,
'options' => [
'offset' => CRM_Utils_Array::value('offset', $params, 0),
'offset' => $params['offset'] ?? 0,
],
];

Expand Down
2 changes: 1 addition & 1 deletion CRM/Activity/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ public static function selectorReturnProperties() {
public static function whereClauseSingleActivityText(&$values, &$query) {
list($name, $op, $value, $grouping, $wildcard) = $values;
$activityOptionValues = $query->getWhereValues('activity_option', $grouping);
$activityOption = CRM_Utils_Array::value(2, $activityOptionValues, 6);
$activityOption = $activityOptionValues[2] ?? 6;

$query->_useDistinct = TRUE;

Expand Down
2 changes: 1 addition & 1 deletion CRM/Activity/Form/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public function preProcess() {

if ($this->_action & CRM_Core_Action::VIEW) {
$url = CRM_Utils_System::url(implode("/", $this->urlPath), "reset=1&id={$this->_activityId}&action=view&cid={$this->_values['source_contact_id']}");
CRM_Utils_Recent::add(CRM_Utils_Array::value('subject', $this->_values, ts('(no subject)')),
CRM_Utils_Recent::add($this->_values['subject'] ?? ts('(no subject)'),
$url,
$this->_values['id'],
'Activity',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Activity/Form/ActivityView.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function preProcess() {
}
if ($engagementLevel = CRM_Utils_Array::value('engagement_level', $defaults)) {
$engagementLevels = CRM_Campaign_PseudoConstant::engagementLevel();
$values['engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel);
$values['engagement_level'] = $engagementLevels[$engagementLevel] ?? $engagementLevel;
}

$values['attachment'] = CRM_Core_BAO_File::attachmentInfo('civicrm_activity', $activityId);
Expand Down
6 changes: 3 additions & 3 deletions CRM/Activity/Import/Parser/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public function init() {
]);

foreach ($fields as $name => $field) {
$field['type'] = CRM_Utils_Array::value('type', $field, CRM_Utils_Type::T_INT);
$field['dataPattern'] = CRM_Utils_Array::value('dataPattern', $field, '//');
$field['headerPattern'] = CRM_Utils_Array::value('headerPattern', $field, '//');
$field['type'] = $field['type'] ?? CRM_Utils_Type::T_INT;
$field['dataPattern'] = $field['dataPattern'] ?? '//';
$field['headerPattern'] = $field['headerPattern'] ?? '//';
$this->addField($name, $field['title'], $field['type'], $field['headerPattern'], $field['dataPattern']);
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Activity/Selector/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL, $ca
$row['status'] = $row['status_id'] ? $activityStatus[$row['status_id']] : NULL;

if ($engagementLevel = CRM_Utils_Array::value('engagement_level', $row)) {
$row['engagement_level'] = CRM_Utils_Array::value($engagementLevel, $engagementLevels, $engagementLevel);
$row['engagement_level'] = $engagementLevels[$engagementLevel] ?? $engagementLevel;
}

// CRM-3553
Expand Down
2 changes: 1 addition & 1 deletion CRM/Admin/Form/Extensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public function postProcess() {
'version' => 3,
'key' => $this->_key,
]);
if (!CRM_Utils_Array::value('is_error', $result, FALSE)) {
if (empty($result['is_error'])) {
CRM_Core_Session::setStatus("", ts('Extension Upgraded'), "success");
}
else {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Admin/Form/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function postProcess() {
$dao->api_entity = $values['api_entity'];
$dao->api_action = $values['api_action'];
$dao->description = $values['description'];
$dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
$dao->is_active = $values['is_active'] ?? 0;

// CRM-17686
$ts = strtotime($values['scheduled_run_date']);
Expand Down
4 changes: 2 additions & 2 deletions CRM/Admin/Form/LocationType.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public function postProcess() {

// store the submitted values in an array
$params = $this->exportValues();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
$params['is_active'] = $params['is_active'] ?? FALSE;
$params['is_default'] = $params['is_default'] ?? FALSE;

// action is taken depending upon the mode
$locationType = new CRM_Core_DAO_LocationType();
Expand Down
2 changes: 1 addition & 1 deletion CRM/Admin/Form/MailSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public function postProcess() {
'is_default',
'is_ssl',
])) {
$params[$f] = CRM_Utils_Array::value($f, $formValues, FALSE);
$params[$f] = $formValues[$f] ?? FALSE;
}
else {
$params[$f] = CRM_Utils_Array::value($f, $formValues);
Expand Down
4 changes: 2 additions & 2 deletions CRM/Admin/Form/ParticipantStatusType.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public function postProcess() {
'name' => CRM_Utils_Array::value('name', $formValues),
'label' => CRM_Utils_Array::value('label', $formValues),
'class' => CRM_Utils_Array::value('class', $formValues),
'is_active' => CRM_Utils_Array::value('is_active', $formValues, FALSE),
'is_counted' => CRM_Utils_Array::value('is_counted', $formValues, FALSE),
'is_active' => $formValues['is_active'] ?? FALSE,
'is_counted' => $formValues['is_counted'] ?? FALSE,
'weight' => CRM_Utils_Array::value('weight', $formValues),
'visibility_id' => CRM_Utils_Array::value('visibility_id', $formValues),
];
Expand Down
8 changes: 4 additions & 4 deletions CRM/Admin/Form/PaymentProcessorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function buildQuickForm($check = FALSE) {
$attributes = CRM_Core_DAO::getAttribute('CRM_Financial_DAO_PaymentProcessorType');

foreach ($this->_fields as $field) {
$required = CRM_Utils_Array::value('required', $field, FALSE);
$required = $field['required'] ?? FALSE;
$this->add('text', $field['name'],
$field['label'], $attributes['name'], $required
);
Expand Down Expand Up @@ -221,9 +221,9 @@ public function postProcess() {
$dao = new CRM_Financial_DAO_PaymentProcessorType();

$dao->id = $this->_id;
$dao->is_default = CRM_Utils_Array::value('is_default', $values, 0);
$dao->is_active = CRM_Utils_Array::value('is_active', $values, 0);
$dao->is_recur = CRM_Utils_Array::value('is_recur', $values, 0);
$dao->is_default = $values['is_default'] ?? 0;
$dao->is_active = $values['is_active'] ?? 0;
$dao->is_recur = $values['is_recur'] ?? 0;

$dao->name = $values['name'];
$dao->description = $values['description'];
Expand Down
4 changes: 2 additions & 2 deletions CRM/Admin/Form/Preferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function setDefaultValues() {
foreach ($this->_varNames as $groupName => $settings) {
CRM_Core_Error::deprecatedFunctionWarning('deprecated use of preferences form. This will be removed from core soon');
foreach ($settings as $settingName => $settingDetails) {
$this->_defaults[$settingName] = isset($this->_config->$settingName) ? $this->_config->$settingName : CRM_Utils_Array::value('default', $settingDetails, NULL);
$this->_defaults[$settingName] = $this->_config->$settingName ?? $settingDetails['default'] ?? NULL;
}
}

Expand Down Expand Up @@ -218,7 +218,7 @@ public function buildQuickForm() {
break;

case 'entity_reference':
$this->addEntityRef($fieldName, $fieldValue['title'], CRM_Utils_Array::value('options', $fieldValue, []));
$this->addEntityRef($fieldName, $fieldValue['title'], $fieldValue['options'] ?? []);
}
}

Expand Down
2 changes: 1 addition & 1 deletion CRM/Admin/Form/Preferences/Contribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public function postProcess() {
// too. This means that saving from api will not have the desired core effect.
// but we should fix that elsewhere - ie. stop abusing the settings
// and fix the code repetition associated with invoicing
$invoiceParams['invoicing'] = CRM_Utils_Array::value('invoicing', $params, 0);
$invoiceParams['invoicing'] = $params['invoicing'] ?? 0;
Civi::settings()->set('contribution_invoice_settings', $invoiceParams);
parent::postProcess();
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Admin/Form/RelationshipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public function postProcess() {
else {
// store the submitted values in an array
$params = $this->exportValues();
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['is_active'] = $params['is_active'] ?? FALSE;

if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
Expand Down
14 changes: 7 additions & 7 deletions CRM/Admin/Form/ScheduleReminders.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ public static function formRule($fields, $files, $self) {
$errors['entity'] = ts('Please select appropriate value');
}

$mode = CRM_Utils_Array::value('mode', $fields, FALSE);
$mode = $fields['mode'] ?? FALSE;
if (!empty($fields['is_active']) &&
CRM_Utils_System::isNull($fields['subject']) && (!$mode || $mode != 'SMS')
) {
Expand Down Expand Up @@ -508,7 +508,7 @@ public function parseActionSchedule($values) {
$params[$key] = CRM_Utils_Array::value($key, $values);
}

$params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0);
$params['is_repeat'] = $values['is_repeat'] ?? 0;

$moreKeys = [
'start_action_offset',
Expand Down Expand Up @@ -569,13 +569,13 @@ public function parseActionSchedule($values) {
$params['limit_to'] = 1;
}

$entity_value = CRM_Utils_Array::value(1, $values['entity'], []);
$entity_status = CRM_Utils_Array::value(2, $values['entity'], []);
$entity_value = $values['entity'][1] ?? [];
$entity_status = $values['entity'][2] ?? [];
$params['entity_value'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $entity_value);
$params['entity_status'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $entity_status);
}

$params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0);
$params['is_active'] = $values['is_active'] ?? 0;

if (CRM_Utils_Array::value('is_repeat', $values) == 0) {
$params['repetition_frequency_unit'] = 'null';
Expand All @@ -587,9 +587,9 @@ public function parseActionSchedule($values) {
}

// multilingual options
$params['filter_contact_language'] = CRM_Utils_Array::value('filter_contact_language', $values, []);
$params['filter_contact_language'] = $values['filter_contact_language'] ?? [];
$params['filter_contact_language'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $params['filter_contact_language']);
$params['communication_language'] = CRM_Utils_Array::value('communication_language', $values, NULL);
$params['communication_language'] = $values['communication_language'] ?? NULL;

if ($this->_action & CRM_Core_Action::UPDATE) {
$params['id'] = $this->_id;
Expand Down
4 changes: 2 additions & 2 deletions CRM/Admin/Form/SettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ protected function addFieldsDefinedInSettingsMetadata() {
$props['html_type'],
$setting,
$props['title'],
($options !== NULL) ? $options : CRM_Utils_Array::value('html_attributes', $props, []),
($options !== NULL) ? CRM_Utils_Array::value('html_attributes', $props, []) : NULL
($options !== NULL) ? $options : $props['html_attributes'] ?? [],
($options !== NULL) ? $props['html_attributes'] ?? [] : NULL
);
}
elseif ($add == 'addSelect') {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Admin/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public static function recipientListing() {
* Used by jstree to incrementally load tags
*/
public static function getTagTree() {
$parent = CRM_Utils_Type::escape(CRM_Utils_Array::value('parent_id', $_GET, 0), 'Integer');
$parent = CRM_Utils_Type::escape($_GET['parent_id'] ?? 0, 'Integer');
$substring = CRM_Utils_Type::escape(CRM_Utils_Array::value('str', $_GET), 'String');
$result = [];

Expand Down
2 changes: 1 addition & 1 deletion CRM/Admin/Page/CKEditorConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class CRM_Admin_Page_CKEditorConfig extends CRM_Core_Page {
* @return string
*/
public function run() {
$this->preset = CRM_Utils_Array::value('preset', $_REQUEST, 'default');
$this->preset = $_REQUEST['preset'] ?? 'default';

// If the form was submitted, take appropriate action.
if (!empty($_POST['revert'])) {
Expand Down
6 changes: 3 additions & 3 deletions CRM/Badge/BAO/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ public static function setIsActive($id, $is_active) {
* @return object
*/
public static function create(&$params) {
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE);
$params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
$params['is_active'] = $params['is_active'] ?? FALSE;
$params['is_default'] = $params['is_default'] ?? FALSE;
$params['is_reserved'] = $params['is_reserved'] ?? FALSE;

$params['label_type_id'] = CRM_Core_PseudoConstant::getKey('CRM_Core_DAO_PrintLabel', 'label_type_id', 'Event Badge');

Expand Down
2 changes: 1 addition & 1 deletion CRM/Badge/Form/Layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function buildQuickForm() {
public function setDefaultValues() {
if (isset($this->_id)) {
$defaults = array_merge($this->_values,
CRM_Badge_BAO_Layout::getDecodedData(CRM_Utils_Array::value('data', $this->_values, '[]')));
CRM_Badge_BAO_Layout::getDecodedData($this->_values['data'] ?? '[]'));
}
else {
for ($i = 1; $i <= self::FIELD_ROWCOUNT; $i++) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Campaign/Form/Campaign.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ public function postProcess() {
$params['created_date'] = date('YmdHis');
}
// format params
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE);
$params['is_active'] = $params['is_active'] ?? FALSE;
$params['last_modified_id'] = $session->get('userID');
$params['last_modified_date'] = date('YmdHis');
$result = self::submit($params, $this);
Expand Down
8 changes: 4 additions & 4 deletions CRM/Campaign/Form/Petition.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function postProcess() {

$params['last_modified_id'] = $session->get('userID');
$params['last_modified_date'] = date('YmdHis');
$params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE);
$params['is_share'] = $params['is_share'] ?? FALSE;

if ($this->_surveyId) {

Expand All @@ -325,9 +325,9 @@ public function postProcess() {
$params['created_date'] = date('YmdHis');
}

$params['bypass_confirm'] = CRM_Utils_Array::value('bypass_confirm', $params, 0);
$params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);
$params['bypass_confirm'] = $params['bypass_confirm'] ?? 0;
$params['is_active'] = $params['is_active'] ?? 0;
$params['is_default'] = $params['is_default'] ?? 0;

$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->getEntityId(), $this->getDefaultEntity());

Expand Down
4 changes: 2 additions & 2 deletions CRM/Campaign/Form/Survey/Main.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ public function postProcess() {
$params['created_date'] = date('YmdHis');
}

$params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0);
$params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0);
$params['is_active'] = $params['is_active'] ?? 0;
$params['is_default'] = $params['is_default'] ?? 0;

$params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $this->getEntityId(), $this->getDefaultEntity());

Expand Down
2 changes: 1 addition & 1 deletion CRM/Campaign/Form/Task/Reserve.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private function _addRespondentToGroup($contactIds) {
}

$params = $this->controller->exportValues($this->_name);
$groups = CRM_Utils_Array::value('groups', $params, []);
$groups = $params['groups'] ?? [];
$newGroupName = CRM_Utils_Array::value('newGroupName', $params);
$newGroupDesc = CRM_Utils_Array::value('newGroupDesc', $params);

Expand Down
2 changes: 1 addition & 1 deletion CRM/Campaign/Page/DashBoard.php
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ public function browse() {
->addScriptFile('civicrm', 'templates/CRM/common/TabHeader.js', 1, 'html-header')
->addSetting([
'tabSettings' => [
'active' => strtolower(CRM_Utils_Array::value('subPage', $_GET, 'campaign')),
'active' => strtolower($_GET['subPage'] ?? 'campaign'),
],
]);
}
Expand Down
Loading

0 comments on commit e22cbd1

Please sign in to comment.