From b9f72a001bca4772a003248595ad20b13a5b2277 Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Wed, 24 Oct 2018 14:16:11 -0400 Subject: Additional validation for bad expressions (*+ for example) --- src/NXP/Classes/Token/TokenMinus.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/NXP/Classes/Token/TokenMinus.php') diff --git a/src/NXP/Classes/Token/TokenMinus.php b/src/NXP/Classes/Token/TokenMinus.php index 0463d4c..566c950 100644 --- a/src/NXP/Classes/Token/TokenMinus.php +++ b/src/NXP/Classes/Token/TokenMinus.php @@ -10,6 +10,8 @@ namespace NXP\Classes\Token; +use NXP\Exception\IncorrectExpressionException; + /** * @author Alexander Kiryukhin */ @@ -41,12 +43,20 @@ class TokenMinus extends AbstractOperator /** * @param InterfaceToken[] $stack + * * @return $this + * + * @throws \NXP\Exception\IncorrectExpressionException */ public function execute(&$stack) { $op2 = array_pop($stack); $op1 = array_pop($stack); + + if ($op1 === null || $op2 === null) { + throw new IncorrectExpressionException("Subtraction requires two operators"); + } + $result = $op1->getValue() - $op2->getValue(); return new TokenNumber($result); -- cgit v1.2.3