Skip to content

Commit 29005a5

Browse files
timhuntdanpoltawski
authored andcommitted
MDL-46148 qtype_calculated: Remove unused function.
1 parent 44f726a commit 29005a5

File tree

1 file changed

+2
-99
lines changed

1 file changed

+2
-99
lines changed

Diff for: question/type/calculated/question.php

+2-99
Original file line numberDiff line numberDiff line change
@@ -465,108 +465,11 @@ protected function substitute_values_pretty($text) {
465465
* @return string the text with values substituted.
466466
*/
467467
public function replace_expressions_in_text($text, $length = null, $format = null) {
468-
$vs = $this; // Can't see to use $this in a PHP closure.
468+
$vs = $this; // Can't use $this in a PHP closure.
469469
$text = preg_replace_callback('~\{=([^{}]*(?:\{[^{}]+}[^{}]*)*)}~',
470470
function ($matches) use ($vs, $format, $length) {
471471
return $vs->format_float($vs->calculate($matches[1]), $length, $format);
472472
}, $text);
473473
return $this->substitute_values_pretty($text);
474474
}
475-
476-
/**
477-
* Return an array describing any problems there are with an expression.
478-
* Returns false if the expression is fine.
479-
* @param string $formula an expression.
480-
* @return array|false list of problems, or false if the exression is OK.
481-
*/
482-
public function get_formula_errors($formula) {
483-
// Validates the formula submitted from the question edit page.
484-
// Returns false if everything is alright
485-
// otherwise it constructs an error message.
486-
// Strip away dataset names.
487-
while (preg_match('~\\{[[:alpha:]][^>} <{"\']*\\}~', $formula, $regs)) {
488-
$formula = str_replace($regs[0], '1', $formula);
489-
}
490-
491-
// Strip away empty space and lowercase it.
492-
$formula = strtolower(str_replace(' ', '', $formula));
493-
494-
$safeoperatorchar = '-+/*%>:^\~<?=&|!'; /* */
495-
$operatorornumber = "[$safeoperatorchar.0-9eE]";
496-
497-
while (preg_match("~(^|[$safeoperatorchar,(])([a-z0-9_]*)" .
498-
"\\(($operatorornumber+(,$operatorornumber+((,$operatorornumber+)+)?)?)?\\)~",
499-
$formula, $regs)) {
500-
switch ($regs[2]) {
501-
// Simple parenthesis.
502-
case '':
503-
if ((isset($regs[4]) && $regs[4]) || strlen($regs[3]) == 0) {
504-
return get_string('illegalformulasyntax', 'qtype_calculated', $regs[0]);
505-
}
506-
break;
507-
508-
// Zero argument functions.
509-
case 'pi':
510-
if ($regs[3]) {
511-
return get_string('functiontakesnoargs', 'qtype_calculated', $regs[2]);
512-
}
513-
break;
514-
515-
// Single argument functions (the most common case).
516-
case 'abs': case 'acos': case 'acosh': case 'asin': case 'asinh':
517-
case 'atan': case 'atanh': case 'bindec': case 'ceil': case 'cos':
518-
case 'cosh': case 'decbin': case 'decoct': case 'deg2rad':
519-
case 'exp': case 'expm1': case 'floor': case 'is_finite':
520-
case 'is_infinite': case 'is_nan': case 'log10': case 'log1p':
521-
case 'octdec': case 'rad2deg': case 'sin': case 'sinh': case 'sqrt':
522-
case 'tan': case 'tanh':
523-
if (!empty($regs[4]) || empty($regs[3])) {
524-
return get_string('functiontakesonearg', 'qtype_calculated', $regs[2]);
525-
}
526-
break;
527-
528-
// Functions that take one or two arguments.
529-
case 'log': case 'round':
530-
if (!empty($regs[5]) || empty($regs[3])) {
531-
return get_string('functiontakesoneortwoargs', 'qtype_calculated',
532-
$regs[2]);
533-
}
534-
break;
535-
536-
// Functions that must have two arguments.
537-
case 'atan2': case 'fmod': case 'pow':
538-
if (!empty($regs[5]) || empty($regs[4])) {
539-
return get_string('functiontakestwoargs', 'qtype_calculated', $regs[2]);
540-
}
541-
break;
542-
543-
// Functions that take two or more arguments.
544-
case 'min': case 'max':
545-
if (empty($regs[4])) {
546-
return get_string('functiontakesatleasttwo', 'qtype_calculated', $regs[2]);
547-
}
548-
break;
549-
550-
default:
551-
return get_string('unsupportedformulafunction', 'qtype_calculated', $regs[2]);
552-
}
553-
554-
// Exchange the function call with '1' and then check for another function call.
555-
556-
if ($regs[1]) {
557-
// The function call is proceeded by an operator.
558-
$formula = str_replace($regs[0], $regs[1] . '1', $formula);
559-
} else {
560-
// The function call starts the formula.
561-
$formula = preg_replace("~^$regs[2]\\([^)]*\\)~", '1', $formula);
562-
}
563-
}
564-
565-
if (preg_match("~[^$safeoperatorchar.0-9eE]+~", $formula, $regs)) {
566-
return get_string('illegalformulasyntax', 'qtype_calculated', $regs[0]);
567-
} else {
568-
// Formula just might be valid.
569-
return false;
570-
}
571-
}
572-
}
475+
}

0 commit comments

Comments
 (0)