Skip to content

Commit

Permalink
Types.
Browse files Browse the repository at this point in the history
  • Loading branch information
kohler committed Apr 2, 2024
1 parent bdf6037 commit a389183
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 35 deletions.
22 changes: 18 additions & 4 deletions src/formula.php
Original file line number Diff line number Diff line change
Expand Up @@ -1977,6 +1977,18 @@ function placeholder_prow() {
return $this->_placeholder_prow;
}

/** @return PaperOption */
function format_sf() {
assert($this->_format === Fexpr::FSUBFIELD);
return $this->_format_detail;
}

/** @return ReviewField */
function format_rf() {
assert($this->_format === Fexpr::FREVIEWFIELD);
return $this->_format_detail;
}

/** @param string $t
* @param string $span
* @return int */
Expand Down Expand Up @@ -2757,11 +2769,12 @@ function unparse_html($x, $real_format = null) {
$rx = round($x * 100) / 100;
if ($this->_format > Fexpr::FNUMERIC) {
if ($this->_format === Fexpr::FREVIEWFIELD) {
return $this->_format_detail->unparse_span_html($rx, $real_format);
return $this->format_rf()->unparse_span_html($rx, $real_format);
} else if ($this->_format === Fexpr::FSUBFIELD) {
$prow = $this->placeholder_prow();
$fr = new FieldRender(FieldRender::CFHTML);
$this->_format_detail->render($fr, PaperValue::make($prow, $this->_format_detail, $x));
$sf = $this->format_sf();
$sf->render($fr, PaperValue::make($prow, $sf, $x));
return $fr->value_html();
} else if ($this->_format === Fexpr::FPREFEXPERTISE) {
return ReviewField::make_expertise($this->conf)->unparse_span_html($x + 2, $real_format);
Expand Down Expand Up @@ -2791,11 +2804,12 @@ function unparse_text($x, $real_format) {
$rx = round($x * 100) / 100;
if ($this->_format > Fexpr::FNUMERIC) {
if ($this->_format === Fexpr::FREVIEWFIELD) {
return $this->_format_detail->unparse_computed($rx, $real_format);
return $this->format_rf()->unparse_computed($rx, $real_format);
} else if ($this->_format === Fexpr::FSUBFIELD) {
$prow = $this->placeholder_prow();
$fr = new FieldRender(FieldRender::CFTEXT | FieldRender::CFCSV | FieldRender::CFVERBOSE);
$this->_format_detail->render($fr, PaperValue::make($prow, $this->_format_detail, $x));
$sf = $this->format_sf();
$sf->render($fr, PaperValue::make($prow, $sf, $x));
return $fr->value; // XXX
} else if ($this->_format === Fexpr::FPREFEXPERTISE) {
return ReviewField::make_expertise($this->conf)->unparse_computed($x + 2, $real_format);
Expand Down
2 changes: 1 addition & 1 deletion src/papertable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2661,7 +2661,7 @@ function review_table() {
foreach ($conf->review_form()->forder as $f) {
if ($f->view_score > $view_score
&& ($fv = $rr->fval($f)) !== null
&& ($fh = $f->unparse_span_html($fv)) !== "") {
&& ($fh = $f->unparse_span_html($fv, null)) !== "") {
if ($score_header[$f->short_id] === "") {
$score_header[$f->short_id] = '<th class="rlscore">' . $f->web_abbreviation() . "</th>";
}
Expand Down
38 changes: 15 additions & 23 deletions src/reviewfield.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,19 +415,19 @@ function value_clean_storage($fval) {
* @return string */
abstract function unparse_value($fval);

/** @deprecated */
function unparse($fval) {
return $this->unparse_value($fval);
}

/** @param ?int|?float|?string $fval
* @return mixed */
abstract function unparse_json($fval);

/** @param int|float $fval
* @param ?string $format
* @return string */
abstract function unparse_computed($fval, $format = null);

/** @param int|float|string $fval
* @param ?string $real_format
* @param ?string $format
* @return string */
function unparse_span_html($fval, $real_format = null) {
function unparse_span_html($fval, $format = null) {
return "";
}

Expand All @@ -437,13 +437,6 @@ function unparse_search($fval) {
return "";
}

const VALUE_NONE = 0;
const VALUE_SC = 1;
/** @deprecated */
function value_unparse($fval, $flags = 0, $real_format = null) {
return $flags & self::VALUE_SC ? $this->unparse_span_html($fval, $real_format) : $this->unparse_value($fval);
}

/** @param Qrequest $qreq
* @param string $key
* @return ?string */
Expand Down Expand Up @@ -649,11 +642,6 @@ function export_setting() {
return $rfs;
}

/** @param int|float $fval
* @param ?string $real_format
* @return string */
abstract function unparse_computed($fval, $real_format = null);

const GRAPH_STACK = 1;
const GRAPH_PROPORTIONS = 2;
const GRAPH_STACK_REQUIRED = 3;
Expand Down Expand Up @@ -982,15 +970,15 @@ function unparse_search($fval) {
}

/** @param int|float $fval
* @param ?string $real_format
* @param ?string $format
* @return string */
function unparse_computed($fval, $real_format = null) {
function unparse_computed($fval, $format = null) {
if ($fval === null) {
return "";
}
$numeric = ($this->flags & self::FLAG_NUMERIC) !== 0;
if ($real_format !== null && $numeric) {
return sprintf($real_format, $fval);
if ($format !== null && $numeric) {
return sprintf($format, $fval);
}
if ($fval <= 0.8) {
return "";
Expand Down Expand Up @@ -1366,6 +1354,10 @@ function unparse_json($fval) {
return $fval;
}

function unparse_computed($fval, $format = null) {
return (string) $fval;
}

function parse($text) {
$text = rtrim($text);
if ($text === "") {
Expand Down
6 changes: 3 additions & 3 deletions src/reviewfields/rf_checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ function unparse_search($fval) {
return $fval > 0 ? "yes" : "no";
}

function unparse_computed($fval, $real_format = null) {
function unparse_computed($fval, $format = null) {
if ($fval === null) {
return "";
} else if ($fval == 0) {
return "";
} else if ($fval == 1) {
return "";
} else if ($real_format !== null) {
return sprintf($real_format, $fval);
} else if ($format !== null) {
return sprintf($format, $fval);
} else if ($fval < 0.125) {
return "";
} else if ($fval >= 0.875) {
Expand Down
8 changes: 4 additions & 4 deletions src/reviewfields/rf_checkboxes.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ function unparse_search($fval) {
}

/** @param int|float $fval
* @param ?string $real_format
* @param ?string $format
* @return string */
function unparse_computed($fval, $real_format = null) {
function unparse_computed($fval, $format = null) {
// XXX
if ($fval === null) {
return "";
}
$numeric = ($this->flags & self::FLAG_NUMERIC) !== 0;
if ($real_format !== null && $numeric) {
return sprintf($real_format, $fval);
if ($format !== null && $numeric) {
return sprintf($format, $fval);
}
if ($fval <= 0.8) {
return "";
Expand Down

0 comments on commit a389183

Please sign in to comment.