Files
Investidor-V2/app/Services/EducationGapCalculator.php
T
nala 250ac35fd1
tests / ci (push) Canceled after 0s
first commit
2026-09-28 10:01:09 +02:00

28 lines
883 B
PHP

<?php
namespace App\Services;
use InvalidArgumentException;
final class EducationGapCalculator
{
/** @return array{state:string, people:?int} */
public function observed(?int $demand, ?int $available, bool $comparable, bool $current): array
{
if (($demand !== null && $demand < 0) || ($available !== null && $available < 0)) {
throw new InvalidArgumentException('Quantities cannot be negative.');
}
if (! $current) {
return ['state' => 'expired', 'people' => null];
}
if (! $comparable) {
return ['state' => 'incomparable', 'people' => null];
}
if ($demand === null || $available === null) {
return ['state' => 'insufficient_data', 'people' => null];
}
return ['state' => 'observed_unvalidated', 'people' => max(0, $demand - $available)];
}
}