Skip to content

Commit

Permalink
Replace CRM_Utils_Array::value with ?? in variable assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
colemanw committed Mar 16, 2020
1 parent 9e1d75a commit 19bdc6b
Show file tree
Hide file tree
Showing 398 changed files with 1,698 additions and 1,698 deletions.
10 changes: 5 additions & 5 deletions CRM/ACL/Page/ACL.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,30 +135,30 @@ public function browse() {
$acl[$dao->id]['is_active'] = $dao->is_active;

if ($acl[$dao->id]['entity_id']) {
$acl[$dao->id]['entity'] = CRM_Utils_Array::value($acl[$dao->id]['entity_id'], $roles);
$acl[$dao->id]['entity'] = $roles[$acl[$dao->id]['entity_id']] ?? NULL;
}
else {
$acl[$dao->id]['entity'] = ts('Everyone');
}

switch ($acl[$dao->id]['object_table']) {
case 'civicrm_saved_search':
$acl[$dao->id]['object'] = CRM_Utils_Array::value($acl[$dao->id]['object_id'], $group);
$acl[$dao->id]['object'] = $group[$acl[$dao->id]['object_id']] ?? NULL;
$acl[$dao->id]['object_name'] = ts('Group');
break;

case 'civicrm_uf_group':
$acl[$dao->id]['object'] = CRM_Utils_Array::value($acl[$dao->id]['object_id'], $ufGroup);
$acl[$dao->id]['object'] = $ufGroup[$acl[$dao->id]['object_id']] ?? NULL;
$acl[$dao->id]['object_name'] = ts('Profile');
break;

case 'civicrm_custom_group':
$acl[$dao->id]['object'] = CRM_Utils_Array::value($acl[$dao->id]['object_id'], $customGroup);
$acl[$dao->id]['object'] = $customGroup[$acl[$dao->id]['object_id']] ?? NULL;
$acl[$dao->id]['object_name'] = ts('Custom Group');
break;

case 'civicrm_event':
$acl[$dao->id]['object'] = CRM_Utils_Array::value($acl[$dao->id]['object_id'], $event);
$acl[$dao->id]['object'] = $event[$acl[$dao->id]['object_id']] ?? NULL;
$acl[$dao->id]['object_name'] = ts('Event');
break;
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/ACL/Page/ACLBasic.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function browse() {
$acl[$dao->entity_id]['name'] = $dao->name;
$acl[$dao->entity_id]['entity_id'] = $dao->entity_id;
$acl[$dao->entity_id]['entity_table'] = $dao->entity_table;
$acl[$dao->entity_id]['object_table'] = CRM_Utils_Array::value($dao->object_table, $permissions);
$acl[$dao->entity_id]['object_table'] = $permissions[$dao->object_table] ?? NULL;
$acl[$dao->entity_id]['is_active'] = 1;

if ($acl[$dao->entity_id]['entity_id']) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/ACL/Page/EntityRole.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function browse() {
$entityRoles[$dao->id] = [];
CRM_Core_DAO::storeValues($dao, $entityRoles[$dao->id]);

$entityRoles[$dao->id]['acl_role'] = CRM_Utils_Array::value($dao->acl_role_id, $aclRoles);
$entityRoles[$dao->id]['acl_role'] = $aclRoles[$dao->acl_role_id] ?? NULL;
$entityRoles[$dao->id]['entity'] = $groups[$dao->entity_id];

// form all action links
Expand Down
26 changes: 13 additions & 13 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static function deleteActivity(&$params, $moveToTrash = FALSE) {
$sourceRecordIds = implode(',', $params['source_record_id']);
}
else {
$sourceRecordIds = CRM_Utils_Array::value('source_record_id', $params);
$sourceRecordIds = $params['source_record_id'] ?? NULL;
}

$result = NULL;
Expand Down Expand Up @@ -490,7 +490,7 @@ public static function create(&$params) {
}
else {
// at worst, take source for recently viewed display
$recentContactId = CRM_Utils_Array::value('source_contact_id', $params);
$recentContactId = $params['source_contact_id'] ?? NULL;
}

if (isset($params['assignee_contact_id'])) {
Expand Down Expand Up @@ -582,7 +582,7 @@ public static function create(&$params) {

// if the subject contains a ‘[case #…]’ string, file that activity on the related case (CRM-5916)
$matches = [];
$subjectToMatch = CRM_Utils_Array::value('subject', $params);
$subjectToMatch = $params['subject'] ?? NULL;
if (preg_match('/\[case #([0-9a-h]{7})\]/', $subjectToMatch, $matches)) {
$key = CRM_Core_DAO::escapeString(CIVICRM_SITE_KEY);
$hash = $matches[1];
Expand Down Expand Up @@ -804,7 +804,7 @@ public static function getActivities($params) {
}
// case related fields
elseif ($apiKey == 'case_id' && !$isBulkActivity) {
$activities[$id][$expectedName] = CRM_Utils_Array::value($apiKey, $activity);
$activities[$id][$expectedName] = $activity[$apiKey] ?? NULL;

// fetch case subject for case ID found
if (!empty($activity['case_id'])) {
Expand All @@ -815,9 +815,9 @@ public static function getActivities($params) {
}
else {
// @todo this generic assign could just be handled in array declaration earlier.
$activities[$id][$expectedName] = CRM_Utils_Array::value($apiKey, $activity);
$activities[$id][$expectedName] = $activity[$apiKey] ?? NULL;
if ($apiKey == 'campaign_id') {
$activities[$id]['campaign'] = CRM_Utils_Array::value($activities[$id][$expectedName], $allCampaigns);
$activities[$id]['campaign'] = $allCampaigns[$activities[$id][$expectedName]] ?? NULL;
}
}
}
Expand Down Expand Up @@ -1427,7 +1427,7 @@ public static function sendSMSMessage(
// To get primary mobile phonenumber, if not get the first mobile phonenumber
if (!empty($toPhoneNumbers)) {
$toPhoneNumberDetails = reset($toPhoneNumbers);
$toPhoneNumber = CRM_Utils_Array::value('phone', $toPhoneNumberDetails);
$toPhoneNumber = $toPhoneNumberDetails['phone'] ?? NULL;
// Contact allows to send sms
}
}
Expand Down Expand Up @@ -2002,8 +2002,8 @@ public static function createFollowupActivity($activityId, $params) {

$followupParams['activity_type_id'] = $params['followup_activity_type_id'];
// Get Subject of Follow-up Activiity, CRM-4491
$followupParams['subject'] = CRM_Utils_Array::value('followup_activity_subject', $params);
$followupParams['assignee_contact_id'] = CRM_Utils_Array::value('followup_assignee_contact_id', $params);
$followupParams['subject'] = $params['followup_activity_subject'] ?? NULL;
$followupParams['assignee_contact_id'] = $params['followup_assignee_contact_id'] ?? NULL;

// Create target contact for followup.
if (!empty($params['target_contact_id'])) {
Expand Down Expand Up @@ -2523,9 +2523,9 @@ public static function getContactActivitySelector(&$params) {
// Format the params.
$params['offset'] = ($params['page'] - 1) * $params['rp'];
$params['rowCount'] = $params['rp'];
$params['sort'] = CRM_Utils_Array::value('sortBy', $params);
$params['sort'] = $params['sortBy'] ?? NULL;
$params['caseId'] = NULL;
$context = CRM_Utils_Array::value('context', $params);
$context = $params['context'] ?? NULL;
$showContactOverlay = !CRM_Utils_String::startsWith($context, "dashlet");
$activityTypeInfo = civicrm_api3('OptionValue', 'get', [
'option_group_id' => "activity_type",
Expand Down Expand Up @@ -2897,8 +2897,8 @@ public function setApiFilter(&$params) {
*/
public static function sendToAssignee($activity, $mailToContacts, $params = []) {
if (!CRM_Utils_Array::crmIsEmptyArray($mailToContacts)) {
$clientID = CRM_Utils_Array::value('client_id', $params);
$caseID = CRM_Utils_Array::value('case_id', $params);
$clientID = $params['client_id'] ?? NULL;
$caseID = $params['case_id'] ?? NULL;

$ics = new CRM_Activity_BAO_ICalendar($activity);
$attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id);
Expand Down
16 changes: 8 additions & 8 deletions CRM/Activity/Form/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public function setFields() {
*/
public function preProcess() {
CRM_Core_Form_RecurringEntity::preProcess('civicrm_activity');
$this->_atypefile = CRM_Utils_Array::value('atypefile', $_GET);
$this->_atypefile = $_GET['atypefile'] ?? NULL;
$this->assign('atypefile', FALSE);
if ($this->_atypefile) {
$this->assign('atypefile', TRUE);
Expand Down Expand Up @@ -444,7 +444,7 @@ public function preProcess() {

// hack to retrieve activity type id from post variables
if (!$this->_activityTypeId) {
$this->_activityTypeId = CRM_Utils_Array::value('activity_type_id', $_POST);
$this->_activityTypeId = $_POST['activity_type_id'] ?? NULL;
}

// when custom data is included in this page
Expand Down Expand Up @@ -540,8 +540,8 @@ public function setDefaultValues() {
}

// Fixme: why are we getting the wrong keys from upstream?
$defaults['target_contact_id'] = CRM_Utils_Array::value('target_contact', $defaults);
$defaults['assignee_contact_id'] = CRM_Utils_Array::value('assignee_contact', $defaults);
$defaults['target_contact_id'] = $defaults['target_contact'] ?? NULL;
$defaults['assignee_contact_id'] = $defaults['assignee_contact'] ?? NULL;

// set default tags if exists
$defaults['tag'] = implode(',', CRM_Core_BAO_EntityTag::getTag($this->_activityId, 'civicrm_activity'));
Expand Down Expand Up @@ -649,7 +649,7 @@ public function buildQuickForm() {

foreach ($this->_fields as $field => $values) {
if (!empty($this->_fields[$field])) {
$attribute = CRM_Utils_Array::value('attributes', $values);
$attribute = $values['attributes'] ?? NULL;
$required = !empty($values['required']);

if ($values['type'] == 'select' && empty($attribute)) {
Expand Down Expand Up @@ -831,8 +831,8 @@ public static function formRule($fields, $files, $self) {
$errors['activity_type_id'] = ts('Activity Type is a required field');
}

$activity_type_id = CRM_Utils_Array::value('activity_type_id', $fields);
$activity_status_id = CRM_Utils_Array::value('status_id', $fields);
$activity_type_id = $fields['activity_type_id'] ?? NULL;
$activity_status_id = $fields['status_id'] ?? NULL;
$scheduled_status_id = CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'status_id', 'Scheduled');

if ($activity_type_id && $activity_status_id == $scheduled_status_id) {
Expand Down Expand Up @@ -1237,7 +1237,7 @@ public function assignActivityType() {
// Set title.
if (isset($activityTypeDisplayLabels)) {
// FIXME - it's not clear why the if line just above is needed here and why we can't just set this once above and re-use. What is interesting, but can't possibly be the reason, is that the first if block will fail if the label is the string '0', whereas this one won't. But who would have an activity type called '0'?
$activityTypeDisplayLabel = CRM_Utils_Array::value($this->_activityTypeId, $activityTypeDisplayLabels);
$activityTypeDisplayLabel = $activityTypeDisplayLabels[$this->_activityTypeId] ?? NULL;

if ($this->_currentlyViewedContactId) {
$displayName = CRM_Contact_BAO_Contact::displayName($this->_currentlyViewedContactId);
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 @@ -59,7 +59,7 @@ public function preProcess() {
$this->assign('activityTypeDescription', $activityTypeDescription);

if (!empty($defaults['mailingId'])) {
$this->_mailing_id = CRM_Utils_Array::value('source_record_id', $defaults);
$this->_mailing_id = $defaults['source_record_id'] ?? NULL;
$mailingReport = CRM_Mailing_BAO_Mailing::report($this->_mailing_id, TRUE);
CRM_Mailing_BAO_Mailing::getMailingContent($mailingReport, $this);
$this->assign('mailingReport', $mailingReport);
Expand Down
2 changes: 1 addition & 1 deletion CRM/Activity/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function fixFormValues() {

if ($survey) {
$this->_formValues['activity_survey_id'] = $this->_defaults['activity_survey_id'] = $survey;
$sid = CRM_Utils_Array::value('activity_survey_id', $this->_formValues);
$sid = $this->_formValues['activity_survey_id'] ?? NULL;
$activity_type_id = CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Survey', $sid, 'activity_type_id');

// since checkbox are replaced by multiple select option
Expand Down
2 changes: 1 addition & 1 deletion CRM/Activity/Form/Task/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function buildQuickForm() {
$typeId = CRM_Core_DAO::getFieldValue("CRM_Activity_DAO_Activity", $activityId, 'activity_type_id');
foreach ($this->_fields as $name => $field) {
if ($customFieldID = CRM_Core_BAO_CustomField::getKeyID($name)) {
$customValue = CRM_Utils_Array::value($customFieldID, $customFields);
$customValue = $customFields[$customFieldID] ?? NULL;
if (!empty($customValue['extends_entity_column_value'])) {
$entityColumnValue = explode(CRM_Core_DAO::VALUE_SEPARATOR,
$customValue['extends_entity_column_value']
Expand Down
2 changes: 1 addition & 1 deletion CRM/Activity/Import/Form/MapField.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public static function formRule($fields) {
}

if (!empty($fields['saveMapping'])) {
$nameField = CRM_Utils_Array::value('saveMappingName', $fields);
$nameField = $fields['saveMappingName'] ?? NULL;
if (empty($nameField)) {
$errors['saveMappingName'] = ts('Name is required to save Import Mapping');
}
Expand Down
2 changes: 1 addition & 1 deletion CRM/Activity/Page/AJAX.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public static function convertToCaseActivity() {
$params = ['caseID', 'activityID', 'contactID', 'newSubject', 'targetContactIds', 'mode'];
$vals = [];
foreach ($params as $param) {
$vals[$param] = CRM_Utils_Array::value($param, $_POST);
$vals[$param] = $_POST[$param] ?? NULL;
}

CRM_Utils_JSON::output(self::_convertToCaseActivity($vals));
Expand Down
6 changes: 3 additions & 3 deletions CRM/Activity/Selector/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
}
}

$contactId = CRM_Utils_Array::value('contact_id', $row);
$contactId = $row['contact_id'] ?? NULL;
if (!$contactId) {
$contactId = CRM_Utils_Array::value('source_contact_id', $row);
$contactId = $row['source_contact_id'] ?? NULL;
}

$row['target_contact_name'] = CRM_Activity_BAO_ActivityContact::getNames($row['activity_id'], $targetID);
Expand Down Expand Up @@ -339,7 +339,7 @@ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
);

// Carry campaign to selector.
$row['campaign'] = CRM_Utils_Array::value($result->activity_campaign_id, $allCampaigns);
$row['campaign'] = $allCampaigns[$result->activity_campaign_id] ?? NULL;
$row['campaign_id'] = $result->activity_campaign_id;

if ($engagementLevel = CRM_Utils_Array::value('activity_engagement_level', $row)) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Activity/StateMachine/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function __construct($controller, $action = CRM_Core_Action::NONE) {
*/
public function taskName($controller, $formName = 'Search') {
// total hack, check POST vars and then session to determine stuff
$value = CRM_Utils_Array::value('task', $_POST);
$value = $_POST['task'] ?? NULL;
if (!isset($value)) {
$value = $this->_controller->get('task');
}
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 @@ -157,7 +157,7 @@ public function postProcess() {
$params[$f] = CRM_Utils_Array::value($f, $formValues, FALSE);
}
else {
$params[$f] = CRM_Utils_Array::value($f, $formValues);
$params[$f] = $formValues[$f] ?? NULL;
}
}

Expand Down
4 changes: 2 additions & 2 deletions CRM/Admin/Form/MessageTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function buildQuickForm() {
]);
}
else {
$this->_workflow_id = CRM_Utils_Array::value('workflow_id', $this->_values);
$this->_workflow_id = $this->_values['workflow_id'] ?? NULL;
$this->checkUserPermission($this->_workflow_id);
$this->assign('workflow_id', $this->_workflow_id);

Expand Down Expand Up @@ -289,7 +289,7 @@ public function postProcess() {
}
}

$this->_workflow_id = CRM_Utils_Array::value('workflow_id', $this->_values);
$this->_workflow_id = $this->_values['workflow_id'] ?? NULL;
if ($this->_workflow_id) {
$params['workflow_id'] = $this->_workflow_id;
$params['is_active'] = TRUE;
Expand Down
2 changes: 1 addition & 1 deletion CRM/Admin/Form/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function setDefaultValues() {
if (isset($this->_id)) {
//Take parent id in object variable to calculate the menu
//weight if menu parent id changed
$this->_currentParentID = CRM_Utils_Array::value('parent_id', $this->_defaults);
$this->_currentParentID = $this->_defaults['parent_id'] ?? NULL;
}
else {
$defaults['permission'] = "access CiviCRM";
Expand Down
2 changes: 1 addition & 1 deletion CRM/Admin/Form/ParticipantStatusType.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function setDefaultValues() {
if (empty($defaults['weight'])) {
$defaults['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Event_DAO_ParticipantStatusType');
}
$this->_isReserved = CRM_Utils_Array::value('is_reserved', $defaults);
$this->_isReserved = $defaults['is_reserved'] ?? NULL;
if ($this->_isReserved) {
$this->freeze(['name', 'class', 'is_active']);
}
Expand Down
6 changes: 3 additions & 3 deletions CRM/Admin/Form/RelationshipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ public function setDefaultValues() {
$params = ['id' => $this->_id];
$baoName = $this->_BAOName;
$baoName::retrieve($params, $defaults);
$defaults['contact_types_a'] = CRM_Utils_Array::value('contact_type_a', $defaults);
$defaults['contact_types_a'] = $defaults['contact_type_a'] ?? NULL;
if (!empty($defaults['contact_sub_type_a'])) {
$defaults['contact_types_a'] .= '__' . $defaults['contact_sub_type_a'];
}

$defaults['contact_types_b'] = CRM_Utils_Array::value('contact_type_b', $defaults);
$defaults['contact_types_b'] = $defaults['contact_type_b'] ?? NULL;
if (!empty($defaults['contact_sub_type_b'])) {
$defaults['contact_types_b'] .= '__' . $defaults['contact_sub_type_b'];
}
Expand Down Expand Up @@ -187,7 +187,7 @@ public function postProcess() {
$params['contact_sub_type_b'] = $cTypeB[1] ? $cTypeB[1] : 'null';

if (!strlen(trim(CRM_Utils_Array::value('label_b_a', $params)))) {
$params['label_b_a'] = CRM_Utils_Array::value('label_a_b', $params);
$params['label_b_a'] = $params['label_a_b'] ?? NULL;
}

if (empty($params['id'])) {
Expand Down
Loading

0 comments on commit 19bdc6b

Please sign in to comment.