Skip to content

Commit

Permalink
Big code cleanup - return types, visibility, type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Aug 9, 2022
1 parent 994bf79 commit 7400070
Show file tree
Hide file tree
Showing 44 changed files with 232 additions and 301 deletions.
6 changes: 4 additions & 2 deletions CRM/Extendedreport/Form/Report/ActivityEditable.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ public function __construct() {
}

/**
* Generate From clause.
* Generate from clause.
*
* @return array
*/
public function fromClauses() {
public function fromClauses(): array {
return [
'activity_target_from_activity',
'activity_assignee_from_activity',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Extendedreport/Form/Report/ActivityPivot.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function __construct() {
*
* @return array
*/
public function fromClauses() {
public function fromClauses(): array {
return [];
}
}
35 changes: 15 additions & 20 deletions CRM/Extendedreport/Form/Report/Campaign/CampaignProgressReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ public function __construct() {

/**
* Add from clause
*
* @throws \CRM_Core_Exception
*/
public function from() {
public function from(): void {
$this->_from = "
FROM civicrm_campaign {$this->_aliases['civicrm_campaign']}";

Expand All @@ -134,7 +136,7 @@ public function from() {
$this->_from .= "
LEFT JOIN civicrm_contact {$this->_aliases['civicrm_contact']}
ON ({$this->_aliases['civicrm_contact']}.id = progress.contact_id )
{$this->_aclFrom}
$this->_aclFrom
";
}

Expand All @@ -143,7 +145,7 @@ public function from() {
*
* @throws \CRM_Core_Exception
*/
protected function joinProgressTable() {
protected function joinProgressTable(): void {
$until = CRM_Utils_Array::value('effective_date_value', $this->_params);
$untilClause = '';
if ($until) {
Expand Down Expand Up @@ -205,9 +207,9 @@ protected function joinProgressTable() {
*
* @return string
*/
function selectClause(&$tableName, $tableKey, &$fieldName, &$field) {
public function selectClause(&$tableName, $tableKey, &$fieldName, &$field): string {
if ($fieldName === 'progress_still_to_raise') {
$alias = "{$tableName}_{$fieldName}";
$alias = "{$tableName}_$fieldName";
$this->_columnHeaders[$alias]['title'] = CRM_Utils_Array::value('title', $field);
$this->_columnHeaders[$alias]['type'] = CRM_Utils_Array::value('type', $field);
$this->_columnHeaders[$alias]['dbAlias'] = CRM_Utils_Array::value('dbAlias', $field);
Expand All @@ -220,7 +222,7 @@ function selectClause(&$tableName, $tableKey, &$fieldName, &$field) {
/**
* Block parent re-ordering of headers.
*/
public function reOrderColumnHeaders() {
public function reOrderColumnHeaders(): void {

}

Expand All @@ -231,16 +233,14 @@ public function reOrderColumnHeaders() {
*
* @return string
*/
public function alterIsPledge($value) {
public function alterIsPledge(bool $value): string {
return str_replace([0, 1], [ts('Payment without pledge'), ts('Pledge')], $value);
}

/**
* @param array $rows
*
* @throws \CRM_Core_Exception
*/
public function alterDisplay(&$rows) {
public function alterDisplay(&$rows): void {
parent::alterDisplay($rows);
$this->unsetUnreliableColumnsIfNotCampaignGrouped();
if (isset($this->_columnHeaders['progress_progress_still_to_raise'])) {
Expand Down Expand Up @@ -289,13 +289,8 @@ public function alterDisplay(&$rows) {
/**
* Do we have a group by array that does not include campaign/
*/
protected function groupByCampaignTypeNotCampaign() {
if (!empty($this->_groupByArray)) {
if (!in_array('campaign.id', $this->_groupByArray, TRUE)) {
return TRUE;
}
}
return FALSE;
protected function groupByCampaignTypeNotCampaign(): bool {
return !empty($this->_groupByArray) && !in_array('campaign.id', $this->_groupByArray, TRUE);
}

/**
Expand All @@ -307,16 +302,16 @@ protected function groupByCampaignTypeNotCampaign() {
*
* @return array
*/
function getOperationPair($type = "string", $fieldName = NULL) {
if ($type == self::OP_SINGLEDATE) {
public function getOperationPair($type = "string", $fieldName = NULL): array {
if ($type === (string) self::OP_SINGLEDATE) {
return [
'to' => ts('Until Date'),
];
}
return parent::getOperationPair($type, $fieldName);
}

protected function unsetUnreliableColumnsIfNotCampaignGrouped() {
protected function unsetUnreliableColumnsIfNotCampaignGrouped(): void {
if ($this->groupByCampaignTypeNotCampaign()) {
if (isset($this->_columnHeaders['progress_still_to_raise'])) {
unset($this->_columnHeaders['progress_still_to_raise']);
Expand Down
10 changes: 3 additions & 7 deletions CRM/Extendedreport/Form/Report/Case/ActivityPivot.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ class CRM_Extendedreport_Form_Report_Case_ActivityPivot extends CRM_Extendedrepo

protected $_customGroupAggregates = TRUE;

protected $_aggregatesIncludeNULL = TRUE;

protected $_aggregatesAddTotal = TRUE;

protected $_rollup = 'WITH ROLLUP';

protected $_aggregatesAddPercentage = TRUE;

public $_drilldownReport = [];

protected $_potentialCriteria = [];

protected $isPivot = TRUE;
Expand All @@ -29,6 +23,8 @@ class CRM_Extendedreport_Form_Report_Case_ActivityPivot extends CRM_Extendedrepo

/**
* Class constructor.
*
* @throws \CiviCRM_API3_Exception
*/
public function __construct() {
$this->_customGroupExtended['civicrm_case'] = [
Expand Down Expand Up @@ -63,7 +59,7 @@ public function __construct() {
/**
* @return array
*/
function fromClauses() {
public function fromClauses(): array {
return [
'case_from_activity',
'contact_from_case',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Extendedreport/Form/Report/Case/CasePivot.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function __construct() {
*
* @return array
*/
public function fromClauses() {
public function fromClauses(): array {
return [
'contact_from_case',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function generateTempTable() {
/**
* @return array
*/
function fromClauses() {
function fromClauses(): array {
return [
'contact_from_case',
'activity_from_case',
Expand Down
8 changes: 4 additions & 4 deletions CRM/Extendedreport/Form/Report/ColumnDefinitionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function getActivityColumns(array $options = []): array {
/**
* Get columns for Case.
*
* @param $options
* @param array $options
*
* @return array
*
Expand Down Expand Up @@ -569,7 +569,7 @@ protected function getContactColumns($options = []) {
*
* @return array
*/
function getLatestActivityColumns($options) {
function getLatestActivityColumns(array $options) {
$defaultOptions = [
'prefix' => '',
'prefix_label' => '',
Expand Down Expand Up @@ -604,7 +604,7 @@ function getLatestActivityColumns($options) {
*
* @return array
*/
protected function getContributionRecurColumns($options = []): array {
protected function getContributionRecurColumns(array $options = []): array {
$spec = [
'id' => [
'is_fields' => TRUE,
Expand Down Expand Up @@ -764,7 +764,7 @@ protected function getContributionRecurColumns($options = []): array {
*
* @return array
*/
protected function getContributionSoftColumns($options = []): array {
protected function getContributionSoftColumns(array $options = []): array {
$spec = [
'id' => [
'is_fields' => FALSE,
Expand Down
4 changes: 2 additions & 2 deletions CRM/Extendedreport/Form/Report/Contact/AddressHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function orderBy() {
*
* @return null|string
*/
public function whereClause(&$field, $op, $value, $min, $max) {
public function whereClause(&$field, $op, $value, $min, $max): ?string {
if ($field['name'] === 'contact_id' && $value) {
$this->contactID = (int) $value;
$mergedContactIDs = $this->getContactsMergedIntoThisOne($this->contactID);
Expand All @@ -137,7 +137,7 @@ public function whereClause(&$field, $op, $value, $min, $max) {
*
* @return array
*/
protected function getContactsMergedIntoThisOne($contactID) {
protected function getContactsMergedIntoThisOne(int $contactID): array {
// @todo get api joins working properly.
$result = civicrm_api3('Activity', 'get', [
'assignee_contact_id' => $contactID,
Expand Down
6 changes: 2 additions & 4 deletions CRM/Extendedreport/Form/Report/Contact/Basiccontact.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
*/
class CRM_Extendedreport_Form_Report_Contact_Basiccontact extends CRM_Extendedreport_Form_Report_ExtendedReport {

protected $_baseTable = 'civicrm_contact';

protected $skipACL = FALSE;

protected $_joinFilters = ['address_from_contact' => ['civicrm_address' => 'is_primary = 1 ']];
Expand Down Expand Up @@ -53,7 +51,7 @@ public function __construct() {
/**
* @return array
*/
function fromClauses() {
public function fromClauses(): array {
return [
'address_from_contact',
'email_from_contact',
Expand All @@ -63,7 +61,7 @@ function fromClauses() {
];
}

function groupBy() {
public function groupBy(): void {
$this->_groupBy = "GROUP BY {$this->_aliases['civicrm_contact']}.id";
}
}
Loading

0 comments on commit 7400070

Please sign in to comment.