Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type release queues #1402

Merged
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
8 changes: 4 additions & 4 deletions api/v1_queues.inc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include_once("api_common.inc");

//---------------------------------------------------------------------------
// queues -- list queues, optionally filtered by round
function api_v1_queues($method, $data, $query_params)
function api_v1_queues(string $method, array $data, array $query_params): array
{
$roundid = $query_params["roundid"] ?? null;
$round = !is_null($roundid) ? validate_round($roundid, null) : null;
Expand Down Expand Up @@ -55,7 +55,7 @@ function api_v1_queues($method, $data, $query_params)

//---------------------------------------------------------------------------
// queues/:queueid -- return release queue info
function api_v1_queue($method, $data, $query_params)
function api_v1_queue(string $method, array $data, array $query_params): array
{
$queue = $data[":queueid"];

Expand All @@ -64,7 +64,7 @@ function api_v1_queue($method, $data, $query_params)

//---------------------------------------------------------------------------
// queue/:queueid/stats -- return release queue stats
function api_v1_queue_stats($method, $data, $query_params)
function api_v1_queue_stats(string $method, array $data, array $query_params): array
{
$queue = $data[":queueid"];

Expand All @@ -76,7 +76,7 @@ function api_v1_queue_stats($method, $data, $query_params)

//---------------------------------------------------------------------------
// queue/:queueid/projects -- list projects in release queue
function api_v1_queue_projects($method, $data, $query_params)
function api_v1_queue_projects(string $method, array $data, array $query_params): array
{
$queue = $data[":queueid"];
$unheld_only = (bool) get_flag_value($query_params, "unheld_only");
Expand Down
4 changes: 2 additions & 2 deletions api/v1_validators.inc
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ function validate_page_round($pageround, $data)
}
}

function validate_release_queue($queueid, $data)
function validate_release_queue(string $queueid, array $_data): array
{
$queue_data = fetch_queue_data($queueid);
$queue_data = fetch_queue_data((int)$queueid);
if (is_null($queue_data)) {
throw new NotFoundError("queue {$queueid} not found");
}
Expand Down
29 changes: 10 additions & 19 deletions pinc/release_queue.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ define('MAX_PAGES_TARGET', 16777215); // max unsigned mediumint

/**
* Format a queue's targets as a release condition.
*
* @param int $projects_target
* @param int $pages_target
*
* @return string
*/
function format_queue_targets_as_condition($projects_target, $pages_target)
function format_queue_targets_as_condition(int $projects_target, int $pages_target): string
{
if ($projects_target == MAX_PROJECTS_TARGET || $pages_target == MAX_PAGES_TARGET) {
// The queue always releases (assuming that the actual number of relevant
Expand All @@ -40,7 +35,7 @@ $tomorrow_MMDD = date('md', strtotime('tomorrow'));
* Expanding date-related sequences means we don't have to
* update the queue's project_selector every day.
*/
function cook_project_selector($project_selector)
function cook_project_selector(string $project_selector): string
{
global $today_MMDD, $tomorrow_MMDD;
return
Expand All @@ -51,7 +46,8 @@ function cook_project_selector($project_selector)
);
}

function _get_queue_length($cooked_project_selector, $project_waiting_state)
/** @return array{0: ?int, 1: ?int} */
function _get_queue_length(string $cooked_project_selector, string $project_waiting_state): array
{
$state_clause = set_col_str("state", $project_waiting_state);
$c_sql = "
Expand Down Expand Up @@ -125,7 +121,7 @@ function _get_queue_length($cooked_project_selector, $project_waiting_state)
*
* @return Generator<array>
*/
function fetch_queues_data($round, $show, $show_groups, $name_selector = null, $group_selector = null)
function fetch_queues_data(?Round $round, string $show, bool $show_groups, $name_selector = null, $group_selector = null)
{
// Building the WHERE clause is rather ad-hoc, mostly because
// a bunch of the output fields don't come directly from the DB result.
Expand Down Expand Up @@ -229,13 +225,8 @@ function fetch_queue_data_by_name($round, $name)

/**
* Return queue data array for a specified release queue
*
* @param int $queueid
* The release queue ID
*
* @return array|null
**/
function fetch_queue_data($queueid)
function fetch_queue_data(int $queueid): ?array
{
$sql = sprintf(
"
Expand All @@ -252,7 +243,7 @@ function fetch_queue_data($queueid)
return _queue_data($res);
}

function _queue_data($row, $length = null, $unheld_length = null)
function _queue_data(array $row, int $length = null, int $unheld_length = null): array
{
$round = Rounds::get_by_id($row["round_id"]);
if (is_null($length) || is_null($unheld_length)) {
Expand Down Expand Up @@ -286,7 +277,7 @@ function _queue_data($row, $length = null, $unheld_length = null)
*
* @return Generator<array>
**/
function fetch_queue_projects_data($round, $project_selector, $unheld_only)
function fetch_queue_projects_data(Round $round, string $project_selector, bool $unheld_only)
{
$cooked_project_selector = cook_project_selector($project_selector);
$unheld_only_sql = $unheld_only ? "project_holds.state is NULL" : "1";
Expand Down Expand Up @@ -332,9 +323,9 @@ function fetch_queue_projects_data($round, $project_selector, $unheld_only)
* @param string $name
* The name of the release queue
*
* @return array
* @return array{"days_ago": int, "projects_released": int, "pages_released": int}[]
**/
function fetch_queue_stats_data($round, $name)
function fetch_queue_stats_data(Round $round, string $name): array
{
$data = [];
foreach ([1, 7, 28, 84] as $days_ago) {
Expand Down
11 changes: 6 additions & 5 deletions stats/release_queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
$round = get_round_param($_GET, 'round_id', null, true);
$name = @$_GET['name'];
$listing_view_mode = get_enumerated_param($_GET, "show", "populated", array_keys($listing_view_modes));
$unheld_only = get_integer_param($_GET, 'unheld_only', 0, 0, 1);
$unheld_only = get_bool_param($_GET, 'unheld_only', false);

$title = _("Release Queues");
output_header($title, NO_STATSBAR);
Expand All @@ -41,7 +41,7 @@

//-----------------------------------------------------------------------------

function _show_available_rounds()
function _show_available_rounds(): void
{
echo html_safe(_("Each round has its own set of release queues.")), "\n";
echo html_safe(_("Please select the round that you're interested in:")), "\n";
Expand All @@ -52,7 +52,7 @@ function _show_available_rounds()
echo "</ul>\n";
}

function _show_round_queues($round, $listing_view_mode)
function _show_round_queues(Round $round, string $listing_view_mode): void
{
global $code_url, $listing_view_modes;

Expand Down Expand Up @@ -163,7 +163,7 @@ function _show_round_queues($round, $listing_view_mode)
}
}

function _show_queue_details($round, $name, $unheld_only)
function _show_queue_details(Round $round, string $name, bool $unheld_only): void
{
global $code_url;
$queue = fetch_queue_data_by_name($round, $name);
Expand Down Expand Up @@ -266,7 +266,8 @@ function _show_queue_details($round, $name, $unheld_only)
echo "</table>";
}

function _get_num_projects_and_pages_available($round)
/** @return array{0: int, 1: int} */
function _get_num_projects_and_pages_available(Round $round): array
{
$sql = sprintf(
"
Expand Down