Automated PR provided by Codex via Gitea API. Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #482
79 lines
2.3 KiB
PHP
79 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Services\TenantConfiguration;
|
|
|
|
use App\Support\OperationRunOutcome;
|
|
use App\Support\TenantConfiguration\CaptureOutcome;
|
|
|
|
final class CoverageCaptureOutcomeSummarizer
|
|
{
|
|
/**
|
|
* @param list<array{canonical_type: string, outcome: string, item_count?: int, reason_code?: string|null}> $outcomes
|
|
* @return array{summary_counts: array<string, int>, run_outcome: string, failures: list<array{code: string, message: string, resource_type?: string}>}
|
|
*/
|
|
public function summarize(array $outcomes): array
|
|
{
|
|
$summary = [
|
|
'total' => count($outcomes),
|
|
'processed' => count($outcomes),
|
|
'succeeded' => 0,
|
|
'skipped' => 0,
|
|
'failed' => 0,
|
|
'errors_recorded' => 0,
|
|
];
|
|
$failures = [];
|
|
|
|
foreach ($outcomes as $outcomeRow) {
|
|
$outcome = CaptureOutcome::tryFrom((string) $outcomeRow['outcome']);
|
|
|
|
if ($outcome === CaptureOutcome::Captured) {
|
|
$summary['succeeded']++;
|
|
|
|
continue;
|
|
}
|
|
|
|
if ($outcome?->isFailure()) {
|
|
$summary['failed']++;
|
|
$summary['errors_recorded']++;
|
|
$failures[] = [
|
|
'code' => (string) ($outcomeRow['reason_code'] ?? CaptureOutcome::Failed->value),
|
|
'message' => sprintf('Capture failed for %s.', (string) $outcomeRow['canonical_type']),
|
|
'resource_type' => (string) $outcomeRow['canonical_type'],
|
|
];
|
|
|
|
continue;
|
|
}
|
|
|
|
$summary['skipped']++;
|
|
}
|
|
|
|
return [
|
|
'summary_counts' => $summary,
|
|
'run_outcome' => $this->runOutcome($summary),
|
|
'failures' => $failures,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param array<string, int> $summary
|
|
*/
|
|
private function runOutcome(array $summary): string
|
|
{
|
|
if (($summary['failed'] ?? 0) > 0 && ($summary['succeeded'] ?? 0) > 0) {
|
|
return OperationRunOutcome::PartiallySucceeded->value;
|
|
}
|
|
|
|
if (($summary['failed'] ?? 0) > 0) {
|
|
return OperationRunOutcome::Failed->value;
|
|
}
|
|
|
|
if (($summary['succeeded'] ?? 0) > 0) {
|
|
return OperationRunOutcome::Succeeded->value;
|
|
}
|
|
|
|
return OperationRunOutcome::Blocked->value;
|
|
}
|
|
}
|