aboutsummaryrefslogtreecommitdiff
path: root/src/NXP/Classes/Token/TokenMinus.php
diff options
context:
space:
mode:
authorClément Lafont <johnrazeur@gmail.com>2020-01-13 20:09:18 +0300
committerBruce Wells <brucekwells@gmail.com>2020-01-13 20:09:18 +0300
commit707e22029d8bcfc93918eaca27905d14e376d3b5 (patch)
tree2a52c65e50cf995dbad15110e1f434b35a6df275 /src/NXP/Classes/Token/TokenMinus.php
parentff550b4180ac88bf1dd2425e137f459342fef0a7 (diff)
Left bracket and minus fix (#55)V1.1.2
* Left bracket and minus fix (#54) * Add test for left bracket and minus fix #55
Diffstat (limited to 'src/NXP/Classes/Token/TokenMinus.php')
-rw-r--r--src/NXP/Classes/Token/TokenMinus.php8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/NXP/Classes/Token/TokenMinus.php b/src/NXP/Classes/Token/TokenMinus.php
index d8ac079..b4b04e3 100644
--- a/src/NXP/Classes/Token/TokenMinus.php
+++ b/src/NXP/Classes/Token/TokenMinus.php
@@ -53,8 +53,12 @@ class TokenMinus extends AbstractOperator
$op2 = array_pop($stack);
$op1 = array_pop($stack);
- if ($op1 === null || $op2 === null) {
- throw new IncorrectExpressionException("Subtraction requires two operators");
+ if ($op2 === null) {
+ throw new IncorrectExpressionException("Subtraction requires right operator");
+ }
+
+ if (!$op1) {
+ $op1 = new TokenNumber(0);
}
$result = $op1->getValue() - $op2->getValue();