-
Notifications
You must be signed in to change notification settings - Fork 988
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dev: Factor out getMismatchInformation()
- Loading branch information
1 parent
127e99a
commit cd7f13c
Showing
1 changed file
with
27 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,14 +271,39 @@ public function RDP_GetErrors() | |
return $this->RDP_errs; | ||
} | ||
|
||
/** | ||
* Get informatin about type mismatch between arguments. | ||
* @param array $arg1 | ||
* @param array $arg2 | ||
* @return array Like (boolean $bMismatchType, boolean $bBothNumeric, boolean $bBothString) | ||
*/ | ||
private function getMismatchInformation(array $arg1, array $arg2) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
Shnoulle
Collaborator
|
||
{ | ||
/* When value come from DB : it's set to 1.000000 (DECIMAL) : must be fixed see #11163. Response::model() must fix this . or not ? */ | ||
/* Don't return true always : user can entre non numeric value in a numeric value : we must compare as string then */ | ||
$arg1[0]=($arg1[2]=="NUMBER" && strpos($arg1[0], ".")) ? rtrim(rtrim($arg1[0], "0"), ".") : $arg1[0]; | ||
$arg2[0]=($arg2[2]=="NUMBER" && strpos($arg2[0], ".")) ? rtrim(rtrim($arg2[0], "0"), ".") : $arg2[0]; | ||
$bNumericArg1 = !$arg1[0] || strval(floatval($arg1[0]))==strval($arg1[0]); | ||
$bNumericArg2 = !$arg2[0] || strval(floatval($arg2[0]))==strval($arg2[0]); | ||
|
||
$bStringArg1 = !$arg1[0] || !$bNumericArg1; | ||
$bStringArg2 = !$arg2[0] || !$bNumericArg2; | ||
|
||
$bBothNumeric = ($bNumericArg1 && $bNumericArg2); | ||
$bBothString = ($bStringArg1 && $bStringArg2); | ||
$bMismatchType = (!$bBothNumeric && !$bBothString); | ||
|
||
return array($bMismatchType, $bBothNumeric, $bBothString); | ||
} | ||
|
||
/** | ||
* RDP_EvaluateBinary() computes binary expressions, such as (a or b), (c * d), popping the top two entries off the | ||
* stack and pushing the result back onto the stack. | ||
* | ||
* @param array $token | ||
* @return boolean - false if there is any error, else true | ||
*/ | ||
public function RDP_EvaluateBinary(array $token) | ||
public function RDP_EvaluateBinary(array $token) | ||
{ | ||
if (count($this->RDP_stack) < 2) | ||
{ | ||
|
@@ -292,19 +317,8 @@ public function RDP_EvaluateBinary(array $token) | |
$this->RDP_AddError(self::gT("Invalid value(s) on the stack"), $token); | ||
return false; | ||
} | ||
/* When value come from DB : it's set to 1.000000 (DECIMAL) : must be fixed see #11163. Response::model() must fix this . or not ? */ | ||
/* Don't return true always : user can entre non numeric value in a numeric value : we must compare as string then */ | ||
$arg1[0]=($arg1[2]=="NUMBER" && strpos($arg1[0],".")) ? rtrim(rtrim($arg1[0],"0"),".") : $arg1[0]; | ||
$arg2[0]=($arg2[2]=="NUMBER" && strpos($arg2[0],".")) ? rtrim(rtrim($arg2[0],"0"),".") : $arg2[0]; | ||
$bNumericArg1 = !$arg1[0] || strval(floatval($arg1[0]))==strval($arg1[0]); | ||
$bNumericArg2 = !$arg2[0] || strval(floatval($arg2[0]))==strval($arg2[0]); | ||
|
||
$bStringArg1 = !$arg1[0] || !$bNumericArg1; | ||
$bStringArg2 = !$arg2[0] || !$bNumericArg2; | ||
|
||
$bBothNumeric = ($bNumericArg1 && $bNumericArg2); | ||
$bBothString = ($bStringArg1 && $bStringArg2); | ||
$bMismatchType=(!$bBothNumeric && !$bBothString); | ||
list($bMismatchType, $bBothNumeric, $bBothString) = $this->getMismatchInformation($arg1, $arg2); | ||
|
||
// Set bBothString if one is forced to be string, only if both can be numeric. Mimic JS and PHP | ||
// Not sure if needed to test if [2] is set. : TODO review | ||
|
@Shnoulle By the way, this is a very easy function to write tests for, since it doesn't have any side-effects (doesn't read or write to session/database/request/etc).