diff options
author | emkael <emkael@tlen.pl> | 2019-01-18 21:30:04 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-01-18 21:30:04 +0100 |
commit | 12a77a8e9897ab0956cf9020a00470bd310bb2a0 (patch) | |
tree | 8d86b468d422587690f307b4d454371bb6ecacf7 | |
parent | 3c13b8b8bb06587f3e3607dcf365a1d278e60447 (diff) |
Parameter sanitation for manual cutoff
-rw-r--r-- | api.php | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -127,6 +127,25 @@ function parse_parameters($parameters) { if ($return['points_cutoffs'][count($return['points_cutoffs'])-1][1] != 0.0) { array_push($return['points_cutoffs'], array(1.0, 0.0)); } + foreach ($return['points_cutoffs'] as $cutoff) { + if (($cutoff[0] < 0.0) || ($cutoff[0] > 1.0)) { + throw new ParametersException('Cutoff points need to be between 0.0 and 1.0: ' . $cutoff[0]); + } + if (($cutoff[1] < 0.0) || ($cutoff[1] > 1.0)) { + throw new ParametersException('Cutoff values need to be between 1.0 and 0.0: ' . $cutoff[1]); + } + } + for ($prev = 0; $prev < count($return['points_cutoffs']) - 1; $prev++) { + $next = $prev + 1; + if ($return['points_cutoffs'][$prev][0] >= $return['points_cutoffs'][$next][0]) { + throw new ParametersException( + 'Cutoff points need to be ascending: ' . $return['points_cutoffs'][$prev][0] . ', ' . $return['points_cutoffs'][$next][0]); + } + if ($return['points_cutoffs'][$prev][1] < $return['points_cutoffs'][$next][1]) { + throw new ParametersException( + 'Cutoff values need to be non-ascending: ' . $return['points_cutoffs'][$prev][1] . ', ' . $return['points_cutoffs'][$next][1]); + } + } return $return; } |