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

[NFC] throw exceptions, single quotes, declare exceptions, remove unused param #16415

Merged
merged 1 commit into from
Jan 29, 2020
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
27 changes: 17 additions & 10 deletions CRM/Admin/Form/SettingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ protected function getSettingsOrderedByWeight() {

/**
* Add fields in the metadata to the template.
*
* @throws \CRM_Core_Exception
*/
protected function addFieldsDefinedInSettingsMetadata() {
$settingMetaData = $this->getSettingsMetaData();
Expand Down Expand Up @@ -178,7 +180,7 @@ protected function addFieldsDefinedInSettingsMetadata() {
}

$add = 'add' . $quickFormType;
if ($add == 'addElement') {
if ($add === 'addElement') {
$this->$add(
$props['html_type'],
$setting,
Expand All @@ -187,13 +189,13 @@ protected function addFieldsDefinedInSettingsMetadata() {
($options !== NULL) ? CRM_Utils_Array::value('html_attributes', $props, []) : NULL
);
}
elseif ($add == 'addSelect') {
elseif ($add === 'addSelect') {
$this->addElement('select', $setting, $props['title'], $options, CRM_Utils_Array::value('html_attributes', $props));
}
elseif ($add == 'addCheckBox') {
elseif ($add === 'addCheckBox') {
$this->addCheckBox($setting, '', $options, NULL, CRM_Utils_Array::value('html_attributes', $props), NULL, NULL, ['  ']);
}
elseif ($add == 'addCheckBoxes') {
elseif ($add === 'addCheckBoxes') {
$newOptions = array_flip($options);
$classes = 'crm-checkbox-list';
if (!empty($props['sortable'])) {
Expand All @@ -208,12 +210,12 @@ protected function addFieldsDefinedInSettingsMetadata() {
'</li><li>'
);
}
elseif ($add == 'addChainSelect') {
elseif ($add === 'addChainSelect') {
$this->addChainSelect($setting, [
'label' => $props['title'],
]);
}
elseif ($add == 'addMonthDay') {
elseif ($add === 'addMonthDay') {
$this->add('date', $setting, $props['title'], CRM_Core_SelectValues::date(NULL, 'M d'));
}
elseif ($add === 'addEntityRef') {
Expand All @@ -232,15 +234,15 @@ protected function addFieldsDefinedInSettingsMetadata() {
$description = CRM_Utils_Array::value('description', $props);
$descriptions[$setting] = $description;
$this->assign("{$setting}_description", $description);
if ($setting == 'max_attachments') {
if ($setting === 'max_attachments') {
//temp hack @todo fix to get from metadata
$this->addRule('max_attachments', ts('Value should be a positive number'), 'positiveInteger');
}
if ($setting == 'max_attachments_backend') {
if ($setting === 'max_attachments_backend') {
//temp hack @todo fix to get from metadata
$this->addRule('max_attachments_backend', ts('Value should be a positive number'), 'positiveInteger');
}
if ($setting == 'maxFileSize') {
if ($setting === 'maxFileSize') {
//temp hack
$this->addRule('maxFileSize', ts('Value should be a positive number'), 'positiveInteger');
}
Expand Down Expand Up @@ -293,12 +295,15 @@ protected function getQuickFormType($spec) {
* Get the defaults for all fields defined in the metadata.
*
* All others are pending conversion.
*
* @throws \CiviCRM_API3_Exception
* @throws \CRM_Core_Exception
*/
protected function setDefaultsForMetadataDefinedFields() {
CRM_Core_BAO_ConfigSetting::retrieve($this->_defaults);
foreach (array_keys($this->_settings) as $setting) {
$this->_defaults[$setting] = civicrm_api3('setting', 'getvalue', ['name' => $setting]);
$spec = $this->getSettingsMetadata()[$setting];
$spec = $this->getSettingsMetaData()[$setting];
if (!empty($spec['serialize'])) {
$this->_defaults[$setting] = CRM_Core_DAO::unSerializeField($this->_defaults[$setting], $spec['serialize']);
}
Expand Down Expand Up @@ -355,6 +360,8 @@ public static function reorderSortableOptions($setting, $options) {
* @param array $settingValue
*
* @return array
*
* @throws \CRM_Core_Exception
*/
private function getReorderedSettingData($setting, $settingValue) {
// Get order from $_POST as $_POST maintains the order the sorted setting
Expand Down
19 changes: 10 additions & 9 deletions CRM/Core/SelectValues.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function unitList($unitType = NULL) {
'month' => ts('month'),
'year' => ts('year'),
];
if ($unitType == 'duration') {
if ($unitType === 'duration') {
$unitList['lifetime'] = ts('lifetime');
}
return $unitList;
Expand Down Expand Up @@ -121,10 +121,10 @@ public static function periodType() {
*/
public static function emailSelectMethods() {
return [
'automatic' => ts("Automatic"),
'location-only' => ts("Only send to email addresses assigned to the specified location"),
'location-prefer' => ts("Prefer email addresses assigned to the specified location"),
'location-exclude' => ts("Exclude email addresses assigned to the specified location"),
'automatic' => ts('Automatic'),
'location-only' => ts('Only send to email addresses assigned to the specified location'),
'location-prefer' => ts('Prefer email addresses assigned to the specified location'),
'location-exclude' => ts('Exclude email addresses assigned to the specified location'),
];
}

Expand Down Expand Up @@ -294,7 +294,7 @@ public static function groupType() {
*
* @return array
* the date array
* @throws \Exception
* @throws CRM_Core_Exception
*/
public static function date($type = NULL, $format = NULL, $minOffset = NULL, $maxOffset = NULL, $context = 'display') {
// These options are deprecated. Definitely not used in datepicker. Possibly not even in jcalendar+addDateTime.
Expand All @@ -312,7 +312,7 @@ public static function date($type = NULL, $format = NULL, $minOffset = NULL, $ma
$dao = new CRM_Core_DAO_PreferencesDate();
$dao->name = $type;
if (!$dao->find(TRUE)) {
CRM_Core_Error::fatal();
throw new CRM_Core_Exception('Date preferences not configured.');
}
if (!$maxOffset) {
$maxOffset = $dao->end;
Expand All @@ -326,7 +326,7 @@ public static function date($type = NULL, $format = NULL, $minOffset = NULL, $ma
}

if (empty($date['format'])) {
if ($context == 'Input') {
if ($context === 'Input') {
$date['format'] = Civi::settings()->get('dateInputFormat');
}
else {
Expand Down Expand Up @@ -866,7 +866,7 @@ public static function getJobFrequency() {
*
* @return array
*/
public static function getSearchBuilderOperators($fieldType = NULL) {
public static function getSearchBuilderOperators() {
return [
'=' => '=',
'!=' => '≠',
Expand Down Expand Up @@ -1099,6 +1099,7 @@ public static function getDashboardEntriesCount() {
* Dropdown options for quicksearch in the menu
*
* @return array
* @throws \CiviCRM_API3_Exception
*/
public static function quicksearchOptions() {
$includeEmail = civicrm_api3('setting', 'getvalue', ['name' => 'includeEmailInName', 'group' => 'Search Preferences']);
Expand Down
3 changes: 3 additions & 0 deletions CRM/Report/Form/Contribute/History.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class CRM_Report_Form_Contribute_History extends CRM_Report_Form {
protected $_yearStatisticsTo = '';

/**
* Class constructor.
*
* @throws \CRM_Core_Exception
*/
public function __construct() {
$this->_autoIncludeIndexedFieldsAsOrderBys = 1;
Expand Down