diff options
author | Javier Marín <javier@marinros.com> | 2022-05-09 21:13:30 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-09 21:13:30 +0300 |
commit | 645f1dfbc6310185b73852c5008ef321b66a0f18 (patch) | |
tree | 2efdfcf4aabeb3c4bc75a80aac7e54dbe68aebe5 /src/NXP/Classes/Calculator.php | |
parent | b7b46bfc476ea0d22e0e92144f68aa81d390fff0 (diff) |
Two more tests + some code refactoring (#104)
* test: add testNullReturnType and testUnsupportedOperands
* refactor: fix PhpDoc comments and use PHP 7.4 arrow functions
* refactor: fix PHP-CS-Fixer issues
* test: run testUnsupportedOperands() only on PHP8+
Co-authored-by: Javier Marín <contacto@ideatic.net>
Diffstat (limited to 'src/NXP/Classes/Calculator.php')
-rw-r--r-- | src/NXP/Classes/Calculator.php | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/NXP/Classes/Calculator.php b/src/NXP/Classes/Calculator.php index 2bb5b4d..10adc24 100644 --- a/src/NXP/Classes/Calculator.php +++ b/src/NXP/Classes/Calculator.php @@ -20,10 +20,18 @@ use NXP\Exception\UnknownVariableException; */ class Calculator { + /** @var array<string, CustomFunction> */ private array $functions = []; + /** @var array<Operator> */ private array $operators = []; + /** + * @todo PHP8: Use constructor property promotion -> public function __construct(private array $functions, private array $operators) + * + * @param array<string, CustomFunction> $functions + * @param array<Operator> $operators + */ public function __construct(array $functions, array $operators) { $this->functions = $functions; @@ -32,10 +40,13 @@ class Calculator /** * Calculate array of tokens in reverse polish notation - * @param Token[] $tokens + * + * @param Token[] $tokens * @param array<string, float|string> $variables - * @throws IncorrectExpressionException + * * @throws UnknownVariableException + * @throws IncorrectExpressionException + * @return int|float|string|null */ public function calculate(array $tokens, array $variables, ?callable $onVarNotFound = null) { |