Skip to content

Commit

Permalink
satisfy sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewPoppe committed Apr 17, 2022
1 parent cc08fd4 commit 894b60a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 42 deletions.
2 changes: 1 addition & 1 deletion Renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ private function parseDataEntryString(?string $string): array
],
"by_instrument" => []
];
foreach ($forms as $index => $form) {
foreach ($forms as $form) {
$split = explode(",", $form);
$result["by_permission"][strval($split[1])][] = $split[0];
$result["by_instrument"][$split[0]] = $split[1];
Expand Down
61 changes: 20 additions & 41 deletions UserRightsHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ function getCurrentRoles($localProjectId)
while ($role = $result->fetch_assoc()) {
$roles[$role["role_id"]] = $role;
}
$roles_to_return = count($roles) > 0 ? base64_encode(gzdeflate(json_encode($roles), 9)) : null;
return $roles_to_return;
return !empty($roles) ? base64_encode(gzdeflate(json_encode($roles), 9)) : null;
} catch (\Exception $e) {
$this->log("Error updating roles", [
"project_id" => $localProjectId,
Expand All @@ -166,8 +165,7 @@ function getLastRoles($localProjectId)
{
$sql = "select roles where message = 'roles' and project_id = ? order by timestamp desc limit 1";
$result = $this->queryLogs($sql, [$localProjectId]);
$roles_gzip = $result->fetch_assoc()["roles"];
return $roles_gzip;
return $result->fetch_assoc()["roles"];
}

function rolesChanged($lastRolesGzip, $currentRolesGzip)
Expand Down Expand Up @@ -350,8 +348,7 @@ function getCurrentDAGs($localProjectId)
while ($dag = $result->fetch_assoc()) {
$dags[$dag["group_id"]] = $dag;
}
$dags_to_return = count($dags) > 0 ? base64_encode(gzdeflate(json_encode($dags), 9)) : null;
return $dags_to_return;
return !empty($dags) ? base64_encode(gzdeflate(json_encode($dags), 9)) : null;
} catch (\Exception $e) {
$this->log("Error updating dags", [
"project_id" => $localProjectId,
Expand All @@ -363,9 +360,7 @@ function getCurrentDAGs($localProjectId)
function getLastDAGs($localProjectId)
{
$sql = "select dags where message = 'dags' and project_id = ? order by timestamp desc limit 1";
$result = $this->queryLogs($sql, [$localProjectId]);
$dags_gzip = $result->fetch_assoc()["dags"];
return $dags_gzip;
return $this->queryLogs($sql, [$localProjectId]);
}

function dagsChanged($lastDAGsGzip, $currentDAGsGzip)
Expand Down Expand Up @@ -418,8 +413,7 @@ function getLastSystem()
{
$sql = "select info where message = 'system' order by timestamp desc limit 1";
$result = $this->queryLogs($sql, []);
$system_gzip = $result->fetch_assoc()["info"];
return $system_gzip;
return $result->fetch_assoc()["info"];
}

function systemChanged($lastSystemGzip, $currentSystemGzip)
Expand Down Expand Up @@ -515,54 +509,40 @@ function getUsersByTimestamp($timestamp_clean)
return json_decode($users_json, true);
}

function getProjectStatusByTimestamp($timestamp_clean)
private function getValueByTimestamp($timestamp_clean, $message, $column, $system = false)
{
$sql = "select info where message = 'project_info'";
$sql = "select $column where message = ?";
$sql .= $system ? " and project_id is null" : "";
$sql .= $timestamp_clean === 0 ? "" : " and timestamp <= from_unixtime(?)";
$sql .= " order by timestamp desc limit 1";
$result = $this->queryLogs($sql, [$timestamp_clean]);
$info_gzip = $result->fetch_assoc()["info"];
return json_decode(gzinflate(base64_decode($info_gzip)), true);
$result = $this->queryLogs($sql, [$message, $timestamp_clean]);
$gzip = $result->fetch_assoc()[$column];
return json_decode(gzinflate(base64_decode($gzip)), true);
}

function getProjectStatusByTimestamp($timestamp_clean)
{
return $this->getValueByTimestamp($timestamp_clean, 'project_info', 'info');
}

function getAllRolesByTimestamp($timestamp_clean)
{
$sql = "select roles where message = 'roles'";
$sql .= $timestamp_clean === 0 ? "" : " and timestamp <= from_unixtime(?)";
$sql .= " order by timestamp desc limit 1";
$result = $this->queryLogs($sql, [$timestamp_clean]);
$roles_gzip = $result->fetch_assoc()["roles"];
return json_decode(gzinflate(base64_decode($roles_gzip)), true);
return $this->getValueByTimestamp($timestamp_clean, 'roles', 'roles');
}

function getAllDAGsByTimestamp($timestamp_clean)
{
$sql = "select dags where message = 'dags'";
$sql .= $timestamp_clean === 0 ? "" : " and timestamp <= from_unixtime(?)";
$sql .= " order by timestamp desc limit 1";
$result = $this->queryLogs($sql, [$timestamp_clean]);
$dags_gzip = $result->fetch_assoc()["dags"];
return json_decode(gzinflate(base64_decode($dags_gzip)), true);
return $this->getValueByTimestamp($timestamp_clean, 'dags', 'dags');
}

function getAllSystemByTimestamp($timestamp_clean)
{
$sql = "select info where message = 'system' and project_id is null";
$sql .= $timestamp_clean === 0 ? "" : " and timestamp <= from_unixtime(?)";
$sql .= " order by timestamp desc limit 1";
$result = $this->queryLogs($sql, [$timestamp_clean]);
$system_gzip = $result->fetch_assoc()["info"];
return json_decode(gzinflate(base64_decode($system_gzip)), true);
return $this->getValueByTimestamp($timestamp_clean, 'system', 'info', true);
}

function getAllInstrumentsByTimestamp($timestamp_clean)
{
$sql = "select instruments where message = 'instruments'";
$sql .= $timestamp_clean === 0 ? "" : " and timestamp <= from_unixtime(?)";
$sql .= " order by timestamp desc limit 1";
$result = $this->queryLogs($sql, [$timestamp_clean]);
$instruments_gzip = $result->fetch_assoc()["instruments"];
return json_decode(gzinflate(base64_decode($instruments_gzip)), true);
return $this->getValueByTimestamp($timestamp_clean, 'instruments', 'instruments');
}

function getAllInfoByTimestamp($timestamp = null)
Expand Down Expand Up @@ -603,7 +583,6 @@ function renderTable(array $permissions)
{
$Renderer = new Renderer($permissions);
try {
//$Renderer->print();
$Renderer->renderTable();
} catch (\Exception $e) {
var_dump($e);
Expand Down

0 comments on commit 894b60a

Please sign in to comment.