Have get_arg never return null

90% of places assume it will never return null, and they will break in
weird ways if it does return null
This commit is contained in:
Shish
2019-11-04 00:40:10 +00:00
parent fc7da5114f
commit d17e207984
19 changed files with 141 additions and 137 deletions

View File

@ -106,13 +106,28 @@ class PageRequestEvent extends Event
/**
* Get the n th argument of the page request (if it exists.)
*/
public function get_arg(int $n): ?string
public function get_arg(int $n): string
{
$offset = $this->part_count + $n;
if ($offset >= 0 && $offset < $this->arg_count) {
return $this->args[$offset];
} else {
return null;
throw new SCoreException("Requested an invalid argument #$n");
}
}
public function try_page_num(int $n): int {
if($this->count_args() > $n) {
$i = $this->get_arg($n);
if (!is_numeric($i) || $i <= 0) {
return int_escape($i);
}
else {
return 1;
}
}
else {
return 1;
}
}