aboutsummaryrefslogtreecommitdiff
path: root/src/NXP/Classes/Calculator.php
diff options
context:
space:
mode:
authorJavier Marín <javier@marinros.com>2021-07-14 05:12:41 +0300
committerGitHub <noreply@github.com>2021-07-14 05:12:41 +0300
commitd1d27b494dececc4e96e608d0bb47fd948d7f959 (patch)
tree02e73bd4eb6772cc3432667fcea7b64e413616d0 /src/NXP/Classes/Calculator.php
parentaa37abbaeb73ac1cac5798608da51d813e976a25 (diff)
PhpStan support, consts visibilty and name for tokens (#89)
* Added handler to define not found variables Added support for string variables Fixed strings and ints comparison error * Check if variables have scalar types (int, float, string and bool) Better $onVarNotFound logic * Better support for null variables * Better support for null variables * Better support for null variables * Allow null values in `setVar` method * Support for unary positive operator * Add PhpStan config file Fix PhpStan warnings Set consts visibility Add name info to variable tokens for easier debugging Co-authored-by: Javier Marín <contacto@ideatic.net>
Diffstat (limited to 'src/NXP/Classes/Calculator.php')
-rw-r--r--src/NXP/Classes/Calculator.php4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/NXP/Classes/Calculator.php b/src/NXP/Classes/Calculator.php
index 4785a8f..a8f16af 100644
--- a/src/NXP/Classes/Calculator.php
+++ b/src/NXP/Classes/Calculator.php
@@ -44,7 +44,7 @@ class Calculator
/**
* Calculate array of tokens in reverse polish notation
* @param Token[] $tokens
- * @param array $variables
+ * @param array<string, float|string> $variables
* @return mixed
* @throws IncorrectExpressionException
* @throws UnknownVariableException
@@ -68,7 +68,7 @@ class Calculator
throw new UnknownVariableException($variable);
}
- $stack[] = new Token(Token::Literal, $value);
+ $stack[] = new Token(Token::Literal, $value, $variable);
} elseif ($token->type === Token::Function) {
if (!array_key_exists($token->value, $this->functions)) {
throw new UnknownFunctionException($token->value);