Commit b34fa9cd authored by Oana-Eliza Alexa's avatar Oana-Eliza Alexa
Browse files

change to audit

1 merge request!74Draft: Resolve "Redesign audit class"
Pipeline #32373 failed with stages
in 17 seconds
This commit is part of merge request !74. Comments created here will be created in the context of that merge request.
Showing with 27 additions and 3 deletions
+27 -3
......@@ -4,11 +4,12 @@ class Audit implements EndpointInterface
{
private TaskGateway $gateway;
private string $errorMessage = 'No audit requiring removal';
private string $errorMessage;
public function __construct (TaskGateway $gateway)
{
$this->gateway = $gateway;
$this->errorMessage = 'No audit requiring removal';
}
/**
......@@ -48,7 +49,7 @@ class Audit implements EndpointInterface
$result = $this->processAuditDeletion($this->gateway->getObjectTypeTask('Audit'));
// Recursive function to filter out empty arrays at any depth
$filteredResults = Utils::recursiveArrayFilter($result);
$filteredResults = $this->recursiveArrayFilter($result);
if (empty($filteredResults)) {
return [$this->errorMessage];
......@@ -80,7 +81,7 @@ class Audit implements EndpointInterface
* @return array
* @throws Exception
*/
private function processScheduledTask (array $task): array
private function processScheduledTask(array $task): array
{
// Retrieve data from the main task.
$auditMainTask = $this->getAuditMainTask($task['fdtasksgranularmaster'][0]);
......@@ -126,4 +127,27 @@ class Audit implements EndpointInterface
return $audit;
}
/**
* @param array $array
* @return array
* Note : Recursively filters out empty values and arrays at any depth.
*/
private function recursiveArrayFilter (array $array): array
{
// First filter the array for non-empty elements
$filtered = array_filter($array, function ($item) {
if (is_array($item)) {
// Recursively filter the sub-array
$item = $this->recursiveArrayFilter($item);
// Only retain non-empty arrays
return !empty($item);
} else {
// Retain non-empty scalar values
return !empty($item);
}
});
return $filtered;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment