28 lines
883 B
PHP
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)];
|
|
}
|
|
}
|