Skip to content

Commit

Permalink
reducing method complexity to pacify scrutinizer
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Jul 22, 2015
1 parent 5035aab commit 585b6b5
Showing 1 changed file with 32 additions and 23 deletions.
55 changes: 32 additions & 23 deletions classes/Member.php
Expand Up @@ -204,42 +204,51 @@ public function offices($include_only = NULL, $priority_only = FALSE) {
$office = $office['office'];

foreach ($office as $row) {
$office_title = prettify_office($row['position'], $row['dept']);

// Reset the inclusion of this position
$include_office = TRUE;

// If we should only include previous offices, and the to date is in the future, suppress this office.
if ($include_only == 'previous' AND $row['to_date'] == '9999-12-31') {
$include_office = FALSE;
if ( $officeObject = $this->getOfficeObject($include_only, $priority_only, $office_title, $row) ) {
$out[] = $officeObject;
}
}
}

// If we should only include previous offices, and the to date is in the past, suppress this office.
if ($include_only == 'current' AND $row['to_date'] != '9999-12-31') {
$include_office = FALSE;
}
return $out;

$office_title = prettify_office($row['position'], $row['dept']);
}

if (($priority_only AND in_array($office_title, $this->priority_offices))
OR !$priority_only) {
if ($include_office) {
$officeObject = new Office;
private function getOfficeObject($include_only, $priority_only, $office_title, $row) {
$officeObject = null;

$officeObject->title = $office_title;
if ( $this->includeOffice($include_only, $row['to_date']) ) {
if (($priority_only AND in_array($office_title, $this->priority_offices)) OR !$priority_only) {
$officeObject = new Office;

$officeObject->from_date = $row['from_date'];
$officeObject->to_date = $row['to_date'];
$officeObject->title = $office_title;

$officeObject->source = $row['source'];
$officeObject->from_date = $row['from_date'];
$officeObject->to_date = $row['to_date'];

$out[] = $officeObject;
}
}
$officeObject->source = $row['source'];
}
}

return $out;
return $officeObject;
}

private function includeOffice($include_only, $to_date) {
$include_office = TRUE;

// If we should only include previous offices, and the to date is in the future, suppress this office.
if ($include_only == 'previous' AND $to_date == '9999-12-31') {
$include_office = FALSE;
}

// If we should only include previous offices, and the to date is in the past, suppress this office.
if ($include_only == 'current' AND $to_date != '9999-12-31') {
$include_office = FALSE;
}

return $include_office;
}

/**
Expand Down

0 comments on commit 585b6b5

Please sign in to comment.