Skip to content

Commit

Permalink
Fix indexes of array return values (#1481)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpalmer authored Jan 11, 2021
1 parent eec93fc commit ba81907
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
6 changes: 5 additions & 1 deletion classes/DataWarehouse/Access/BatchExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ public static function getBatchExportRealms(XDUser $user)
$config = RawStatisticsConfiguration::factory();
$allowedRealms = Realms::getRealmIdsForUser($user);

return array_filter(
$realms = array_filter(
$config->getBatchExportRealms(),
function ($realm) use ($allowedRealms) {
return in_array($realm['name'], $allowedRealms);
}
);

// Use array_values to remove gaps in keys that may have been
// introduced by the use of array_filter.
return array_values($realms);
}

/**
Expand Down
6 changes: 5 additions & 1 deletion classes/DataWarehouse/Access/RawData.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,16 @@ public static function getRawDataRealms(XDUser $user)
$config = RawStatisticsConfiguration::factory();
$allowedRealms = Realms::getRealmsForUser($user);

return array_filter(
$realms = array_filter(
$config->getRawDataRealms(),
function ($realmConfig) use ($allowedRealms) {
return in_array($realmConfig['name'], $allowedRealms);
}
);

// Use array_values to remove gaps in keys that may have been
// introduced by the use of array_filter.
return array_values($realms);
}

/**
Expand Down
12 changes: 10 additions & 2 deletions classes/DataWarehouse/Export/RealmManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ function ($realm) {
$this->config->getBatchExportRealms()
);

return array_filter(
$realms = array_filter(
Realms::getRealms(),
function ($realm) use ($exportable) {
return in_array($realm->getName(), $exportable);
}
);

// Use array_values to remove gaps in keys that may have been
// introduced by the use of array_filter.
return array_values($realms);
}

/**
Expand All @@ -57,12 +61,16 @@ function ($realm) use ($exportable) {
*/
public function getRealmsForUser(XDUser $user)
{
return array_filter(
$realms = array_filter(
$this->getRealms(),
function ($realm) use ($user) {
return BatchExport::realmExists($user, $realm->getName());
}
);

// Use array_values to remove gaps in keys that may have been
// introduced by the use of array_filter.
return array_values($realms);
}

/**
Expand Down

0 comments on commit ba81907

Please sign in to comment.