fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -11,17 +11,28 @@ class OpportunityInitiativeApplicability
|
||||
'unit_investment' => ['total_investment', 'currency', 'investment_breakdown', 'secured_financing', 'funding_sought', 'financial_indicators'],
|
||||
];
|
||||
|
||||
/**
|
||||
* @param array<array-key, mixed> $p
|
||||
*/
|
||||
public function enabled(array $p): bool
|
||||
{
|
||||
return ($p['opportunity_category'] ?? null) === 'investment_project'
|
||||
&& in_array($p['initiative']['kind'] ?? null, ['program', 'portfolio'], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array-key, mixed> $p
|
||||
*/
|
||||
public function applicable(array $p, string $group): bool
|
||||
{
|
||||
return ! $this->enabled($p) || ($p['initiative']['applicability'][$group] ?? 'missing') !== 'not_applicable';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array-key, mixed> $payload
|
||||
* @param array<array-key, mixed> $schema
|
||||
* @return array<array-key, mixed>
|
||||
*/
|
||||
public function schema(array $schema, array $payload): array
|
||||
{
|
||||
$base = &$schema['$defs']['opportunityCreate'];
|
||||
@@ -42,6 +53,7 @@ class OpportunityInitiativeApplicability
|
||||
if (isset($payload['initiative'])) {
|
||||
$base['allOf'][] = ['properties' => ['opportunity_category' => ['const' => 'investment_project']]];
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
$ignored = [];
|
||||
@@ -73,9 +85,14 @@ class OpportunityInitiativeApplicability
|
||||
if (! $this->applicable($payload, 'physical_site')) {
|
||||
unset($base['properties']['locations']['minItems']);
|
||||
}
|
||||
|
||||
return $schema;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array-key, mixed> $errors
|
||||
* @param array<array-key, mixed> $p
|
||||
*/
|
||||
public function validate(array $p, array &$errors): void
|
||||
{
|
||||
if (! $this->enabled($p)) {
|
||||
@@ -91,4 +108,3 @@ class OpportunityInitiativeApplicability
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user