Commit 0d48f1cc authored by totten's avatar totten

(NFC) Apply upcoming civicrm/coder policies (batch 1)

Method:

* Checkout latest merged branch of civicrm/coder (`8.x-2.x-civi`)
* Run this command to autoclean a batch of 100 files
 `PG=1 SIZE=100 ; find Civi/ CRM/ api/ bin/ extern/ tests/ -name '*.php' | grep -v /examples/ | grep -v /DAO/ | sort | head -n $(( $PG  * $SIZE )) | tail -n $SIZE | xargs phpcbf-civi`
* Go through the diff. For anything that looks wonky, open in an editor and find a better solution

Note: The automated checker makes good points about awkward indentation, but the automated cleanup often makes it
worse.  So that's why I have to open it up.
parent cf9ccf98
......@@ -141,30 +141,30 @@ class CRM_ACL_Form_ACL extends CRM_Admin_Form {
$label = ts('Role');
$role = [
'-1' => ts('- select role -'),
'0' => ts('Everyone'),
] + CRM_Core_OptionGroup::values('acl_role');
'-1' => ts('- select role -'),
'0' => ts('Everyone'),
] + CRM_Core_OptionGroup::values('acl_role');
$this->add('select', 'entity_id', $label, $role, TRUE);
$group = [
'-1' => ts('- select -'),
'0' => ts('All Groups'),
] + CRM_Core_PseudoConstant::group();
'-1' => ts('- select -'),
'0' => ts('All Groups'),
] + CRM_Core_PseudoConstant::group();
$customGroup = [
'-1' => ts('- select -'),
'0' => ts('All Custom Groups'),
] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
'-1' => ts('- select -'),
'0' => ts('All Custom Groups'),
] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
$ufGroup = [
'-1' => ts('- select -'),
'0' => ts('All Profiles'),
] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id');
'-1' => ts('- select -'),
'0' => ts('All Profiles'),
] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id');
$event = [
'-1' => ts('- select -'),
'0' => ts('All Events'),
] + CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
'-1' => ts('- select -'),
'0' => ts('All Events'),
] + CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
$this->add('select', 'group_id', ts('Group'), $group);
$this->add('select', 'custom_group_id', ts('Custom Data'), $customGroup);
......
......@@ -80,9 +80,9 @@ SELECT object_table
$label = ts('Role');
$role = [
'-1' => ts('- select role -'),
'0' => ts('Everyone'),
] + CRM_Core_OptionGroup::values('acl_role');
'-1' => ts('- select role -'),
'0' => ts('Everyone'),
] + CRM_Core_OptionGroup::values('acl_role');
$entityID = &$this->add('select', 'entity_id', $label, $role, TRUE);
if ($this->_id) {
......
......@@ -123,22 +123,22 @@ ORDER BY entity_id
$roles = CRM_Core_OptionGroup::values('acl_role');
$group = [
'-1' => ts('- select -'),
'0' => ts('All Groups'),
] + CRM_Core_PseudoConstant::group();
'-1' => ts('- select -'),
'0' => ts('All Groups'),
] + CRM_Core_PseudoConstant::group();
$customGroup = [
'-1' => ts('- select -'),
'0' => ts('All Custom Groups'),
] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
'-1' => ts('- select -'),
'0' => ts('All Custom Groups'),
] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_CustomField', 'custom_group_id');
$ufGroup = [
'-1' => ts('- select -'),
'0' => ts('All Profiles'),
] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id');
'-1' => ts('- select -'),
'0' => ts('All Profiles'),
] + CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id');
$event = [
'-1' => ts('- select -'),
'0' => ts('All Events'),
] + CRM_Event_PseudoConstant::event();
'-1' => ts('- select -'),
'0' => ts('All Events'),
] + CRM_Event_PseudoConstant::event();
while ($dao->fetch()) {
$acl[$dao->id] = [];
......
......@@ -30,7 +30,6 @@
* @copyright CiviCRM LLC (c) 2004-2019
*/
use Civi\ActionSchedule\RecipientBuilder;
/**
* Class CRM_Activity_ActionMapping
......
......@@ -1207,7 +1207,7 @@ class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
}
if (!isset($contactDetails) && !isset($contactIds)) {
Throw new CRM_Core_Exception('You must specify either $contactDetails or $contactIds');
throw new CRM_Core_Exception('You must specify either $contactDetails or $contactIds');
}
// Populate $contactDetails and $contactIds if only one is set
if (is_array($contactIds) && !empty($contactIds) && empty($contactDetails)) {
......@@ -2403,9 +2403,9 @@ INNER JOIN civicrm_option_group grp ON (grp.id = option_group_id AND grp.name =
$enabledComponents = self::activityComponents();
// @todo - should we move this to activity get api.
foreach ([
'case_id' => 'CiviCase',
'campaign_id' => 'CiviCampaign',
] as $attr => $component) {
'case_id' => 'CiviCase',
'campaign_id' => 'CiviCampaign',
] as $attr => $component) {
if (!in_array($component, $enabledComponents)) {
$activityParams[$attr] = ['IS NULL' => 1];
}
......
......@@ -260,11 +260,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
if (CRM_Contact_Form_Search::isSearchContext($this->_context)) {
$this->_context = 'search';
}
elseif (!in_array($this->_context, [
'dashlet',
'case',
'dashletFullscreen',
])
elseif (!in_array($this->_context, ['dashlet', 'case', 'dashletFullscreen'])
&& $this->_currentlyViewedContactId
) {
$this->_context = 'activity';
......
......@@ -130,7 +130,7 @@ class CRM_Activity_Form_ActivityView extends CRM_Core_Form {
'spacing' => '         ',
'isDefault' => TRUE,
],
]
]
);
}
......
......@@ -109,7 +109,8 @@ class CRM_Activity_Form_Task_FileOnCase extends CRM_Activity_Form_Task {
}
}
else {
CRM_Core_Session::setStatus(ts('Not permitted to file activity %1 %2.', [
CRM_Core_Session::setStatus(
ts('Not permitted to file activity %1 %2.', [
1 => empty($defaults['subject']) ? '' : $defaults['subject'],
2 => $defaults['activity_date_time'],
]),
......
......@@ -251,7 +251,7 @@ class CRM_Activity_Import_Form_MapField extends CRM_Import_Form_MapField {
'type' => 'cancel',
'name' => ts('Cancel'),
],
]
]
);
}
......
......@@ -240,30 +240,24 @@ abstract class CRM_Activity_Import_Parser extends CRM_Import_Parser {
}
if ($this->_invalidRowCount) {
// removed view url for invlaid contacts
$headers = array_merge([
ts('Line Number'),
ts('Reason'),
],
$headers = array_merge(
[ts('Line Number'), ts('Reason')],
$customHeaders
);
$this->_errorFileName = self::errorFileName(self::ERROR);
self::exportCSV($this->_errorFileName, $headers, $this->_errors);
}
if ($this->_conflictCount) {
$headers = array_merge([
ts('Line Number'),
ts('Reason'),
],
$headers = array_merge(
[ts('Line Number'), ts('Reason')],
$customHeaders
);
$this->_conflictFileName = self::errorFileName(self::CONFLICT);
self::exportCSV($this->_conflictFileName, $headers, $this->_conflicts);
}
if ($this->_duplicateCount) {
$headers = array_merge([
ts('Line Number'),
ts('View Activity History URL'),
],
$headers = array_merge(
[ts('Line Number'), ts('View Activity History URL')],
$customHeaders
);
......
......@@ -78,7 +78,8 @@ class CRM_Activity_Tokens extends \Civi\Token\AbstractTokenSubscriber {
// Q: Could we simplify & move the extra AND clauses into `where(...)`?
$e->query->param('casEntityJoinExpr', 'e.id = reminder.entity_id AND e.is_current_revision = 1 AND e.is_deleted = 0');
$e->query->select('e.*'); // FIXME: seems too broad.
// FIXME: seems too broad.
$e->query->select('e.*');
$e->query->select('ov.label as activity_type, e.id as activity_id');
$e->query->join("og", "!casMailingJoinType civicrm_option_group og ON og.name = 'activity_type'");
......
......@@ -128,27 +128,25 @@ class CRM_Admin_Form extends CRM_Core_Form {
public function buildQuickForm() {
if ($this->_action & CRM_Core_Action::VIEW || $this->_action & CRM_Core_Action::PREVIEW) {
$this->addButtons([
[
'type' => 'cancel',
'name' => ts('Done'),
'isDefault' => TRUE,
],
]
);
[
'type' => 'cancel',
'name' => ts('Done'),
'isDefault' => TRUE,
],
]);
}
else {
$this->addButtons([
[
'type' => 'next',
'name' => $this->_action & CRM_Core_Action::DELETE ? ts('Delete') : ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]
);
[
'type' => 'next',
'name' => $this->_action & CRM_Core_Action::DELETE ? ts('Delete') : ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
}
}
......
......@@ -42,17 +42,16 @@ class CRM_Admin_Form_CMSUser extends CRM_Core_Form {
public function buildQuickForm() {
$this->addButtons([
[
'type' => 'next',
'name' => ts('OK'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]
);
[
'type' => 'next',
'name' => ts('OK'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
}
/**
......
......@@ -137,17 +137,16 @@ class CRM_Admin_Form_Extensions extends CRM_Admin_Form {
$this->assign('title', $title);
$this->addButtons([
[
'type' => 'next',
'name' => $buttonName,
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]
);
[
'type' => 'next',
'name' => $buttonName,
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
}
/**
......
......@@ -84,17 +84,16 @@ class CRM_Admin_Form_Generic extends CRM_Core_Form {
// @todo - do we still like this redirect?
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
$this->addButtons([
[
'type' => 'next',
'name' => ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]
);
[
'type' => 'next',
'name' => ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
}
/**
......
......@@ -78,9 +78,9 @@ class CRM_Admin_Form_Job extends CRM_Admin_Form {
);
$this->addRule('name', ts('Name already exists in Database.'), 'objectExists', [
'CRM_Core_DAO_Job',
$this->_id,
]);
'CRM_Core_DAO_Job',
$this->_id,
]);
$this->add('text', 'description', ts('Description'),
$attributes['description']
......
......@@ -61,9 +61,9 @@ class CRM_Admin_Form_Mapping extends CRM_Admin_Form {
CRM_Core_DAO::getAttribute('CRM_Core_DAO_Mapping', 'name'), TRUE
);
$this->addRule('name', ts('Name already exists in Database.'), 'objectExists', [
'CRM_Core_DAO_Mapping',
$this->_id,
]);
'CRM_Core_DAO_Mapping',
$this->_id,
]);
$this->addElement('text', 'description', ts('Description'),
CRM_Core_DAO::getAttribute('CRM_Core_DAO_Mapping', 'description')
......
......@@ -95,14 +95,13 @@ class CRM_Admin_Form_MessageTemplates extends CRM_Admin_Form {
$cancelURL = CRM_Utils_System::url('civicrm/admin/messageTemplates', 'selectedChild=workflow&reset=1');
$cancelURL = str_replace('&', '&', $cancelURL);
$this->addButtons([
[
'type' => 'cancel',
'name' => ts('Done'),
'js' => ['onclick' => "location.href='{$cancelURL}'; return false;"],
'isDefault' => TRUE,
],
]
);
[
'type' => 'cancel',
'name' => ts('Done'),
'js' => ['onclick' => "location.href='{$cancelURL}'; return false;"],
'isDefault' => TRUE,
],
]);
}
else {
$this->_workflow_id = CRM_Utils_Array::value('workflow_id', $this->_values);
......
......@@ -96,9 +96,9 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
if ($isInUse) {
$scriptURL = "<a href='" . CRM_Utils_System::docURL2('Update Greetings and Address Data for Contacts', TRUE, NULL, NULL, NULL, "wiki") . "'>" . ts('Learn more about a script that can automatically update contact addressee and greeting options.') . "</a>";
CRM_Core_Session::setStatus(ts('The selected %1 option has <strong>not been deleted</strong> because it is currently in use. Please update these contacts to use a different format before deleting this option. %2', [
1 => $this->_gLabel,
2 => $scriptURL,
]), ts('Sorry'), 'error');
1 => $this->_gLabel,
2 => $scriptURL,
]), ts('Sorry'), 'error');
$redirect = CRM_Utils_System::url($url, $params);
CRM_Utils_System::redirect($redirect);
}
......@@ -193,11 +193,8 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
$this->add('color', 'color', ts('Color'));
}
if (!in_array($this->_gName, [
'email_greeting',
'postal_greeting',
'addressee',
]) && !$isReserved
if (!in_array($this->_gName, ['email_greeting', 'postal_greeting', 'addressee'])
&& !$isReserved
) {
$this->addRule('label',
ts('This Label already exists in the database for this option group. Please select a different Label.'),
......@@ -323,11 +320,8 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
}
// get contact type for which user want to create a new greeting/addressee type, CRM-4575
if (in_array($this->_gName, [
'email_greeting',
'postal_greeting',
'addressee',
]) && !$isReserved
if (in_array($this->_gName, ['email_greeting', 'postal_greeting', 'addressee'])
&& !$isReserved
) {
$values = [
1 => ts('Individual'),
......@@ -372,11 +366,8 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
$errors['grouping'] = ts('Status class is a required field');
}
if (in_array($self->_gName, [
'email_greeting',
'postal_greeting',
'addressee',
]) && empty($self->_defaultValues['is_reserved'])
if (in_array($self->_gName, ['email_greeting', 'postal_greeting', 'addressee'])
&& empty($self->_defaultValues['is_reserved'])
) {
$label = $fields['label'];
$condition = " AND v.label = '{$label}' ";
......@@ -487,9 +478,9 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
$optionValue = CRM_Core_OptionValue::addOptionValue($params, $this->_gName, $this->_action, $this->_id);
CRM_Core_Session::setStatus(ts('The %1 \'%2\' has been saved.', [
1 => $this->_gLabel,
2 => $optionValue->label,
]), ts('Saved'), 'success');
1 => $this->_gLabel,
2 => $optionValue->label,
]), ts('Saved'), 'success');
$this->ajaxResponse['optionValue'] = $optionValue->toArray();
}
......
......@@ -183,11 +183,11 @@ class CRM_Admin_Form_PaymentProcessor extends CRM_Admin_Form {
);
$this->addRule('name', ts('Name already exists in Database.'), 'objectExists', [
'CRM_Financial_DAO_PaymentProcessor',
$this->_id,
'name',
CRM_Core_Config::domainID(),
]);
'CRM_Financial_DAO_PaymentProcessor',
$this->_id,
'name',
CRM_Core_Config::domainID(),
]);
$this->add('text', 'description', ts('Description'),
$attributes['description']
......
......@@ -80,9 +80,9 @@ class CRM_Admin_Form_PdfFormats extends CRM_Admin_Form {
$this->add('number', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Core_BAO_PdfFormat', 'weight'), TRUE);
$this->addRule('name', ts('Name already exists in Database.'), 'objectExists', [
'CRM_Core_BAO_PdfFormat',
$this->_id,
]);
'CRM_Core_BAO_PdfFormat',
$this->_id,
]);
$this->addRule('margin_left', ts('Margin must be numeric'), 'numeric');
$this->addRule('margin_right', ts('Margin must be numeric'), 'numeric');
$this->addRule('margin_top', ts('Margin must be numeric'), 'numeric');
......
......@@ -73,17 +73,16 @@ class CRM_Admin_Form_Persistent extends CRM_Core_Form {
$this->add('text', 'name', ts('Name:'), NULL, TRUE);
$this->add('textarea', 'data', ts('Data:'), ['rows' => 4, 'cols' => 50], TRUE);
$this->addButtons([
[
'type' => 'submit',
'name' => ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]
);
[
'type' => 'submit',
'name' => ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
}
public function postProcess() {
......
......@@ -228,17 +228,16 @@ class CRM_Admin_Form_Preferences extends CRM_Core_Form {
}
$this->addButtons([
[
'type' => 'next',
'name' => ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]
);
[
'type' => 'next',
'name' => ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
if ($this->_action == CRM_Core_Action::VIEW) {
$this->freeze();
......
......@@ -69,11 +69,11 @@ class CRM_Admin_Form_RelationshipType extends CRM_Admin_Form {
],
'label_b_a' => [
'name' => 'label_b_a',
'description' => ts("Label for the relationship from Contact B to Contact A. EXAMPLE: Contact B is 'Child of' Contact A. You may leave this blank for relationships where the name is the same in both directions (e.g. Spouse).")
'description' => ts("Label for the relationship from Contact B to Contact A. EXAMPLE: Contact B is 'Child of' Contact A. You may leave this blank for relationships where the name is the same in both directions (e.g. Spouse)."),
],
'description' => [
'name' => 'description',
'description' => ''
'description' => '',
],
'contact_types_a' => ['name' => 'contact_types_a', 'not-auto-addable' => TRUE],
'contact_types_b' => ['name' => 'contact_types_b', 'not-auto-addable' => TRUE],
......
......@@ -74,17 +74,16 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
public function buildQuickForm() {
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
$this->addButtons([
[
'type' => 'next',
'name' => ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]
);
[
'type' => 'next',
'name' => ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]);
$this->addFieldsDefinedInSettingsMetadata();
......@@ -143,7 +142,8 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
}
CRM_Core_Config::clearDBCache();
Civi::cache('session')->clear(); // This doesn't make a lot of sense to me, but it maintains pre-existing behavior.
// This doesn't make a lot of sense to me, but it maintains pre-existing behavior.
Civi::cache('session')->clear();
CRM_Utils_System::flushCache();
CRM_Core_Resources::singleton()->resetCacheCode();
......
......@@ -85,7 +85,8 @@ class CRM_Admin_Form_Setting_UF extends CRM_Admin_Form_Setting {
if ($config->userFramework === 'Backdrop') {
$tablePrefixes = '$database_prefix = array(';
}
$tablePrefixes .= "\n 'default' => '$drupal_prefix',"; // add default prefix: the drupal database prefix
// add default prefix: the drupal database prefix
$tablePrefixes .= "\n 'default' => '$drupal_prefix',";
$prefix = "";
if ($config->dsn != $config->userFrameworkDSN) {
$prefix = "`{$dsnArray['database']}`.";
......
......@@ -139,17 +139,16 @@ class CRM_Admin_Form_WordReplacements extends CRM_Core_Form {
$this->assign('stringOverrideInstances', empty($stringOverrideInstances) ? FALSE : $stringOverrideInstances);
$this->addButtons([
[
'type' => 'next',
'name' => ts('Save'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
],
]
);
[
'type' => 'next',
'name' => ts('Save'),