To get a positiv result
function modulo(int $a, int $b):?int {
if ($b == 0) {
throw new Exception('modulo : second operand must not be zero');
}
$b = abs($b);
// test $b == 1 for performance when $a < 0
return ($b == 1) ? 0 : (($a < 0) ? modulo($a + $b, $b) : $a % $b);
}