From 26deb4b09490dccbe9a0d206584ecbacd2ef4a77 Mon Sep 17 00:00:00 2001 From: Eddie Kohler Date: Wed, 6 May 2020 13:13:30 -0400 Subject: [PATCH] Braces, null coalescing, remove unused. --- autoassign.php | 38 +++-- batch/fakenames.php | 12 +- buzzer.php | 32 ++-- checkupdates.php | 30 ++-- lib/cleanhtml.php | 3 +- lib/ht.php | 40 ++--- lib/json.php | 6 +- lib/mincostmaxflow.php | 278 ++++++++++++++++++++++------------ lib/scoreinfo.php | 49 +++--- lib/tagger.php | 33 ++-- lib/xlsx.php | 4 +- manualassign.php | 6 +- offline.php | 22 +-- profile.php | 3 +- review.php | 43 +++--- src/assigners/a_decision.php | 13 +- src/capability.php | 8 +- src/commentinfo.php | 8 +- src/conference.php | 15 +- src/contact.php | 55 ++++--- src/contactlist.php | 4 +- src/documentinfo.php | 44 ++++-- src/formatspec.php | 17 ++- src/formulas/f_author.php | 3 +- src/helpers.php | 3 +- src/init.php | 6 +- src/meetingtracker.php | 82 ++++++---- src/paperinfo.php | 18 ++- src/papersearch.php | 84 +++++----- src/papertable.php | 3 +- src/settings/s_reviewform.php | 3 +- 31 files changed, 596 insertions(+), 369 deletions(-) diff --git a/autoassign.php b/autoassign.php index d68b26da0..3bd619021 100644 --- a/autoassign.php +++ b/autoassign.php @@ -3,22 +3,26 @@ // Copyright (c) 2006-2020 Eddie Kohler; see LICENSE. require_once("src/initweb.php"); -if (!$Me->is_manager()) +if (!$Me->is_manager()) { $Me->escape(); +} // clean request // paper selection -if (!isset($Qreq->q) || trim($Qreq->q) === "(All)") +if (!isset($Qreq->q) || trim($Qreq->q) === "(All)") { $Qreq->q = ""; -if ($Qreq->post_ok()) +} +if ($Qreq->post_ok()) { header("X-Accel-Buffering: no"); // NGINX: do not hold on to file +} $tOpt = PaperSearch::manager_search_types($Me); if ($Me->privChair && !isset($Qreq->t) && $Qreq->a === "prefconflict" - && $Conf->can_pc_see_active_submissions()) + && $Conf->can_pc_see_active_submissions()) { $Qreq->t = "all"; +} if (!isset($Qreq->t) || !isset($tOpt[$Qreq->t])) { reset($tOpt); $Qreq->t = key($tOpt); @@ -50,26 +54,31 @@ $x = preg_split('/\s+/', $Conf->setting_data("autoassign_badpairs", ""), null, PREG_SPLIT_NO_EMPTY); $pcm = $Conf->pc_members(); $bpnum = 1; - for ($i = 0; $i < count($x) - 1; $i += 2) - if (isset($pcm[$x[$i]]) && isset($pcm[$x[$i+1]])) { + for ($i = 0; $i < count($x) - 1; $i += 2) { + if (isset($pcm[(int) $x[$i]]) && isset($pcm[(int) $x[$i+1]])) { $Qreq["bpa$bpnum"] = $pcm[$x[$i]]->email; $Qreq["bpb$bpnum"] = $pcm[$x[$i+1]]->email; ++$bpnum; } - if ($Conf->setting("autoassign_badpairs")) + } + if ($Conf->setting("autoassign_badpairs")) { $Qreq->badpairs = 1; + } } else if ($Me->privChair && isset($Qreq->assign) && $Qreq->post_ok()) { $x = array(); - for ($i = 1; isset($Qreq["bpa$i"]); ++$i) + for ($i = 1; isset($Qreq["bpa$i"]); ++$i) { if ($Qreq["bpa$i"] && $Qreq["bpb$i"] && ($pca = $Conf->pc_member_by_email($Qreq["bpa$i"])) && ($pcb = $Conf->pc_member_by_email($Qreq["bpb$i"]))) { $x[] = $pca->contactId; $x[] = $pcb->contactId; } - if (count($x) || $Conf->setting_data("autoassign_badpairs") - || (!isset($Qreq->badpairs) != !$Conf->setting("autoassign_badpairs"))) + } + if (count($x) + || $Conf->setting_data("autoassign_badpairs") + || (!isset($Qreq->badpairs) != !$Conf->setting("autoassign_badpairs"))) { $Conf->q("insert into Settings (name, value, data) values ('autoassign_badpairs', ?, ?) on duplicate key update data=values(data), value=values(value)", isset($Qreq->badpairs) ? 1 : 0, join(" ", $x)); + } } // set $badpairs array $badpairs = array(); @@ -108,18 +117,21 @@ $SSel->sort_selection(); // rev_round -if (($x = $Conf->sanitize_round_name($Qreq->rev_round)) !== false) +if (($x = $Conf->sanitize_round_name($Qreq->rev_round)) !== false) { $Qreq->rev_round = $x; +} // score selector $scoreselector = array("+overAllMerit" => "", "-overAllMerit" => ""); -foreach ($Conf->all_review_fields() as $f) +foreach ($Conf->all_review_fields() as $f) { if ($f->has_options) { $scoreselector["+" . $f->id] = "high $f->name_html scores"; $scoreselector["-" . $f->id] = "low $f->name_html scores"; } -if ($scoreselector["+overAllMerit"] === "") +} +if ($scoreselector["+overAllMerit"] === "") { unset($scoreselector["+overAllMerit"], $scoreselector["-overAllMerit"]); +} $scoreselector["__break"] = null; $scoreselector["x"] = "random submitted reviews"; $scoreselector["xa"] = "random reviews"; diff --git a/batch/fakenames.php b/batch/fakenames.php index b56e74425..ec632245a 100644 --- a/batch/fakenames.php +++ b/batch/fakenames.php @@ -138,18 +138,20 @@ function new_fake_email() { // process papers $result = $Conf->qe("select * from Paper"); $papers = []; -while (($p = PaperInfo::fetch($result, null, $Conf))) +while (($p = PaperInfo::fetch($result, null, $Conf))) { $papers[] = $p; +} Dbl::free($result); $q = $qv = []; foreach ($papers as $p) { $ax = []; foreach ($p->author_list() as $a) { - if ($a->email && isset($email_map[strtolower($a->email)])) + if ($a->email && isset($email_map[strtolower($a->email)])) { $aa = $email_map[strtolower($a->email)]; - else + } else { $aa = [$fakes->first(), $fakes->last(), new_fake_email(), $fakes->affiliation()]; + } $ax[] = join("\t", $aa) . "\n"; } $q[] = "update Paper set authorInformation=? where paperId={$p->paperId}"; @@ -167,9 +169,9 @@ function new_fake_email() { $nl = ""; while (preg_match('/\A(.*?)([^\s\(\)\<\>@\/]+@[^\s\(\)\]\>\/]+\.[A-Za-z]+)(.*)\z/', $l, $m)) { $nl .= $m[1]; - if (isset($email_map[strtolower($m[2])])) + if (isset($email_map[strtolower($m[2])])) { $nl .= $email_map[strtolower($m[2])][2]; - else { + } else { $ne = new_fake_email(); $email_map[strtolower($m[2])] = [$fakes->first(), $fakes->last(), $ne, $fakes->affiliation()]; $nl .= $ne; diff --git a/buzzer.php b/buzzer.php index ac3ce176a..2b8822d84 100644 --- a/buzzer.php +++ b/buzzer.php @@ -21,16 +21,18 @@ reset($kiosks); } // look for new kiosks - $kiosk_keys = array(null, null); - foreach ($kiosks as $k => $kj) + $kiosk_keys = [null, null]; + foreach ($kiosks as $k => $kj) { if ($kj->update_at >= $Now - 7200) $kiosk_keys[$kj->show_papers ? 1 : 0] = $k; - for ($i = 0; $i <= 1; ++$i) + } + for ($i = 0; $i <= 1; ++$i) { if (!$kiosk_keys[$i]) { $key = hotcrp_random_password(); - $kiosks[$key] = (object) array("update_at" => $Now, "show_papers" => !!$i); + $kiosks[$key] = (object) ["update_at" => $Now, "show_papers" => !!$i]; $kiosk_keys[$i] = $kchange = $key; } + } // save kiosks if ($kchange) $Conf->save_setting("__tracker_kiosk", 1, $kiosks); @@ -45,28 +47,33 @@ function kiosk_lookup($key) { global $Conf, $Now; - $kiosks = (array) ($Conf->setting_json("__tracker_kiosk") ? : array()); - if (isset($kiosks[$key]) && $kiosks[$key]->update_at >= $Now - 604800) + $kiosks = (array) ($Conf->setting_json("__tracker_kiosk") ? : []); + if (isset($kiosks[$key]) && $kiosks[$key]->update_at >= $Now - 604800) { return $kiosks[$key]; - return null; + } else { + return null; + } } $kiosk = null; if (!$Me->has_email() && ($key = $Qreq->path_component(0)) - && ($kiosk = kiosk_lookup($key))) + && ($kiosk = kiosk_lookup($key))) { $Me->set_capability("tracker_kiosk", $key); -else if (($key = $Me->capability("tracker_kiosk"))) +} else if (($key = $Me->capability("tracker_kiosk"))) { $kiosk = kiosk_lookup($key); - +} if ($kiosk) { $Me->tracker_kiosk_state = $kiosk->show_papers ? 2 : 1; $show_papers = $kiosk->show_papers; +} else { + $show_papers = true; } // user -if (!$Me->isPC && !$Me->tracker_kiosk_state) +if (!$Me->isPC && !$Me->tracker_kiosk_state) { $Me->escape(); +} $Conf->header("Discussion status", "buzzer", ["action_bar" => false, "body_class" => "hide-tracker"]); @@ -115,8 +122,9 @@ function kiosk_lookup($key) { $Conf->hoturl_absolute("buzzer", ["__PATH__" => $kiosk_keys[0]], Conf::HOTURL_RAW), $Conf->hoturl_absolute("buzzer", ["__PATH__" => $kiosk_keys[1]], Conf::HOTURL_RAW) ]; -} else if ($kiosk) +} else if ($kiosk) { $buzzer_status["is_kiosk"] = true; +} $buzzer_status["no_discussion"] = $no_discussion . ''; echo Ht::unstash(); echo $Conf->make_script_file("scripts/buzzer.js"); diff --git a/checkupdates.php b/checkupdates.php index 514613c10..9e19e0ed4 100644 --- a/checkupdates.php +++ b/checkupdates.php @@ -18,47 +18,55 @@ && is_array($data["updates"])) { foreach ($data["updates"] as $update) { $ok = true; - if (isset($update["opt"]) && is_array($update["opt"])) + if (isset($update["opt"]) && is_array($update["opt"])) { foreach ($update["opt"] as $k => $v) { $kk = ($k[0] == "-" ? substr($k, 1) : $k); $test = $Conf->opt($kk, null) == $v; $ok = $ok && ($k[0] == "-" ? !$test : $test); } + } if (isset($update["settings"]) && is_array($update["settings"])) foreach ($update["settings"] as $k => $v) { if (preg_match('/\A([!<>]?)(-?\d+|now)\z/', $v, $m)) { $setting = $Conf->setting($k, 0); - if ($m[2] == "now") + if ($m[2] == "now") { $m[2] = time(); - if ($m[1] == "!") + } + if ($m[1] == "!") { $test = $setting != +$m[2]; - else if ($m[1] == ">") + } else if ($m[1] == ">") { $test = $setting > +$m[2]; - else if ($m[1] == "<") + } else if ($m[1] == "<") { $test = $setting < +$m[2]; - else + } else { $test = $setting == +$m[2]; + } $ok = $ok && $test; } } $errid = isset($update["errid"]) && ctype_alnum("" . $update["errid"]) ? $update["errid"] : false; - if ($errid && $Conf->setting("ignoreupdate_$errid", 0) > time()) + if ($errid && $Conf->setting("ignoreupdate_$errid", 0) > time()) { $ok = false; + } if ($ok) { $m = "
WARNING: Upgrade your HotCRP installation."; - if (isset($update["vulnid"]) && is_numeric($update["vulnid"])) + if (isset($update["vulnid"]) && is_numeric($update["vulnid"])) { $m .= " (HotCRP-Vulnerability-" . $update["vulnid"] . ")"; + } $m .= "
"; - if (isset($update["message"]) && is_string($update["message"])) + if (isset($update["message"]) && is_string($update["message"])) { $m .= "
" . CleanHTML::clean($update["message"], $error) . "
"; + } if (isset($update["to"]) && is_string($update["to"])) { $m .= "
First unaffected commit: " . htmlspecialchars($update["to"]); - if ($errid) + if ($errid) { $m .= ' · ' . 'Ignore for two days'; + } $m .= "
"; } $messages[] = $m . "
\n"; diff --git a/lib/cleanhtml.php b/lib/cleanhtml.php index c8fee0ea6..7d74411aa 100644 --- a/lib/cleanhtml.php +++ b/lib/cleanhtml.php @@ -144,8 +144,9 @@ function clean_all($t, &$err = null) { } static function basic() { - if (!self::$g) + if (!self::$g) { self::$g = new CleanHTML; + } return self::$g; } diff --git a/lib/ht.php b/lib/ht.php index 4ffa1fcc1..4d0fc5162 100644 --- a/lib/ht.php +++ b/lib/ht.php @@ -68,7 +68,9 @@ static function script($script) { } static function script_file($src, $js = null) { - if ($js && get($js, "crossorigin") && !preg_match(',\A([a-z]+:)?//,', $src)) { + if ($js + && ($js["crossorigin"] ?? false) + && !preg_match('/\A([a-z]+:)?\/\//', $src)) { unset($js["crossorigin"]); } return self::$_script_open . ' src="' . htmlspecialchars($src) . '"' . self::extra($js) . '>'; @@ -79,16 +81,16 @@ static function stylesheet_file($src) { . htmlspecialchars($src) . "\" />"; } - static function form($action, $extra = null) { + static function form($action, $extra = []) { if (is_array($action)) { $extra = $action; - $action = get($extra, "action", ""); + $action = $extra["action"] ?? ""; } // GET method requires special handling: extract params from URL // and render as hidden inputs $suffix = ">"; - $method = get($extra, "method") ? : "post"; + $method = $extra["method"] ?? "post"; if ($method === "get" && ($qpos = strpos($action, "?")) !== false) { $pos = $qpos + 1; @@ -108,7 +110,7 @@ static function form($action, $extra = null) { if ((string) $action !== "") { $x .= ' method="' . $method . '" action="' . $action . '"'; } - $enctype = get($extra, "enctype"); + $enctype = $extra["enctype"] ?? null; if (!$enctype && $method !== "get") { $enctype = "multipart/form-data"; } @@ -128,17 +130,17 @@ static function select($name, $opt, $selected = null, $js = null) { if (is_array($selected) && $js === null) { list($js, $selected) = array($selected, null); } - $disabled = get($js, "disabled"); + $disabled = $js["disabled"] ?? null; if (is_array($disabled)) { unset($js["disabled"]); } - $optionstyles = get($js, "optionstyles", null); + $optionstyles = $js["optionstyles"] ?? null; $x = $optgroup = ""; $first_value = $has_selected = false; foreach ($opt as $value => $info) { if (is_array($info) && isset($info[0]) && $info[0] === "optgroup") { - $info = (object) array("type" => "optgroup", "label" => get($info, 1)); + $info = (object) ["type" => "optgroup", "label" => $info[1] ?? null]; } else if (is_array($info)) { $info = (object) $info; } else if (is_scalar($info)) { @@ -166,7 +168,7 @@ static function select($name, $opt, $selected = null, $js = null) { } } else { $x .= 'id ?? null) { $x .= ' id="' . $info->id . '"'; } $x .= ' value="' . htmlspecialchars($value) . '"'; @@ -177,13 +179,13 @@ static function select($name, $opt, $selected = null, $js = null) { $x .= ' selected'; $has_selected = true; } - if (get($info, "disabled")) { + if ($info->disabled ?? false) { $x .= ' disabled'; } - if (get($info, "class")) { + if ($info->class ?? false) { $x .= ' class="' . $info->class . '"'; } - if (get($info, "style")) { + if ($info->style ?? false) { $x .= ' style="' . htmlspecialchars($info->style) . '"'; } $x .= '>' . $info->label . ''; @@ -208,7 +210,7 @@ static function checkbox($name, $value = 1, $checked = false, $js = null) { $js = $checked; $checked = false; } - $js = $js ? : array(); + $js = $js ? : []; if (!array_key_exists("id", $js) || $js["id"] === true) { $js["id"] = "htctl" . ++self::$_controlid; } @@ -283,19 +285,19 @@ static function hidden_default_submit($name, $value = null, $js = null) { } private static function apply_placeholder(&$value, &$js) { - if ($value === null || $value === get($js, "placeholder")) { + if ($value === null || $value === ($js["placeholder"] ?? null)) { $value = ""; } - if (($default = get($js, "data-default-value")) !== null + if (($default = $js["data-default-value"] ?? null) !== null && $value === $default) { unset($js["data-default-value"]); } } static function entry($name, $value, $js = null) { - $js = $js ? $js : array(); + $js = $js ? : array(); self::apply_placeholder($value, $js); - $type = get($js, "type") ? : "text"; + $type = $js["type"] ?? "text"; return ''; } @@ -420,11 +422,11 @@ static function format0($html_text) { } static function check_stash($uniqueid) { - return get(self::$_stash_map, $uniqueid, false); + return self::$_stash_map[$uniqueid] ?? false; } static function mark_stash($uniqueid) { - $marked = get(self::$_stash_map, $uniqueid); + $marked = self::$_stash_map[$uniqueid] ?? false; self::$_stash_map[$uniqueid] = true; return !$marked; } diff --git a/lib/json.php b/lib/json.php index 2b0a7acad..e92e80eec 100644 --- a/lib/json.php +++ b/lib/json.php @@ -109,15 +109,17 @@ private static function decode_part(&$x, $assoc, $depth, $options) { $x = substr($x, 1); $n = 0; while (true) { - if (!is_string($x)) + if (!is_string($x)) { return self::set_error($x, JSON_ERROR_SYNTAX); + } $x = ltrim($x); if ($x[0] === "}") { $x = substr($x, 1); break; } else if ($n) { - if ($x[0] !== ",") + if ($x[0] !== ",") { return self::set_error($x, JSON_ERROR_SYNTAX); + } $x = substr($x, 1); } diff --git a/lib/mincostmaxflow.php b/lib/mincostmaxflow.php index c05e4c661..0fd20448d 100644 --- a/lib/mincostmaxflow.php +++ b/lib/mincostmaxflow.php @@ -21,17 +21,20 @@ function __construct($name, $klass) { $this->klass = $klass; } function check_excess($expected) { - foreach ($this->e as $e) + foreach ($this->e as $e) { $expected += $e->flow_to($this); - if ($expected != $this->excess) + } + if ($expected != $this->excess) { fwrite(STDERR, "{$this->name}: bad excess e{$this->excess}, have $expected\n"); + } assert($expected == $this->excess); } function count_outgoing_price_admissible() { $n = 0; - foreach ($this->e as $e) + foreach ($this->e as $e) { if ($e->is_price_admissible_from($this)) ++$n; + } return $n; } function set_price_fix_admissible($p) { @@ -41,14 +44,17 @@ function set_price_fix_admissible($p) { // adjust n_outgoing_admissible counts foreach ($this->e as $e) { $rc = $e->cost + $e->src->price - $e->dst->price; - if ($e->src === $this) + if ($e->src === $this) { $old_rc = $e->cost + $old_price - $e->dst->price; - else + } else { $old_rc = $e->cost + $e->src->price - $old_price; - if (($rc < 0) !== ($old_rc < 0) && $e->flow < $e->cap) + } + if (($rc < 0) !== ($old_rc < 0) && $e->flow < $e->cap) { $e->src->n_outgoing_admissible += $rc < 0 ? 1 : -1; - if (($rc > 0) !== ($old_rc > 0) && $e->flow > $e->mincap) + } + if (($rc > 0) !== ($old_rc > 0) && $e->flow > $e->mincap) { $e->dst->n_outgoing_admissible += $rc > 0 ? 1 : -1; + } } } }; @@ -92,17 +98,19 @@ function reduced_cost_from($v) { return $this->reduced_cost($v === $this->dst); } function is_distance_admissible_from($v) { - if ($v === $this->src) + if ($v === $this->src) { return $this->flow < $this->cap && $v->distance == $this->dst->distance + 1; - else + } else { return $this->flow > $this->mincap && $v->distance == $this->src->distance + 1; + } } function is_price_admissible_from($v) { $c = $this->cost + $this->src->price - $this->dst->price; - if ($v === $this->src) + if ($v === $this->src) { return $this->flow < $this->cap && $c < 0; - else + } else { return $this->flow > $this->mincap && $c > 0; + } } function update_flow($delta) { $this->flow += $delta; @@ -152,8 +160,9 @@ function __construct($flags = false) { } function add_node($name, $klass = "") { - if ($name === "") + if ($name === "") { $name = ".v" . count($this->v); + } assert(is_string($name) && !isset($this->vmap[$name])); $v = new MinCostMaxFlow_Node($name, $klass); $this->v[] = $this->vmap[$name] = $v; @@ -161,10 +170,12 @@ function add_node($name, $klass = "") { } function add_edge($vs, $vd, $cap, $cost = 0, $mincap = 0) { - if (is_string($vs)) + if (is_string($vs)) { $vs = $this->vmap[$vs]; - if (is_string($vd)) + } + if (is_string($vd)) { $vd = $this->vmap[$vd]; + } assert(($vs instanceof MinCostMaxFlow_Node) && ($vd instanceof MinCostMaxFlow_Node)); assert($vs !== $this->sink && $vd !== $this->source && $vs !== $vd); // XXX assert(this edge does not exist) @@ -187,40 +198,45 @@ function node_exists($name) { function nodes($klass) { $a = array(); - foreach ($this->v as $v) + foreach ($this->v as $v) { if ($v->klass === $klass) $a[] = $v; + } return $a; } function current_flow() { - if ($this->maxflow !== null) + if ($this->maxflow !== null) { return $this->maxflow; - else + } else { return min(-$this->source->excess, $this->sink->excess); + } } function current_cost() { $cost = 0; - foreach ($this->e as $e) + foreach ($this->e as $e) { if ($e->flow) $cost += $e->flow * $e->cost; + } return $cost; } private function add_reachable($v, $klass, &$a) { - if ($v->klass === $klass) + if ($v->klass === $klass) { $a[] = $v; - else if ($v !== $this->sink) { - foreach ($v->e as $e) + } else if ($v !== $this->sink) { + foreach ($v->e as $e) { if ($e->src === $v && $e->flow > 0) $this->add_reachable($e->dst, $klass, $a); + } } } function reachable($v, $klass) { - if (is_string($v)) + if (is_string($v)) { $v = $this->vmap[$v]; + } $a = array(); $this->add_reachable($v, $klass, $a); return $a; @@ -229,19 +245,23 @@ function reachable($v, $klass) { private function topological_sort_visit($v, $klass, &$a) { if ($v !== $this->sink && !$v->npos) { $v->npos = 1; - foreach ($v->e as $e) + foreach ($v->e as $e) { if ($e->src === $v && $e->flow > 0 && !$e->dst->npos) $this->topological_sort_visit($e->dst, $klass, $a); - if ($v->klass === $klass) + } + if ($v->klass === $klass) { $a[] = $v; + } } } function topological_sort($v, $klass) { - if (is_string($v)) + if (is_string($v)) { $v = $this->vmap[$v]; - foreach ($this->v as $vx) + } + foreach ($this->v as $vx) { $vx->npos = 0; + } $a = array(); $this->topological_sort_visit($v, $klass, $a); return array_reverse($a); @@ -251,10 +271,13 @@ function topological_sort($v, $klass) { // internals private function initialize_edges() { - foreach ($this->e as $e) + // all sources must come before all destinations + foreach ($this->e as $e) { $e->src->e[] = $e; - foreach ($this->e as $e) + } + foreach ($this->e as $e) { $e->dst->e[] = $e; + } } @@ -271,17 +294,19 @@ private static function pushrelabel_bfs_setdistance($qtail, $v, $dist) { } private function pushrelabel_make_distance() { - foreach ($this->v as $v) + foreach ($this->v as $v) { $v->xlink = $this->sink; + } $qhead = $qtail = $this->sink; $qhead->distance = 0; $qhead->xlink = null; while ($qhead) { $d = $qhead->distance + 1; - foreach ($qhead->e as $e) + foreach ($qhead->e as $e) { if ($e->residual_cap_to($qhead) > 0 && $e->other($qhead)->xlink === $this->sink) $qtail = self::pushrelabel_bfs_setdistance($qtail, $e->other($qhead), $d); + } $qhead = $qhead->xlink; } } @@ -295,9 +320,10 @@ private function pushrelabel_push_from($e, $src) { private function pushrelabel_relabel($v) { $d = INF; - foreach ($v->e as $e) + foreach ($v->e as $e) { if ($e->residual_cap_from($v) > 0) $d = min($d, $e->other($v)->distance + 1); + } //fwrite(STDERR, "relabel {$v->name}@{$v->distance}->{$d}\n"); $v->distance = $d; $v->npos = 0; @@ -312,10 +338,11 @@ private function pushrelabel_discharge($v) { $relabeled = true; } else { $e = $v->e[$v->npos]; - if ($e->is_distance_admissible_from($v)) + if ($e->is_distance_admissible_from($v)) { $this->pushrelabel_push_from($e, $v); - else + } else { ++$v->npos; + } } } return $relabeled; @@ -331,20 +358,22 @@ private function pushrelabel_run() { } $this->pushrelabel_make_distance(); foreach ($this->e as $e) { - if ($e->src === $this->source) + if ($e->src === $this->source) { $e->update_flow($e->cap); - else if ($e->mincap > 0) + } else if ($e->mincap > 0) { $e->update_flow($e->mincap); + } } // initialize list $lhead = $ltail = null; - foreach ($this->v as $v) + foreach ($this->v as $v) { if ($v !== $this->source && $v !== $this->sink) { $ltail ? ($ltail->link = $v) : ($lhead = $v); $v->link = null; $ltail = $v; } + } // relabel-to-front $n = 0; @@ -355,9 +384,11 @@ private function pushrelabel_run() { while ($l) { // check progress ++$n; - if ($n % 32768 == 0) - foreach ($this->progressf as $progressf) + if ($n % 32768 == 0) { + foreach ($this->progressf as $progressf) { call_user_func($progressf, $this, self::PMAXFLOW); + } + } // discharge current vertex if ($this->pushrelabel_discharge($l)) { @@ -395,8 +426,9 @@ private function pushrelabel_run() { $this->maxflow = $this->sink->excess; $this->source->excess = $this->sink->excess = 0; $this->maxflow_end_at = microtime(true); - foreach ($this->progressf as $progressf) + foreach ($this->progressf as $progressf) { call_user_func($progressf, $this, self::PMAXFLOW_DONE); + } } @@ -414,8 +446,9 @@ private function cspushrelabel_push_from($e, $src) { $amt = min($src->excess, $e->residual_cap_from($src)); $amt = ($e->src === $src ? $amt : -$amt); $e->update_flow($amt); - if (!$e->residual_cap_from($src)) + if (!$e->residual_cap_from($src)){ --$src->n_outgoing_admissible; + } if ($dst->excess > 0 && $dst->link === false) { $this->ltail = $this->ltail->link = $dst; @@ -429,22 +462,24 @@ private function cspushrelabel_relabel($v) { // calculate new price $p = -INF; foreach ($v->e as $epos => $e) { - if ($e->src === $v && $e->flow < $e->cap) + if ($e->src === $v && $e->flow < $e->cap) { $px = $e->dst->price - $e->cost; - else if ($e->dst === $v && $e->flow > $e->mincap) + } else if ($e->dst === $v && $e->flow > $e->mincap) { $px = $e->src->price + $e->cost; - else + } else { continue; + } if ($px > $p) { $p = $px; $ex = $epos; } } assert($p != -INF || $v->excess == 0); - if ($p > -INF) + if ($p > -INF) { $v->npos = $ex; - else + } else { $p = $v->price; + } $p -= $this->epsilon; $this->debug && fwrite(STDERR, "relabel {$v->name} E{$v->excess} @{$v->price}->{$p}\n"); $v->set_price_fix_admissible($p); @@ -454,14 +489,15 @@ private function cspushrelabel_relabel($v) { private function cspushrelabel_discharge($v) { $ne = count($v->e); while ($v->excess > 0) { - if ($v->npos == $ne || !$v->n_outgoing_admissible) + if ($v->npos == $ne || !$v->n_outgoing_admissible) { $this->cspushrelabel_relabel($v); - else { + } else { $e = $v->e[$v->npos]; - if ($e->is_price_admissible_from($v)) + if ($e->is_price_admissible_from($v)) { $this->cspushrelabel_push_from($e, $v); - else + } else { ++$v->npos; + } } } } @@ -476,8 +512,9 @@ private function cspushrelabel_reprice() { if ($v->excess < 0) { $v->distance = 0; $b[0][] = $v; - } else + } else { $v->distance = $max_distance; + } $excess += max($v->excess, 0); } $total_excess = $excess; @@ -490,39 +527,47 @@ private function cspushrelabel_reprice() { continue; } $v = array_pop($b[$bi]); - if ($v->distance !== $bi) + if ($v->distance !== $bi) { continue; - foreach ($v->e as $ei => $e) + } + foreach ($v->e as $ei => $e) { if ($e->residual_cap_to($v) && ($dst = $e->other($v)) && $bi < $dst->distance) { $nd = $bi; $cost = $e->reduced_cost_from($dst); - if ($cost >= 0) + if ($cost >= 0) { $nd += 1 + (int) min($max_distance, $cost / $this->epsilon); + } if ($nd < $dst->distance) { $dst->distance = $nd; - while (count($b) <= $nd) + while (count($b) <= $nd) { $b[] = array(); + } $b[$nd][] = $dst; } } - if ($bi) + } + if ($bi) { $v->set_price_fix_admissible($v->price - $bi * $this->epsilon); + } $v->distance = -1; $excess -= max($v->excess, 0); } // reduce prices for unexamined nodes - if ($total_excess && $bi) - foreach ($this->v as $v) + if ($total_excess && $bi) { + foreach ($this->v as $v) { if ($v->distance >= 0) $v->set_price_fix_admissible($v->price - $bi * $this->epsilon); + } + } } private function cspushrelabel_refine($phaseno, $nphases) { - foreach ($this->progressf as $progressf) + foreach ($this->progressf as $progressf) { call_user_func($progressf, $this, self::PMINCOST_BEGINROUND, $phaseno, $nphases); + } // arc fixing; note that Goldberg 1997's description of arc fixing // is incorrect/misleading -- we care about the absolute value of @@ -531,20 +576,23 @@ private function cspushrelabel_refine($phaseno, $nphases) { $fixbound = count($this->v) * $this->epsilon * (1 + 1.0 / self::CSPUSHRELABEL_ALPHA); if (max(abs($this->mincost), $this->maxcost) >= $fixbound) { $ndropped = 0; - foreach ($this->v as $v) + foreach ($this->v as $v) { for ($i = 0; $i < count($v->e); ) { $e = $v->e[$i]; if (abs($e->reduced_cost(false)) >= $fixbound) { - if ($e->is_price_admissible_from($v)) + if ($e->is_price_admissible_from($v)) { --$v->n_outgoing_admissible; + } $v->xe[] = $e; $v->e[$i] = $v->e[count($v->e) - 1]; array_pop($v->e); $v->npos = 0; // keep npos in bounds ++$ndropped; - } else + } else { ++$i; + } } + } $this->debug && $ndropped && fwrite(STDERR, "dropedge $ndropped\n"); } @@ -557,15 +605,17 @@ private function cspushrelabel_refine($phaseno, $nphases) { $this->debug && fwrite(STDERR, "phase " . (1 + $phaseno) . " epsilon $this->epsilon\n"); // saturate negative-cost arcs - foreach ($this->v as $v) + foreach ($this->v as $v) { if ($v->n_outgoing_admissible) { - foreach ($v->e as $e) + foreach ($v->e as $e) { if ($e->is_price_admissible_from($v)) { $delta = ($e->src === $v ? $e->cap : $e->mincap) - $e->flow; $e->update_flow($delta); --$v->n_outgoing_admissible; } + } } + } // initialize lists and neighbor position $lhead = $this->ltail = null; @@ -575,8 +625,9 @@ private function cspushrelabel_refine($phaseno, $nphases) { $this->ltail ? ($this->ltail->link = $v) : ($lhead = $v); $v->link = null; $this->ltail = $v; - } else + } else { $v->link = false; + } } // price update heuristic @@ -587,8 +638,9 @@ private function cspushrelabel_refine($phaseno, $nphases) { while ($lhead) { // check progress if ($this->npush + $this->nrelabel - $n >= 2048) { - foreach ($this->progressf as $progressf) + foreach ($this->progressf as $progressf) { call_user_func($progressf, $this, self::PMINCOST_INROUND, $phaseno, $nphases); + } $n = $this->npush + $this->nrelabel; } @@ -602,17 +654,21 @@ private function cspushrelabel_refine($phaseno, $nphases) { } function cspushrelabel_check($allow_excess = false) { - if (!$allow_excess) - foreach ($this->v as $v) + if (!$allow_excess) { + foreach ($this->v as $v) { if ($v->excess > 0) fwrite(STDERR, "BUG: node {$v->name} has positive excess {$v->excess}\n"); + } + } $ebound = -$this->epsilon - (0.5 / count($this->v)); foreach ($this->e as $e) { - if ($e->flow < $e->cap && $e->reduced_cost(false) < $ebound) + if ($e->flow < $e->cap && $e->reduced_cost(false) < $ebound) { fwrite(STDERR, "BUG: residual arc {$e->src->name} > {$e->dst->name} ({$e->flow}/{$e->cap} \${$e->cost}) has reduced cost " . $e->reduced_cost(false) . " < " . -$this->epsilon . "\n"); - if ($e->flow > $e->mincap && $e->reduced_cost(true) < $ebound) + } + if ($e->flow > $e->mincap && $e->reduced_cost(true) < $ebound) { fwrite(STDERR, "BUG: residual arc {$e->src->name} < {$e->dst->name} (" . (-$e->flow) . "/{$e->mincap} \$" . -$e->cost . ") has reduced cost " . $e->reduced_cost(true) . " < " . -$this->epsilon . "\n"); + } } } @@ -621,8 +677,9 @@ function cspushrelabel_finish() { $this->mincost_start_at = microtime(true); $this->npush = $this->nrelabel = 0; $phaseno = $nphases = 0; - for ($e = $this->epsilon; $e >= 1 / count($this->v); $e /= self::CSPUSHRELABEL_ALPHA) + for ($e = $this->epsilon; $e >= 1 / count($this->v); $e /= self::CSPUSHRELABEL_ALPHA) { ++$nphases; + } foreach ($this->v as $v) { $v->n_outgoing_admissible = $v->count_outgoing_price_admissible(); @@ -637,13 +694,15 @@ function cspushrelabel_finish() { } $this->mincost_end_at = microtime(true); - foreach ($this->v as $v) + foreach ($this->v as $v) { if ($v->xe) { $v->e = array_merge($v->e, $v->xe); $v->xe = null; } - foreach ($this->progressf as $progressf) + } + foreach ($this->progressf as $progressf) { call_user_func($progressf, $this, self::PMINCOST_DONE); + } } @@ -656,8 +715,9 @@ function shuffle() { private function make_debug_file() { global $Conf, $Now; - if (!($dir = $Conf->opt("minCostMaxFlowDebug"))) + if (!($dir = $Conf->opt("minCostMaxFlowDebug"))) { return null; + } $f = null; $time = time(); while (!$f && $time < $Now + 20) { @@ -678,16 +738,19 @@ function run() { fwrite($f, "\nc begintime " . microtime(true) . "\n"); } $this->pushrelabel_run(); - if ($f) + if ($f) { fwrite($f, "\nc pushrelabeltime " . microtime(true) . "\n"); + } if (!$this->infeasible && ($this->mincost != 0 || $this->maxcost != 0)) { $this->epsilon = max(abs($this->mincost), $this->maxcost); $this->cspushrelabel_finish(); - if ($f) + if ($f) { fwrite($f, "\nc cspushrelabeltime " . microtime(true) . "\n"); + } } - if ($f) + if ($f) { fclose($f); + } } @@ -697,8 +760,9 @@ function reset() { $v->distance = $v->excess = $v->price = 0; $v->e = array(); } - foreach ($this->e as $e) + foreach ($this->e as $e) { $e->flow = 0; + } $this->maxflow = null; $this->maxflow_start_at = $this->maxflow_end_at = null; $this->mincost_start_at = $this->mincost_end_at = null; @@ -708,10 +772,12 @@ function reset() { function clear() { // break circular references - foreach ($this->v as $v) + foreach ($this->v as $v) { $v->link = $v->xlink = $v->e = null; - foreach ($this->e as $e) + } + foreach ($this->e as $e) { $e->src = $e->dst = null; + } $this->v = array(); $this->e = array(); $this->vmap = array(); @@ -726,20 +792,24 @@ function debug_info($only_flow = false) { $ex = array(); $cost = 0; foreach ($this->e as $e) { - if ($e->flow || $e->mincap || !$only_flow) + if ($e->flow || $e->mincap || !$only_flow) { $ex[] = "{$e->src->name} {$e->dst->name} $e->mincap $e->cap $e->cost $e->flow\n"; - if ($e->flow) + } + if ($e->flow) { $cost += $e->flow * $e->cost; + } } usort($ex, "strnatcmp"); $vx = array(); - foreach ($this->v as $v) + foreach ($this->v as $v) { if ($v->excess) $vx[] = "E {$v->name} {$v->excess}\n"; + } usort($vx, "strnatcmp"); $x = ""; - if ($this->hasrun) + if ($this->hasrun) { $x = "total {$e->flow} $cost\n"; + } return $x . join("", $ex) . join("", $vx); } @@ -747,8 +817,9 @@ function debug_info($only_flow = false) { private function dimacs_input($mincost) { $x = array("p " . ($mincost ? "min" : "max") . " " . count($this->v) . " " . count($this->e) . "\n"); - foreach ($this->v as $i => $v) + foreach ($this->v as $i => $v) { $v->vindex = $i + 1; + } if ($mincost && $this->maxflow) { $x[] = "n {$this->source->vindex} {$this->maxflow}\n"; $x[] = "n {$this->sink->vindex} -{$this->maxflow}\n"; @@ -756,19 +827,22 @@ private function dimacs_input($mincost) { $x[] = "n {$this->source->vindex} s\n"; $x[] = "n {$this->sink->vindex} t\n"; } - foreach ($this->v as $v) + foreach ($this->v as $v) { if ($v !== $this->source && $v !== $this->sink) { $cmt = "c ninfo {$v->vindex} {$v->name}"; if ($v->klass !== "") $cmt .= " {$v->klass}"; $x[] = "$cmt\n"; } + } if ($mincost) { - foreach ($this->e as $e) + foreach ($this->e as $e) { $x[] = "a {$e->src->vindex} {$e->dst->vindex} {$e->mincap} {$e->cap} {$e->cost}\n"; + } } else { - foreach ($this->e as $e) + foreach ($this->e as $e) { $x[] = "a {$e->src->vindex} {$e->dst->vindex} {$e->cap}\n"; + } } return join("", $x); } @@ -785,28 +859,34 @@ function mincost_dimacs_input() { private function dimacs_output($mincost) { $x = array("c p " . ($mincost ? "min" : "max") . " " . count($this->v) . " " . count($this->e) . "\n"); - foreach ($this->v as $i => $v) + foreach ($this->v as $i => $v) { $v->vindex = $i + 1; + } if ($mincost) { $x[] = "s " . $this->current_cost() . "\n"; $x[] = "c flow " . $this->current_flow() . "\n"; $x[] = "c min_epsilon " . $this->epsilon . "\n"; - foreach ($this->v as $v) + foreach ($this->v as $v) { if ($v->price != 0) $x[] = "c nprice {$v->vindex} {$v->price}\n"; - } else + } + } else { $x[] = "s " . $this->current_flow() . "\n"; - foreach ($this->e as $e) + } + foreach ($this->e as $e) { if ($e->flow) { // is this flow ambiguous? $n = 0; - foreach ($e->src->e as $ee) + foreach ($e->src->e as $ee) { if ($ee->dst === $e->dst) ++$n; - if ($n !== 1) + } + if ($n !== 1) { $x[] = "c finfo {$e->cap} {$e->cost}\n"; + } $x[] = "f {$e->src->vindex} {$e->dst->vindex} {$e->flow}\n"; } + } return join("", $x); } @@ -820,8 +900,9 @@ function mincost_dimacs_output() { private function dimacs_node(&$vnames, $num, $name = "", $klass = "") { - if (!($v = get($vnames, $num))) + if (!($v = get($vnames, $num))) { $v = $vnames[$num] = $this->add_node($name, $klass); + } return $v; } @@ -832,8 +913,9 @@ function parse_dimacs($str) { $next_cap = $next_cost = null; $has_edges = false; foreach (CsvParser::split_lines($str) as $lineno => $line) { - if ($line[0] !== "f") + if ($line[0] !== "f") { $next_cap = $next_cost = null; + } if (preg_match('/\An (\d+) (-?\d+|s|t)\s*\z/', $line, $m)) { $issink = $m[2] === "t" || $m[2] < 0; assert(!get($vnames, $m[1])); @@ -869,7 +951,7 @@ function parse_dimacs($str) { $src = $this->dimacs_node($vnames, $m[1]); $dst = $this->dimacs_node($vnames, $m[2]); $found = false; - foreach ($src->e as $e) + foreach ($src->e as $e) { if ($e->dst === $dst && ($next_cap === null || $e->cap === $next_cap) && ($next_cost === null || $e->cost === $next_cost)) { @@ -879,8 +961,10 @@ function parse_dimacs($str) { $found = true; break; } - if (!$found) + } + if (!$found) { error_log("MinCostMaxFlow::parse_dimacs: line " . ($lineno + 1) . ": no such edge"); + } $next_cap = $next_cost = null; } else if (preg_match('/\As (\d+)\s*\z/', $line, $m) && $this->source->excess === 0) { diff --git a/lib/scoreinfo.php b/lib/scoreinfo.php index daf505eb8..53cb758cd 100644 --- a/lib/scoreinfo.php +++ b/lib/scoreinfo.php @@ -24,25 +24,28 @@ class ScoreInfo { function __construct($data = null, $positive = false) { $this->_positive = $positive; if (is_array($data)) { - foreach ($data as $key => $x) + foreach ($data as $key => $x) { $this->add($x, $key); + } } else if (is_string($data) && $data !== "") { - foreach (preg_split('/[\s,]+/', $data) as $x) + foreach (preg_split('/[\s,]+/', $data) as $x) { if (is_numeric($x)) $this->add(+$x); + } } } static function mean_of($data, $positive = false) { $n = $sum = 0; if (is_array($data)) { - foreach ($data as $x) + foreach ($data as $x) { if ($x !== null && (!$positive || $x > 0)) { ++$n; $sum += +$x; } + } } else if (is_string($data) && $data !== "") { - foreach (preg_split('/[\s,]+/', $data) as $x) + foreach (preg_split('/[\s,]+/', $data) as $x) { if ($x !== "" && is_numeric($x)) { $x = +$x; if (!$positive || $x > 0) { @@ -50,20 +53,24 @@ static function mean_of($data, $positive = false) { $sum += +$x; } } + } } return $n ? $sum / $n : null; } function add($x, $key = null) { - if (is_bool($x)) + if (is_bool($x)) { $x = +$x; + } if ($x !== null && (!$this->_positive || $x > 0)) { - if ($this->_keyed && $key === null) + if ($this->_keyed && $key === null) { $this->_keyed = false; - if ($this->_keyed) + } + if ($this->_keyed) { $this->_scores[$key] = $x; - else + } else { $this->_scores[] = $x; + } $this->_sum += $x; $this->_sumsq += $x * $x; ++$this->_n; @@ -102,10 +109,12 @@ function stddev_p() { function counts($max = 0) { $counts = $max ? array_fill(0, $max, 0) : array(); foreach ($this->_scores as $i) { - while ($i > count($counts)) + while ($i > count($counts)) { $counts[] = 0; - if ($i > 0) + } + if ($i > 0) { ++$counts[$i - 1]; + } } return $counts; } @@ -120,12 +129,13 @@ private function sort() { function median() { $this->sort(); $a = $this->_keyed ? array_values($this->_scores) : $this->_scores; - if ($this->_n % 2) + if ($this->_n % 2) { return $a[($this->_n - 1) >> 1]; - else if ($this->_n) + } else if ($this->_n) { return ($a[($this->_n - 2) >> 1] + $a[$this->_n >> 1]) / 2; - else + } else { return 0; + } } function max() { @@ -137,18 +147,19 @@ function min() { } function statistic($stat) { - if ($stat == self::COUNT) + if ($stat == self::COUNT) { return $this->_n; - else if ($stat == self::MEAN) + } else if ($stat == self::MEAN) { return $this->mean(); - else if ($stat == self::MEDIAN) + } else if ($stat == self::MEDIAN) { return $this->median(); - else if ($stat == self::SUM) + } else if ($stat == self::SUM) { return $this->_sum; - else if ($stat == self::VARIANCE_P) + } else if ($stat == self::VARIANCE_P) { return $this->variance_p(); - else if ($stat == self::STDDEV_P) + } else if ($stat == self::STDDEV_P) { return $this->stddev_p(); + } } function sort_data($sorter, $key = null) { diff --git a/lib/tagger.php b/lib/tagger.php index 6728d45f5..ff4a196de 100644 --- a/lib/tagger.php +++ b/lib/tagger.php @@ -232,10 +232,11 @@ function __construct(Conf $conf) { $basic_colors = "red&|orange&|yellow&|green&|blue&|purple&|violet=purple|gray&|grey=gray|white&|bold|italic|underline|strikethrough|big|small|dim"; if (($o = $conf->opt("tagBasicColors"))) { - if (str_starts_with($o, "|")) + if (str_starts_with($o, "|")) { $basic_colors .= $o; - else + } else { $basic_colors = $o; + } } preg_match_all('/([a-z@_.][-a-z0-9!@_:.\/]*)(\&?)(?:=([a-z@_.][-a-z0-9!@_:.\/]*))?/', strtolower($basic_colors), $ms, PREG_SET_ORDER); foreach ($ms as $m) { @@ -321,8 +322,9 @@ function add($tag) { $t = $this->storage[$ltag] ?? false; if (!$t) { $t = new TagMapItem($tag, $this); - if (!TagInfo::basic_check($ltag)) + if (!TagInfo::basic_check($ltag)) { return $t; + } $this->storage[$ltag] = $t; $this->sorted = false; if ($ltag[0] === ":" && ($e = $this->check_emoji_code($ltag))) { @@ -337,9 +339,11 @@ function add($tag) { ++$this->pattern_version; } } - if ($this->has_pattern && !$t->pattern - && $t->pattern_version < $this->pattern_version) + if ($this->has_pattern + && !$t->pattern + && $t->pattern_version < $this->pattern_version) { $t = $this->update_patterns($tag, $ltag, $t); + } return $t; } private function sort_storage() { @@ -352,8 +356,9 @@ function getIterator() { } function filter($property) { $k = "has_{$property}"; - if (!$this->$k) + if (!$this->$k) { return []; + } $this->sorted || $this->sort_storage(); return array_filter($this->storage, function ($t) use ($property) { return $t->$property; }); } @@ -371,10 +376,11 @@ function check_property($tag, $property) { function is_chair($tag) { - if ($tag[0] === "~") + if ($tag[0] === "~") { return $tag[1] === "~"; - else + } else { return !!$this->check_property($tag, "chair"); + } } function is_readonly($tag) { return !!$this->check_property($tag, "readonly"); @@ -399,8 +405,9 @@ function is_approval($tag) { } function votish_base($tag) { if (!$this->has_votish - || ($twiddle = strpos($tag, "~")) === false) + || ($twiddle = strpos($tag, "~")) === false) { return false; + } $tbase = substr(TagInfo::base($tag), $twiddle + 1); $t = $this->check($tbase); return $t && $t->votish ? $tbase : false; @@ -538,9 +545,10 @@ function color_classes($tags, $no_pattern_fill = false) { function canonical_colors() { $colors = []; - foreach ($this->canonical_style_lmap as $ltag => $canon_ltag) + foreach ($this->canonical_style_lmap as $ltag => $canon_ltag) { if ($ltag === $canon_ltag) $colors[] = $ltag; + } return $colors; } @@ -562,8 +570,9 @@ function canonical_badges() { function emoji_regex() { if (!$this->badge_re) { $re = "{(?:\\A| )(?:\\d*~|~~|)(:\\S+:"; - foreach ($this->filter("emoji") as $t) + foreach ($this->filter("emoji") as $t) { $re .= "|" . $t->tag_regex(); + } $this->emoji_re = $re . ")(?:#[\\d.]+)?(?=\\z| )}i"; } return $this->emoji_re; @@ -872,7 +881,7 @@ static function unpack($tag) { } static function split($taglist) { - preg_match_all(',\S+,', $taglist, $m); + preg_match_all('/\S+/', $taglist, $m); return $m[0]; } diff --git a/lib/xlsx.php b/lib/xlsx.php index a66e6f9c3..169a4edda 100644 --- a/lib/xlsx.php +++ b/lib/xlsx.php @@ -35,9 +35,9 @@ private function row_data($row, $data, $style) { foreach ($data as $x) { if ($x !== null && $x !== "") { $t .= "sst[$x])) { $this->sst[$x] = $this->nsst; ++$this->nsst; diff --git a/manualassign.php b/manualassign.php index 47edd7dbb..b3147de92 100644 --- a/manualassign.php +++ b/manualassign.php @@ -4,8 +4,9 @@ require_once("src/initweb.php"); require_once("src/papersearch.php"); -if (!$Me->is_manager()) +if (!$Me->is_manager()) { $Me->escape(); +} $Me->add_overrides(Contact::OVERRIDE_CONFLICT); // request cleaning @@ -15,8 +16,9 @@ $Qreq->t = key($tOpt); } -if (!$Qreq->q || trim($Qreq->q) == "(All)") +if (!$Qreq->q || trim($Qreq->q) == "(All)") { $Qreq->q = ""; +} $Qreq->allow_a("p", "pap"); if (!$Qreq->p && $Qreq->pap) { diff --git a/offline.php b/offline.php index f436d5cab..30a537a1d 100644 --- a/offline.php +++ b/offline.php @@ -100,28 +100,32 @@ function setTagIndexes($qreq) { $csvp = new CsvParser("", CsvParser::TYPE_GUESS); foreach (explode("\n", rtrim(cleannl($text))) as $l) { if (substr($l, 0, 4) == "Tag:" || substr($l, 0, 6) == "# Tag:") { - if (!$tag) + if (!$tag) { $tag = $tagger->check(trim(substr($l, ($l[0] == "#" ? 6 : 4))), Tagger::NOVALUE); + } } else if (trim($l) !== "" && $l[0] !== "#") { $csvp->unshift($l); $line = $csvp->next_array(); if ($line && check_tag_index_line($line)) { - if (isset($settings[$line[1]])) + if (isset($settings[$line[1]])) { $errors[$lineno] = "Paper #$line[1] already given on line " . $linenos[$line[1]]; - if ($line[0] === "X" || $line[0] === "x") + } + if ($line[0] === "X" || $line[0] === "x") { $settings[$line[1]] = null; - else if ($line[0] === "" || $line[0] === ">") + } else if ($line[0] === "" || $line[0] === ">") { $settings[$line[1]] = $curIndex = $curIndex + 1; - else if (is_numeric($line[0])) + } else if (is_numeric($line[0])) { $settings[$line[1]] = $curIndex = intval($line[0]); - else if ($line[0] === "=") + } else if ($line[0] === "=") { $settings[$line[1]] = $curIndex; - else + } else { $settings[$line[1]] = $curIndex = $curIndex + strlen($line[0]); - $titles[$line[1]] = trim(get($line, 2, "")); + } + $titles[$line[1]] = trim($line[2] ?? ""); $linenos[$line[1]] = $lineno; - } else + } else { $errors[$lineno] = "Syntax error"; + } } ++$lineno; } diff --git a/profile.php b/profile.php index 9b2b17607..4d771d82f 100644 --- a/profile.php +++ b/profile.php @@ -423,8 +423,9 @@ function parseBulkFile($text, $filename) { $Conf->msg("Created an account for " . Text::user_html_nolink($saved_user) . ". A password has been emailed to that address. You may now create another account.", "xconfirm"); } else { $Conf->msg("Profile updated.", "xconfirm"); - if ($Acct->contactId != $Me->contactId) + if ($Acct->contactId != $Me->contactId) { $Qreq->u = $Acct->email; + } } if (isset($Qreq->redirect)) { go(hoturl("index")); diff --git a/review.php b/review.php index d36925e49..eafd5d0dd 100644 --- a/review.php +++ b/review.php @@ -26,26 +26,26 @@ function errorMsgExit($msg) { // collect paper ID -function loadRows() { +function review_load() { global $Conf, $Me, $Qreq, $prow, $paperTable; if (!($prow = PaperTable::fetch_paper_request($Qreq, $Me))) { - errorMsgExit(whyNotText($Qreq->annex("paper_whynot") + ["listViewable" => true])); + review_error(whyNotText($Qreq->annex("paper_whynot") + ["listViewable" => true])); } $paperTable = new PaperTable($prow, $Qreq); $paperTable->resolveReview(true); } - -loadRows(); +review_load(); // general error messages if ($Qreq->post && $Qreq->post_empty()) { $Conf->post_missing_msg(); } else if ($Qreq->post && $Qreq->default) { - if ($Qreq->has_file("uploadedFile")) + if ($Qreq->has_file("uploadedFile")) { $Qreq->uploadForm = 1; - else + } else { $Qreq->update = 1; + } } else if ($Qreq->submitreview) { $Qreq->update = $Qreq->ready = 1; } else if ($Qreq->savedraft) { @@ -141,8 +141,9 @@ function loadRows() { $tfx->check_and_save($Me, $prow, $paperTable->editrrow); } } - if (($my_rrow = $prow->fresh_review_of_user($Me))) + if (($my_rrow = $prow->fresh_review_of_user($Me))) { $Qreq->r = $my_rrow->reviewId; + } $Conf->self_redirect($Qreq); // normally does not return } @@ -151,22 +152,26 @@ function loadRows() { if (isset($Qreq->deletereview) && $Qreq->post_ok() && $Me->can_administer($prow)) { - if (!$paperTable->editrrow) + if (!$paperTable->editrrow) { Conf::msg_error("No review to delete."); - else { + } else { $result = $Conf->qe("delete from PaperReview where paperId=? and reviewId=?", $prow->paperId, $paperTable->editrrow->reviewId); if ($result) { $Me->log_activity_for($paperTable->editrrow->contactId, "Review {$paperTable->editrrow->reviewId} deleted", $prow); $Conf->confirmMsg("Deleted review."); $Conf->qe("delete from ReviewRating where paperId=? and reviewId=?", $prow->paperId, $paperTable->editrrow->reviewId); - if ($paperTable->editrrow->reviewToken != 0) + if ($paperTable->editrrow->reviewToken != 0) { $Conf->update_rev_tokens_setting(-1); - if ($paperTable->editrrow->reviewType == REVIEW_META) + } + if ($paperTable->editrrow->reviewType == REVIEW_META) { $Conf->update_metareviews_setting(-1); + } // perhaps a delegatee needs to redelegate - if ($paperTable->editrrow->reviewType < REVIEW_SECONDARY && $paperTable->editrrow->requestedBy > 0) + if ($paperTable->editrrow->reviewType < REVIEW_SECONDARY + && $paperTable->editrrow->requestedBy > 0) { $Me->update_review_delegation($paperTable->editrrow->paperId, $paperTable->editrrow->requestedBy, -1); + } unset($Qreq->r, $Qreq->reviewId); $Qreq->paperId = $Qreq->p = $paperTable->editrrow->paperId; @@ -186,13 +191,15 @@ function downloadForm($qreq) { && $prow->review_type($Me) > 0; $text = $rf->textFormHeader(false) . $rf->textForm($prow, $rrow, $Me, $use_request ? $qreq : null); $filename = "review-{$prow->paperId}"; - if ($rrow && $rrow->reviewOrdinal) + if ($rrow && $rrow->reviewOrdinal) { $filename .= unparseReviewOrdinal($rrow->reviewOrdinal); + } downloadText($text, $filename, false); } -if (isset($Qreq->downloadForm)) +if (isset($Qreq->downloadForm)) { downloadForm($Qreq); +} function download_all_text_reviews() { @@ -227,10 +234,11 @@ function download_one_text_review(ReviewInfo $rrow) { } if (isset($Qreq->text)) { - if ($paperTable->rrow) + if ($paperTable->rrow) { download_one_text_review($paperTable->rrow); - else + } else { download_all_text_reviews(); + } } @@ -308,8 +316,9 @@ function download_one_text_review(ReviewInfo $rrow) { // mode $paperTable->fixReviewMode(); -if ($paperTable->mode == "edit") +if ($paperTable->mode == "edit") { go(hoturl("paper", ["p" => $prow->paperId])); +} // paper table diff --git a/src/assigners/a_decision.php b/src/assigners/a_decision.php index 611c02006..cca08af83 100644 --- a/src/assigners/a_decision.php +++ b/src/assigners/a_decision.php @@ -34,12 +34,13 @@ function apply(PaperInfo $prow, Contact $contact, $req, AssignmentState $state) } else { $dec = $matchexpr; } - if (count($dec) === 1) + if (count($dec) === 1) { $dec = $dec[0]; - else if (empty($dec)) + } else if (empty($dec)) { return "No decisions match “" . htmlspecialchars($req["decision"]) . "”."; - else + } else { return "More than one decision matches “" . htmlspecialchars($req["decision"]) . "”."; + } } else { $removepred = function ($item) use ($matchexpr) { return CountMatcher::compare_using($item["_decision"], $matchexpr); @@ -57,11 +58,13 @@ function apply(PaperInfo $prow, Contact $contact, $req, AssignmentState $state) Status_AssignmentParser::load_status_state($state); $sm = $state->remove(["type" => "status", "pid" => $prow->paperId]); $sres = $sm[0]; - if ($sres["_submitted"] === 0) + if ($sres["_submitted"] === 0) { $sres["_submitted"] = ($sres["_withdrawn"] > 0 ? -$Now : $Now); + } $state->add($sres); - if ($sres["_submitted"] > 0) + if ($sres["_submitted"] > 0) { $decyes = 1; + } } $state->add(["type" => "decision", "pid" => $prow->paperId, "_decision" => +$dec, "_decyes" => $decyes]); diff --git a/src/capability.php b/src/capability.php index acb7afec1..f31d3e333 100644 --- a/src/capability.php +++ b/src/capability.php @@ -19,9 +19,9 @@ private function prefix() { function create(Contact $user, $capabilityType, $options = []) { $contactId = $this->cdb ? $user->contactdb_user()->contactDbId : $user->contactId; - $paperId = get($options, "paperId", 0); - $timeExpires = get($options, "timeExpires", time() + 259200); - $data = get($options, "data"); + $paperId = $options["paperId"] ?? 0; + $timeExpires = $options["timeExpires"] ?? time() + 259200; + $data = $options["data"] ?? null; $ok = false; for ($tries = 0; !$ok && $tries < 4; ++$tries) { @@ -110,7 +110,7 @@ static function apply_hoturl_capability($name, $isadd) { if (Conf::$hoturl_defaults === null) { Conf::$hoturl_defaults = []; } - $cap = urldecode(get(Conf::$hoturl_defaults, "cap", "")); + $cap = urldecode(Conf::$hoturl_defaults["cap"] ?? ""); $a = array_diff(explode(" ", $cap), [$name, ""]); if ($isadd) { $a[] = $name; diff --git a/src/commentinfo.php b/src/commentinfo.php index eee0e1a8c..336080838 100644 --- a/src/commentinfo.php +++ b/src/commentinfo.php @@ -527,12 +527,14 @@ function save($req, Contact $acting_contact) { } $response_name = $this->conf->resp_round_name($this->commentRound); } else if ($contact->act_author_view($this->prow)) { - if ($req_visibility === null) + if ($req_visibility === null) { $req_visibility = COMMENTTYPE_AUTHOR; + } $ctype = $req_visibility | COMMENTTYPE_BYAUTHOR; } else { - if ($req_visibility === null) + if ($req_visibility === null) { $req_visibility = COMMENTTYPE_REVIEWER; + } $ctype = $req_visibility; } if ($is_response @@ -553,7 +555,7 @@ function save($req, Contact $acting_contact) { $ctags .= " {$response_name}response#0"; } } else if (($req->tags ?? null) - && preg_match_all(',\S+,', $req->tags, $m) + && preg_match_all('/\S+/', $req->tags, $m) && !$contact->act_author_view($this->prow)) { $tagger = new Tagger($contact); $ts = []; diff --git a/src/conference.php b/src/conference.php index 57b1a9a9b..951c3fe7a 100644 --- a/src/conference.php +++ b/src/conference.php @@ -242,7 +242,7 @@ function load_settings() { $this->opt_override = []; $result = $this->q_raw("select name, value, data from Settings"); - while ($result && ($row = $result->fetch_row())) { + while (($row = $result->fetch_row())) { $this->settings[$row[0]] = (int) $row[1]; if ($row[2] !== null) { $this->settingTexts[$row[0]] = $row[2]; @@ -406,9 +406,10 @@ private function crosscheck_settings() { private function crosscheck_round_settings() { $this->rounds = [""]; if (isset($this->settingTexts["tag_rounds"])) { - foreach (explode(" ", $this->settingTexts["tag_rounds"]) as $r) + foreach (explode(" ", $this->settingTexts["tag_rounds"]) as $r) { if ($r != "") $this->rounds[] = $r; + } } $this->_round_settings = null; if (isset($this->settingTexts["round_settings"])) { @@ -2469,13 +2470,15 @@ function check_document_inactive_invariants() { function update_schema_version($n) { - if (!$n) + if (!$n) { $n = $this->fetch_ivalue("select value from Settings where name='allowPaperOption'"); + } if ($n && $this->ql("update Settings set value=? where name='allowPaperOption'", $n)) { $this->sversion = $this->settings["allowPaperOption"] = $n; return true; - } else + } else { return false; + } } function invalidate_caches($caches = null) { @@ -3265,10 +3268,6 @@ function paper_result($options, Contact $user = null) { if (count($paperset) > 1) { $paperset = array(call_user_func_array("array_intersect", $paperset)); } - $papersel = ""; - if (!empty($paperset)) { - $papersel = "paperId" . sql_in_numeric_set($paperset[0]) . " and "; - } // prepare query: basic tables // * Every table in `$joins` can have at most one row per paperId, diff --git a/src/contact.php b/src/contact.php index fd79546b0..2553dd1ff 100644 --- a/src/contact.php +++ b/src/contact.php @@ -159,13 +159,16 @@ private function merge($user) { if (isset($user->roles) || isset($user->isPC) || isset($user->isAssistant) || isset($user->isChair)) { - $roles = (int) get($user, "roles"); - if (get($user, "isPC")) + $roles = (int) ($user->roles ?? 0); + if ($user->isPC ?? null) { $roles |= self::ROLE_PC; - if (get($user, "isAssistant")) + } + if ($user->isAssistant ?? null) { $roles |= self::ROLE_ADMIN; - if (get($user, "isChair")) + } + if ($user->isChair ?? null) { $roles |= self::ROLE_CHAIR; + } $this->assign_roles($roles); } if (property_exists($user, "contactTags")) { @@ -525,8 +528,9 @@ function overrides() { } function set_overrides($overrides) { $old_overrides = $this->_overrides; - if (($overrides & self::OVERRIDE_CONFLICT) && !$this->is_manager()) + if (($overrides & self::OVERRIDE_CONFLICT) && !$this->is_manager()) { $overrides &= ~self::OVERRIDE_CONFLICT; + } $this->_overrides = $overrides; return $old_overrides; } @@ -1092,12 +1096,14 @@ function escape($qreq = null) { function save_assign_field($k, $v, Contact_Update $cu) { if ($k === "contactTags") { - if ($v !== null && trim($v) === "") + if ($v !== null && trim($v) === "") { $v = null; + } } else if ($k !== "collaborators" && $k !== "defaultWatch") { $v = simplify_whitespace($v); - if ($k === "birthday" && !$v) + if ($k === "birthday" && !$v) { $v = null; + } } // change contactdb if (isset(self::$cdb_fields[$k]) @@ -1197,10 +1203,11 @@ function save_roles($new_roles, $actor) { // log role change foreach ([self::ROLE_PC => "pc", self::ROLE_ADMIN => "sysadmin", self::ROLE_CHAIR => "chair"] as $role => $type) { - if (($new_roles & $role) && !($old_roles & $role)) + if (($new_roles & $role) && !($old_roles & $role)) { $this->conf->log_for($actor ? : $this, $this, "Added as $type"); - else if (!($new_roles & $role) && ($old_roles & $role)) + } else if (!($new_roles & $role) && ($old_roles & $role)) { $this->conf->log_for($actor ? : $this, $this, "Removed as $type"); + } } // save the roles bits if ($old_roles != $new_roles) { @@ -1213,10 +1220,12 @@ function save_roles($new_roles, $actor) { private function _make_create_updater($reg, $is_cdb) { $cj = []; if ($this->firstName === "" && $this->lastName === "") { - if (get_s($reg, "firstName") !== "") + if (($reg->firstName ?? "") !== "") { $cj["firstName"] = (string) $reg->firstName; - if (get_s($reg, "lastName") !== "") + } + if (($reg->lastName ?? "") !== "") { $cj["lastName"] = (string) $reg->lastName; + } } foreach (["affiliation", "country", "gender", "birthday", "preferredEmail", "phone"] as $k) { @@ -4197,7 +4206,7 @@ function hide_reviewer_identity_pids() { function paper_status_info(PaperInfo $row) { if ($row->timeWithdrawn > 0) { - return array("pstat_with", "Withdrawn"); + return ["pstat_with", "Withdrawn"]; } else if ($row->outcome && $this->can_view_decision($row)) { $data = get(self::$status_info_cache, $row->outcome); if (!$data) { @@ -4212,15 +4221,15 @@ function paper_status_info(PaperInfo $row) { } else $decname = "Unknown decision #" . $row->outcome; - $data = self::$status_info_cache[$row->outcome] = array($decclass, $decname); + $data = self::$status_info_cache[$row->outcome] = [$decclass, $decname]; } return $data; } else if ($row->timeSubmitted <= 0 && $row->paperStorageId == 1) { - return array("pstat_noup", "No submission"); + return ["pstat_noup", "No submission"]; } else if ($row->timeSubmitted > 0) { - return array("pstat_sub", "Submitted"); + return ["pstat_sub", "Submitted"]; } else { - return array("pstat_prog", "Not ready"); + return ["pstat_prog", "Not ready"]; } } @@ -4228,15 +4237,17 @@ function paper_status_info(PaperInfo $row) { private function unassigned_review_token() { while (true) { $token = mt_rand(1, 2000000000); - if (!$this->conf->fetch_ivalue("select reviewId from PaperReview where reviewToken=$token")) + if (!$this->conf->fetch_ivalue("select reviewId from PaperReview where reviewToken=$token")) { return ", reviewToken=$token"; + } } } private function assign_review_explanation($type, $round) { $t = ReviewForm::$revtype_names_lc[$type] . " review"; - if ($round && ($rname = $this->conf->round_name($round))) + if ($round && ($rname = $this->conf->round_name($round))) { $t .= " (round $rname)"; + } return $t; } @@ -4310,7 +4321,7 @@ function assign_review($pid, $reviewer_cid, $type, $extra = array()) { // on new review, update PaperReviewRefused, ReviewRequest, delegation if ($type && !$oldtype) { $this->conf->ql("delete from PaperReviewRefused where paperId=$pid and contactId=$reviewer_cid"); - if (($req_email = get($extra, "requested_email"))) { + if (($req_email = $extra["requested_email"] ?? null)) { $this->conf->qe("delete from ReviewRequest where paperId=$pid and email=?", $req_email); } if ($type < REVIEW_SECONDARY) { @@ -4325,7 +4336,7 @@ function assign_review($pid, $reviewer_cid, $type, $extra = array()) { $this->update_review_delegation($pid, $rrow->requestedBy, -1); } // Mark rev_tokens setting for future update by update_rev_tokens_setting - if (get($rrow, "reviewToken")) { + if ($rrow->reviewToken ?? null) { $this->conf->settings["rev_tokens"] = -1; } } else { @@ -4339,7 +4350,7 @@ function assign_review($pid, $reviewer_cid, $type, $extra = array()) { } self::update_rights(); - if (!get($extra, "no_autosearch")) { + if (!($extra["no_autosearch"] ?? false)) { $this->conf->update_autosearch_tags($pid); } return $reviewId; @@ -4372,7 +4383,7 @@ function unsubmit_review_row($rrow, $extra = null) { if ($result->affected_rows && $rrow->reviewType < REVIEW_SECONDARY) { $this->update_review_delegation($rrow->paperId, $rrow->requestedBy, -1); } - if (!$extra || !get($extra, "no_autosearch")) { + if (!$extra || !($extra["no_autosearch"] ?? false)) { $this->conf->update_autosearch_tags($rrow->paperId); } return $result; diff --git a/src/contactlist.php b/src/contactlist.php index 042d6fb53..c8b204564 100644 --- a/src/contactlist.php +++ b/src/contactlist.php @@ -548,8 +548,8 @@ function _rows($queryOptions) { if (isset($queryOptions["shepherds"])) { $pq .= ",\n (select count(paperId) from Paper where shepherdContactId=u.contactId" . $this->_pid_restriction() . ") numShepherds"; } - if (isset($queryOptions['scores'])) { - foreach ($queryOptions['scores'] as $score) { + if (isset($queryOptions["scores"])) { + foreach ($queryOptions["scores"] as $score) { $rf[] = "group_concat(if(reviewSubmitted>0 or timeApprovalRequested<0,$score,null)) $score"; $pq .= ", $score"; } diff --git a/src/documentinfo.php b/src/documentinfo.php index 05ed32aaf..24038e797 100644 --- a/src/documentinfo.php +++ b/src/documentinfo.php @@ -189,50 +189,59 @@ function content_available() { } function ensure_content() { - if ($this->content_available()) + if ($this->content_available()) { return true; + } // 1. check docstore - if ($this->load_docstore()) + if ($this->load_docstore()) { return true; + } // 2. check db $dbNoPapers = $this->conf->opt("dbNoPapers"); - if (!$dbNoPapers && $this->load_database()) + if (!$dbNoPapers && $this->load_database()) { return true; + } // 3. check S3 - if ($this->load_s3()) + if ($this->load_s3()) { return true; + } // 4. check db as last resort - if ($dbNoPapers && $this->load_database()) + if ($dbNoPapers && $this->load_database()) { return true; + } return $this->add_error_html("Cannot load document."); } function ensure_size() { if ($this->size == 0 && $this->paperStorageId != 1) { - if (!$this->ensure_content()) + if (!$this->ensure_content()) { return false; - else if ($this->content !== null) + } else if ($this->content !== null) { $this->size = strlen($this->content); - else if ($this->content_file !== null) + } else if ($this->content_file !== null) { $this->size = (int) filesize($this->content_file); - else if ($this->filestore !== null) + } else if ($this->filestore !== null) { $this->size = (int) filesize($this->filestore); + } } return $this->size != 0 || $this->paperStorageId == 1; } function load_database() { - if ($this->paperStorageId <= 1) + if ($this->paperStorageId <= 1) { return false; + } $row = $this->conf->fetch_first_row("select paper, compression from PaperStorage where paperId=? and paperStorageId=?", $this->paperId, $this->paperStorageId); - if ($row === null) + if ($row === null) { $row = $this->conf->fetch_first_row("select paper, compression from PaperStorage where paperStorageId=?", $this->paperStorageId); + } if ($row !== null && $row[0] !== null) { $this->content = $row[1] == 1 ? gzinflate($row[0]) : $row[0]; $this->size = strlen($this->content); return true; + } else { + return false; } - return false; } function load_docstore() { @@ -240,8 +249,9 @@ function load_docstore() { $this->filestore = $dspath; $this->size = 0; return true; + } else { + return false; } - return false; } function store_skeleton() { @@ -574,14 +584,16 @@ function content_text_signature() { $t = substr($s, 0, 8); if (!is_valid_utf8($s)) { $t = UnicodeHelper::utf8_prefix(UnicodeHelper::utf8_truncate_invalid($s), 8); - if (strlen($t) < 7) + if (strlen($t) < 7) { $t = join("", array_map(function ($ch) { $c = ord($ch); - if ($c >= 0x20 && $c <= 0x7E) + if ($c >= 0x20 && $c <= 0x7E) { return $ch; - else + } else { return sprintf("\\x%02X", $c); + } }, str_split(substr($s, 0, 8)))); + } } return "starts with “{$t}”"; } diff --git a/src/formatspec.php b/src/formatspec.php index 4ab6b0be7..5b108edb7 100644 --- a/src/formatspec.php +++ b/src/formatspec.php @@ -22,20 +22,21 @@ function __construct(/* ... */) { } function merge($x, $timestamp = 0) { - if (is_string($x) && substr($x, 0, 1) === "{") + if (is_string($x) && substr($x, 0, 1) === "{") { $x = json_decode($x); + } if ($x && is_string($x)) { if (($gt = strpos($x, ">")) !== false) { $x = substr($x, 0, $gt); } $x = explode(";", $x); - $this->merge1("papersize", get($x, 0, "")); - $this->merge1("pagelimit", get($x, 1, "")); - $this->merge1("columns", get($x, 2)); - $this->merge1("textblock", get($x, 3)); - $this->merge1("bodyfontsize", get($x, 4)); - $this->merge1("bodylineheight", get($x, 5)); - $this->merge1("unlimitedref", get($x, 6)); + $this->merge1("papersize", $x[0] ?? ""); + $this->merge1("pagelimit", $x[1] ?? ""); + $this->merge1("columns", $x[2] ?? null); + $this->merge1("textblock", $x[3] ?? null); + $this->merge1("bodyfontsize", $x[4] ?? null); + $this->merge1("bodylineheight", $x[5] ?? null); + $this->merge1("unlimitedref", $x[6] ?? null); } else if ($x && (is_object($x) || is_array($x))) { foreach ($x as $k => $v) { $this->merge1($k, $v); diff --git a/src/formulas/f_author.php b/src/formulas/f_author.php index 00a158957..ceb9f4ec2 100644 --- a/src/formulas/f_author.php +++ b/src/formulas/f_author.php @@ -9,7 +9,8 @@ class Author_Fexpr extends Fexpr { function __construct(FormulaCall $ff, Formula $formula) { if ($ff->modifier === "none") { $this->matchtype = $ff->modifier; - } else if (is_array($ff->modifier) && $ff->modifier[0] == $formula->user->contactId) { + } else if (is_array($ff->modifier) + && $ff->modifier[0] == $formula->user->contactId) { $this->matchtype = $formula->user->contactId; } else if (is_array($ff->modifier) || is_object($ff->modifier)) { self::$matchers[] = $ff->modifier; diff --git a/src/helpers.php b/src/helpers.php index a4cbdc51e..3e20b6fc3 100644 --- a/src/helpers.php +++ b/src/helpers.php @@ -665,8 +665,9 @@ function unparseReviewOrdinal($ord) { $t = ""; while (true) { $t = chr((($ord - 1) % 26) + 65) . $t; - if ($ord <= 26) + if ($ord <= 26) { return $t; + } $ord = intval(($ord - 1) / 26); } } diff --git a/src/init.php b/src/init.php index 970a61feb..23c2cb85c 100644 --- a/src/init.php +++ b/src/init.php @@ -63,10 +63,12 @@ function set_path_variables() { global $ConfSitePATH; if (!isset($ConfSitePATH)) { $ConfSitePATH = substr(__FILE__, 0, strrpos(__FILE__, "/")); - while ($ConfSitePATH !== "" && !file_exists("$ConfSitePATH/src/init.php")) + while ($ConfSitePATH !== "" && !file_exists("$ConfSitePATH/src/init.php")) { $ConfSitePATH = substr($ConfSitePATH, 0, strrpos($ConfSitePATH, "/")); - if ($ConfSitePATH === "") + } + if ($ConfSitePATH === "") { $ConfSitePATH = "/var/www/html"; + } } require_once("$ConfSitePATH/lib/navigation.php"); } diff --git a/src/meetingtracker.php b/src/meetingtracker.php index 43ed81803..d309680a5 100644 --- a/src/meetingtracker.php +++ b/src/meetingtracker.php @@ -6,9 +6,10 @@ class MeetingTracker { static function lookup(Conf $conf) { global $Now; $tracker = $conf->setting_json("tracker"); - if ($tracker && (!$tracker->trackerid || $tracker->update_at >= $Now - 150)) + if ($tracker + && (!$tracker->trackerid || $tracker->update_at >= $Now - 150)) { return $tracker; - else { + } else { $when = $tracker ? $tracker->update_at + 0.1 : 0; return (object) ["trackerid" => false, "position_at" => $when, "update_at" => $when]; } @@ -18,9 +19,10 @@ static function expand($tracker) { global $Now; if (isset($tracker->ts)) { $ts = []; - foreach ($tracker->ts as $tr) + foreach ($tracker->ts as $tr) { if ($tr->update_at >= $Now - 150) $ts[] = $tr; + } return $ts; } else if ($tracker->trackerid) { return [$tracker]; @@ -67,8 +69,9 @@ static function contact_tracker_comet(Conf $conf, $pids = null) { $comet_dir = $conf->opt("trackerCometUpdateDirectory"); $comet_url = $conf->opt("trackerCometSite"); - if (!$comet_dir && !$comet_url) + if (!$comet_dir && !$comet_url) { return; + } // calculate status $url = Navigation::base_absolute(); @@ -76,9 +79,9 @@ static function contact_tracker_comet(Conf $conf, $pids = null) { // first drop notification json in trackerCometUpdateDirectory if ($comet_dir) { - $j = array("ok" => true, "conference" => $url, - "tracker_status" => self::tracker_status($tracker), - "tracker_status_at" => $tracker->position_at); + $j = ["ok" => true, "conference" => $url, + "tracker_status" => self::tracker_status($tracker), + "tracker_status_at" => $tracker->position_at]; if ($pids) { $j["pulse"] = true; } @@ -207,7 +210,7 @@ static private function check_tracker_admin_perm(Contact $user, $admin_perm) { } static private function compute_default_visibility(Contact $user, $admin_perm) { - foreach ($user->conf->track_tags() as $tag) + foreach ($user->conf->track_tags() as $tag) { if (in_array($user->conf->track_permission($tag, Track::ADMIN), $admin_perm)) { foreach ([Track::VIEW, Track::VIEWREV, Track::ASSREV] as $p) { if (($perm = $user->conf->track_permission($tag, $p)) @@ -216,6 +219,7 @@ static private function compute_default_visibility(Contact $user, $admin_perm) { return $perm; } } + } return ""; } @@ -325,14 +329,14 @@ static function track_api(Contact $user, $qreq) { // check admin perms if (!$user->privChair && $match !== false - && !self::check_tracker_admin_perm($user, get($trs[$match], "admin_perm"))) { + && !self::check_tracker_admin_perm($user, $trs[$match]->admin_perm ?? null)) { json_exit(403, "Permission error: You can’t administer that tracker."); } $admin_perm = null; if ($user->conf->check_track_admin_sensitivity()) { if ($match !== false && $xlist->ids == $trs[$match]->ids) { - $admin_perm = get($trs[$match], "admin_perm"); + $admin_perm = $trs[$match]->admin_perm ?? null; } else { $admin_perm = self::compute_xlist_admin_perm($user->conf, $xlist->ids); if (!$user->privChair @@ -532,31 +536,32 @@ static function trackerconfig_api(Contact $user, $qreq) { } else if (($match = self::tracker_search($trackerid, $trs)) !== false) { $tr = $trs[$match]; if (!isset($qreq["tr{$i}-name"])) { - $name = (string) get($tr, "name"); + $name = $tr->name ?? ""; } if (!isset($qreq["tr{$i}-vis"])) { - $vis = (string) get($tr, "visibility"); + $vis = $tr->visibility ?? ""; } if (!isset($qreq["tr{$i}-logo"])) { - $logo = (string) get($tr, "logo"); + $logo = $tr->logo ?? ""; } - if ($name === (string) get($tr, "name") - && $vis === (string) get($tr, "visibility") - && $logo === (string) get($tr, "logo") + if ($name === ($tr->name ?? "") + && $vis === ($tr->visibility ?? "") + && $logo === ($tr->logo ?? "") && !$stop) { /* do nothing */ } else if (!$user->privChair - && !self::check_tracker_admin_perm($user, get($tr, "admin_perm"))) { + && !self::check_tracker_admin_perm($user, $tr->admin_perm ?? null)) { if ($qreq["tr{$i}-changed"]) { $errf["tr{$i}-name"] = true; $error[] = "You can’t administer that tracker."; } } else { foreach (["name" => $name, "visibility" => $vis, "logo" => $logo] as $k => $v) { - if ($v !== "") + if ($v !== "") { $tr->$k = $v; - else + } else { unset($tr->$k); + } } if ($stop) { @@ -574,11 +579,13 @@ static function trackerconfig_api(Contact $user, $qreq) { } if (empty($errf)) { - if ($changed) + if ($changed) { self::tracker_save($user->conf, $trs, $tracker, $position_at); + } $j = (object) ["ok" => true]; - if ($new_trackerid !== false) + if ($new_trackerid !== false) { $j->new_trackerid = $new_trackerid; + } self::my_deadlines($j, $user); return $j; } else { @@ -606,7 +613,7 @@ static private function trinfo($tr, Contact $user) { ]; if ($user->privChair || ($user->is_track_manager() - && self::check_tracker_admin_perm($user, get($tr, "admin_perm")))) { + && self::check_tracker_admin_perm($user, $tr->admin_perm ?? null))) { $ti->allow_administer = true; } if ($user->conf->opt("trackerHideConflicts")) { @@ -679,34 +686,41 @@ static private function trinfo_papers($tis, $trs, Contact $user) { && $user->tracker_kiosk_state != 1) { $p->pid = $prow->paperId; $p->title = $prow->title; - if (($format = $prow->title_format())) + if (($format = $prow->title_format())) { $p->format = $format; + } } if ($user->contactId > 0) { - if ($prow->managerContactId == $user->contactId) + if ($prow->managerContactId == $user->contactId) { $p->is_manager = true; - if ($prow->has_reviewer($user)) + } + if ($prow->has_reviewer($user)) { $p->is_reviewer = true; - if ($prow->conflictType > CONFLICT_MAXUNCONFLICTED) + } + if ($prow->conflictType > CONFLICT_MAXUNCONFLICTED) { $p->is_conflict = true; - if ($prow->leadContactId == $user->contactId) + } + if ($prow->leadContactId == $user->contactId) { $p->is_lead = true; + } } if ($show_pc_conflicts) { $pcc = []; $more = false; foreach (explode(",", (string) $prow->conflictIds) as $cid) { - if (($pc = get($pcm, $cid))) { - if ($pc->include_tracker_conflict($trs[$ti_index])) + if (($pc = $pcm[$cid] ?? null)) { + if ($pc->include_tracker_conflict($trs[$ti_index])) { $pcc[$pc->sort_position] = $pc->contactId; - else + } else { $more = true; + } } } ksort($pcc); $p->pc_conflicts = array_values($pcc); - if ($more) + if ($more) { $p->other_pc_conflicts = $more; + } } } if (isset($ti->papers)) { @@ -726,8 +740,9 @@ static function my_deadlines($dl, Contact $user) { $tis[] = self::trinfo($tr, $user); } } - if (!empty($tis)) + if (!empty($tis)) { self::trinfo_papers($tis, $trs, $user); + } if (count($tis) === 1 && $tis[0]->trackerid === $tracker->trackerid) { @@ -739,8 +754,9 @@ static function my_deadlines($dl, Contact $user) { "ts" => $tis ]; } - if (($perm = $user->conf->track_permission("_", Track::VIEWTRACKER))) + if (($perm = $user->conf->track_permission("_", Track::VIEWTRACKER))) { $dl->tracker->global_visibility = $perm; + } $dl->tracker_status = self::tracker_status($tracker); $dl->now = microtime(true); } diff --git a/src/paperinfo.php b/src/paperinfo.php index 38436742f..ecd106ef0 100644 --- a/src/paperinfo.php +++ b/src/paperinfo.php @@ -130,8 +130,9 @@ static function load_into(PaperInfo $prow, $user) { && ($Me->privChair || $Me->contactId == $prow->managerContactId))) && ($pcm = $conf->pc_members()) && isset($pcm[$cid])) { - foreach ($pcm as $u) + foreach ($pcm as $u) { $prow->_clear_contact_info($u); + } $result = $conf->qe("$q, ContactInfo.contactId from ContactInfo left join PaperConflict on (PaperConflict.paperId=? and PaperConflict.contactId=ContactInfo.contactId) @@ -151,8 +152,9 @@ static function load_into(PaperInfo $prow, $user) { $qv[] = $rev_tokens; } $result = $conf->qe_apply("$q))", $qv); - } else + } else { $result = null; + } } while ($result && ($local = $result->fetch_row())) { $ci = $prow->_get_contact_info($local[4]); @@ -189,8 +191,9 @@ class PaperInfoSet implements ArrayAccess, IteratorAggregate, Countable { private $_need_pid_sort = false; public $loaded_allprefs = 0; function __construct(PaperInfo $prow = null) { - if ($prow) + if ($prow) { $this->add($prow, true); + } } function add(PaperInfo $prow, $copy = false) { $this->prows[] = $prow; @@ -1023,8 +1026,9 @@ function add_tag_info_json($pj, Contact $user) { private function load_topics() { $row_set = $this->_row_set ? : new PaperInfoSet($this); - foreach ($row_set as $prow) + foreach ($row_set as $prow) { $prow->topicIds = null; + } if ($this->conf->has_topics()) { $result = $this->conf->qe("select paperId, group_concat(topicId) from PaperTopic where paperId?a group by paperId", $row_set->paper_ids()); while ($result && ($row = $result->fetch_row())) { @@ -1036,8 +1040,9 @@ private function load_topics() { } function has_topics() { - if (!property_exists($this, "topicIds")) + if (!property_exists($this, "topicIds")) { $this->load_topics(); + } return $this->topicIds !== null && $this->topicIds !== ""; } @@ -1060,8 +1065,9 @@ function topic_list() { function topic_map() { $t = []; foreach ($this->topic_list() as $tid) { - if (empty($t)) + if (empty($t)) { $tset = $this->conf->topic_set(); + } $t[$tid] = $tset[$tid]; } return $t; diff --git a/src/papersearch.php b/src/papersearch.php index 5788b7851..dfd3189f3 100644 --- a/src/papersearch.php +++ b/src/papersearch.php @@ -169,7 +169,7 @@ static function get($name) { self::$list["THEN"] = new SearchOperator("then", false, 2); self::$list["HIGHLIGHT"] = new SearchOperator("highlight", false, 1, ""); } - return get(self::$list, $name); + return self::$list[$name] ?? null; } } @@ -224,10 +224,10 @@ function set_float($k, $v) { $this->float[$k] = $v; } function get_float($k, $defval = null) { - return get($this->float, $k, $defval); + return $this->float[$k] ?? $defval; } function apply_strspan($span) { - $span1 = get($this->float, "strspan"); + $span1 = $this->float["strspan"] ?? null; if ($span && $span1) { $span = [min($span[0], $span1[0]), max($span[1], $span1[1])]; } @@ -360,7 +360,7 @@ function __construct($type) { protected function append($term) { if ($term) { foreach ($term->float as $k => $v) { - $v1 = get($this->float, $k); + $v1 = $this->float[$k] ?? null; if (($k === "sort" || $k === "view" || $k === "tags") && $v1) { array_splice($this->float[$k], count($v1), 0, $v); } else if ($k === "strspan" && $v1) { @@ -380,19 +380,22 @@ protected function finish() { } protected function _flatten_children() { $qvs = array(); - foreach ($this->child ? : array() as $qv) - if ($qv->type === $this->type) + foreach ($this->child ? : array() as $qv) { + if ($qv->type === $this->type) { $qvs = array_merge($qvs, $qv->child); - else + } else { $qvs[] = $qv; + } + } return $qvs; } protected function _finish_combine($newchild, $any) { $qr = null; - if (!$newchild) + if (!$newchild) { $qr = $any ? new True_SearchTerm : new False_SearchTerm; - else if (count($newchild) == 1) + } else if (count($newchild) == 1) { $qr = clone $newchild[0]; + } if ($qr) { $qr->float = $this->float; return $qr; @@ -405,25 +408,29 @@ protected function _finish_combine($newchild, $any) { function set_strspan_owner($str) { if (!isset($this->float["strspan_owner"])) { parent::set_strspan_owner($str); - foreach ($this->child as $qv) + foreach ($this->child as $qv) { $qv->set_strspan_owner($str); + } } } function debug_json() { $a = [$this->type]; - foreach ($this->child as $qv) + foreach ($this->child as $qv) { $a[] = $qv->debug_json(); + } return $a; } function adjust_reviews(ReviewAdjustment_SearchTerm $revadj = null, PaperSearch $srch) { - foreach ($this->child as &$qv) + foreach ($this->child as &$qv) { $qv = $qv->adjust_reviews($revadj, $srch); + } return $this; } function trivial_rights(Contact $user, PaperSearch $srch) { - foreach ($this->child as $ch) + foreach ($this->child as $ch) { if (!$ch->trivial_rights($user, $srch)) return false; + } return true; } } @@ -533,8 +540,9 @@ function adjust_reviews(ReviewAdjustment_SearchTerm $revadj = null, PaperSearch } if ($myrevadj && !$myrevadj->used_revadj) { $this->child[0] = $myrevadj->promote($srch); - if ($used_revadj) + if ($used_revadj) { $revadj->used_revadj = true; + } } return $this; } @@ -1660,7 +1668,7 @@ function __construct(Contact $user, $options) { // NB: If a complex query field, e.g., "re", "tag", or "option", is // default, then it must be the only default or query construction // will break. - $this->_qt = self::_canonical_qt(get($options, "qt")); + $this->_qt = self::_canonical_qt($options["qt"] ?? null); if ($this->_qt === "n") { $this->_qt_fields = ["ti", "ab"]; if ($this->user->can_view_some_authors()) @@ -1670,11 +1678,11 @@ function __construct(Contact $user, $options) { } // the query itself - $this->q = trim(get_s($options, "q")); - $this->_default_sort = get($options, "sort"); + $this->q = trim($options["q"] ?? ""); + $this->_default_sort = $options["sort"] ?? null; // reviewer - if (($reviewer = get($options, "reviewer"))) { + if (($reviewer = $options["reviewer"] ?? null)) { if (is_string($reviewer)) { if (strcasecmp($reviewer, $user->email) == 0) { $reviewer = $user; @@ -1692,7 +1700,7 @@ function __construct(Contact $user, $options) { } // paper selection - $limit = self::canonical_search_type((string) get($options, "t")); + $limit = self::canonical_search_type($options["t"] ?? ""); if (in_array($limit, ["a", "r", "ar", "rout", "viewable"], true) || ($user->privChair && in_array($limit, ["all", "unsub", "alladmin"], true)) || ($user->isPC && in_array($limit, ["acc", "req", "lead", "reviewable", @@ -2134,10 +2142,11 @@ static private function _shift_word($splitter, Conf $conf) { // some keywords may be followed by parentheses if (strpos($x, ":") && preg_match('/\A([-_.a-zA-Z0-9]+:|"[^"]+":)(?=[^"]|\z)/', $x, $m)) { - if ($m[1][0] === "\"") + if ($m[1][0] === "\"") { $kw = substr($m[1], 1, strlen($m[1]) - 2); - else + } else { $kw = substr($m[1], 0, strlen($m[1]) - 1); + } if (($kwdef = $conf->search_keyword($kw)) && $splitter->starts_with("(") && ($kwdef->allow_parens ?? false)) { @@ -2151,12 +2160,14 @@ static private function _shift_word($splitter, Conf $conf) { static private function _pop_expression_stack($curqe, &$stack) { $x = array_pop($stack); - if (!$curqe) + if (!$curqe) { return $x->leftqe; - if ($x->leftqe) + } + if ($x->leftqe) { $curqe = SearchTerm::make_op($x->op, [$x->leftqe, $curqe]); - else if ($x->op->op !== "+" && $x->op->op !== "(") + } else if ($x->op->op !== "+" && $x->op->op !== "(") { $curqe = SearchTerm::make_op($x->op, [$curqe]); + } $curqe->apply_strspan($x->strspan); return $curqe; } @@ -2197,8 +2208,9 @@ private function _search_expression($str) { } else { // The heart of the matter. $curqe = $this->_search_word($word, $defkw); - if (!$curqe->is_uninteresting()) + if (!$curqe->is_uninteresting()) { $curqe->set_float("strspan", $splitter->strspan); + } } } else if ($op->op === ")") { while (!empty($stack) @@ -2241,25 +2253,28 @@ private function _search_expression($str) { static private function _canonical_qt($qt) { - if (in_array($qt, ["ti", "ab", "au", "ac", "co", "re", "tag"])) + if (in_array($qt, ["ti", "ab", "au", "ac", "co", "re", "tag"])) { return $qt; - else + } else { return "n"; + } } static private function _pop_canonicalize_stack($curqe, &$stack) { $x = array_pop($stack); - if ($curqe) + if ($curqe) { $x->qe[] = $curqe; + } if (empty($x->qe)) { return null; } else if ($x->op->unary) { $qe = $x->qe[0]; if ($x->op->op === "not") { - if (preg_match('/\A(?:[(-]|NOT )/i', $qe)) + if (preg_match('/\A(?:[(-]|NOT )/i', $qe)) { $qe = "NOT $qe"; - else + } else { $qe = "-$qe"; + } } return $qe; } else if (count($x->qe) === 1) { @@ -2273,8 +2288,9 @@ static private function _pop_canonicalize_stack($curqe, &$stack) { static private function _canonical_expression($str, $type, $qt, Conf $conf) { $str = trim((string) $str); - if ($str === "") + if ($str === "") { return ""; + } $stack = array(); $parens = 0; @@ -2948,7 +2964,7 @@ function session_list_object() { function highlight_tags() { if ($this->_highlight_tags === null) { $this->_prepare(); - $this->_highlight_tags = get($this->term()->float, "tags", []); + $this->_highlight_tags = $this->term()->float["tags"] ?? []; foreach ($this->_sorters as $s) { if ($s->type[0] === "#") $this->_highlight_tags[] = substr($s->type, 1); @@ -2980,12 +2996,12 @@ function field_highlighters() { } function field_highlighter($field) { - return get($this->field_highlighters(), $field, ""); + return ($this->field_highlighters())[$field] ?? ""; } static function search_type_description(Conf $conf, $t) { - return $conf->_c("search_type", get(self::$search_type_names, $t, "Submissions")); + return $conf->_c("search_type", self::$search_type_names[$t] ?? "Submissions"); } static function canonical_search_type($reqtype) { diff --git a/src/papertable.php b/src/papertable.php index 937db7304..2b03a7a25 100644 --- a/src/papertable.php +++ b/src/papertable.php @@ -1225,8 +1225,9 @@ private function _echo_normal_body() { } $class = "pg"; - if ($nvos1 === $last - $first) + if ($nvos1 === $last - $first) { $class .= " fx8"; + } $foldnum = get($this->foldnumber, $o1->display_group, 0); if ($foldnum && $renders[$first][2] !== "") { $group_html = '' diff --git a/src/settings/s_reviewform.php b/src/settings/s_reviewform.php index 965376586..18bb74edf 100644 --- a/src/settings/s_reviewform.php +++ b/src/settings/s_reviewform.php @@ -183,8 +183,9 @@ function parse(SettingValues $sv, Si $si) { foreach (self::requested_fields($sv) as $fid => $x) { $finfo = ReviewInfo::field_info($fid, $sv->conf); if (!$finfo) { - if ($sv->has_reqv("order_$fid") && $sv->reqv("order_$fid") > 0) + if ($sv->has_reqv("order_$fid") && $sv->reqv("order_$fid") > 0) { $sv->error_at("shortName_$fid", "Too many review fields. You must delete some other fields before adding this one."); + } continue; } if (isset($rf->fmap[$finfo->id])) {