86 lines
3.1 KiB
PHP
86 lines
3.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Support\ReviewPublicationResolution;
|
|
|
|
use App\Models\EnvironmentReview;
|
|
use App\Models\EvidenceSnapshot;
|
|
use App\Models\ReviewPack;
|
|
use App\Support\Evidence\EvidenceSnapshotStatus;
|
|
use App\Support\ReviewPackStatus;
|
|
|
|
final class ReviewPublicationProofResolver
|
|
{
|
|
/**
|
|
* @return array{
|
|
* proof_type:?string,
|
|
* proof_id:?int,
|
|
* proof_status:?string,
|
|
* operation_run_id:?int
|
|
* }
|
|
*/
|
|
public function proofFor(ReviewPublicationResolutionStepKey $stepKey, EnvironmentReview $review): array
|
|
{
|
|
$review->loadMissing(['evidenceSnapshot', 'currentExportReviewPack', 'operationRun']);
|
|
|
|
return match ($stepKey) {
|
|
ReviewPublicationResolutionStepKey::ValidateReviewReadiness,
|
|
ReviewPublicationResolutionStepKey::RefreshReviewComposition,
|
|
ReviewPublicationResolutionStepKey::ReturnToPublication => [
|
|
'proof_type' => 'environment_review',
|
|
'proof_id' => (int) $review->getKey(),
|
|
'proof_status' => (string) $review->status,
|
|
'operation_run_id' => is_numeric($review->operation_run_id) ? (int) $review->operation_run_id : null,
|
|
],
|
|
ReviewPublicationResolutionStepKey::CompleteRequiredReports,
|
|
ReviewPublicationResolutionStepKey::CollectEvidenceSnapshot => $this->evidenceProof($review->evidenceSnapshot),
|
|
ReviewPublicationResolutionStepKey::GenerateReviewPack => $this->reviewPackProof($review->currentExportReviewPack),
|
|
};
|
|
}
|
|
|
|
/**
|
|
* @return array{proof_type:?string, proof_id:?int, proof_status:?string, operation_run_id:?int}
|
|
*/
|
|
public function evidenceProof(?EvidenceSnapshot $snapshot): array
|
|
{
|
|
if (! $snapshot instanceof EvidenceSnapshot) {
|
|
return [
|
|
'proof_type' => null,
|
|
'proof_id' => null,
|
|
'proof_status' => EvidenceSnapshotStatus::Failed->value,
|
|
'operation_run_id' => null,
|
|
];
|
|
}
|
|
|
|
return [
|
|
'proof_type' => 'evidence_snapshot',
|
|
'proof_id' => (int) $snapshot->getKey(),
|
|
'proof_status' => (string) $snapshot->status,
|
|
'operation_run_id' => is_numeric($snapshot->operation_run_id) ? (int) $snapshot->operation_run_id : null,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array{proof_type:?string, proof_id:?int, proof_status:?string, operation_run_id:?int}
|
|
*/
|
|
public function reviewPackProof(?ReviewPack $reviewPack): array
|
|
{
|
|
if (! $reviewPack instanceof ReviewPack) {
|
|
return [
|
|
'proof_type' => null,
|
|
'proof_id' => null,
|
|
'proof_status' => ReviewPackStatus::Failed->value,
|
|
'operation_run_id' => null,
|
|
];
|
|
}
|
|
|
|
return [
|
|
'proof_type' => 'review_pack',
|
|
'proof_id' => (int) $reviewPack->getKey(),
|
|
'proof_status' => (string) $reviewPack->status,
|
|
'operation_run_id' => is_numeric($reviewPack->operation_run_id) ? (int) $reviewPack->operation_run_id : null,
|
|
];
|
|
}
|
|
}
|