Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions pinc/misc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,22 @@ function validate_csrf_token(): void
}


/**
* When calling `array_search` with a list, the key for a matching value is
* always an integer -- it's the index of the value.
* PHPStan dosen't know this because of `array_search`'s type signature, so
* this wrapper function lets us tell PHPStan that list keys are integers
* by squashing the impossible non-integral `$key` result to `false`.
* @template T
* @param T $needle
* @param T[] $haystack
*/
function list_search(mixed $needle, array $haystack): int|false
{
$key = array_search($needle, $haystack, strict: true);
return is_int($key) ? $key : false;
}

// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

// Useful exceptions
Expand Down
3 changes: 1 addition & 2 deletions pinc/page_table.inc
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,8 @@ function fetch_page_table_data(Project $project, $page_selector = null, ?Round $
$tables = $project->projectid;
foreach ($rounds_to_display as $round) {
$rn = $round->round_number;

// find the previous round with data to use as the diff column
$rounds_with_data_index = array_search($round, $rounds_with_data);
$rounds_with_data_index = list_search($round, $rounds_with_data);
if ($rounds_with_data_index === 0 || $rn == 1) {
$prev_text_column_name = 'master_text';
} elseif ($rounds_with_data_index === false) {
Expand Down