From cab8e2d38ae1c8c7fb75022f7d9b0539a0a86d4e Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Fri, 15 May 2020 21:51:23 +0300 Subject: Massive refactoring More clean structure Parsing without regular expressions --- src/NXP/MathExecutor.php | 386 +++++++++++++++++++++-------------------------- 1 file changed, 169 insertions(+), 217 deletions(-) (limited to 'src/NXP/MathExecutor.php') diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php index e9ce0ed..8d3e890 100644 --- a/src/NXP/MathExecutor.php +++ b/src/NXP/MathExecutor.php @@ -12,9 +12,13 @@ namespace NXP; use NXP\Classes\Calculator; -use NXP\Classes\Lexer; +use NXP\Classes\CustomFunction; +use NXP\Classes\Operator; +use NXP\Classes\Token\AbstractOperator; use NXP\Classes\TokenFactory; -use NXP\Exception\UnknownVariableException; +use NXP\Classes\Tokenizer; +use NXP\Exception\DivisionByZeroException; +use ReflectionException; /** * Class MathExecutor @@ -27,12 +31,17 @@ class MathExecutor * * @var array */ - private $variables = []; + public $variables = []; /** - * @var TokenFactory + * @var Operator[] */ - private $tokenFactory; + public $operators = []; + + /** + * @var CustomFunction[] + */ + public $functions = []; /** * @var array @@ -47,239 +56,139 @@ class MathExecutor $this->addDefaults(); } - public function __clone() - { - $this->addDefaults(); - } - - /** - * Get all vars - * - * @return array - */ - public function getVars() - { - return $this->variables; - } - /** - * Get a specific var - * - * @param string $variable - * @return integer|float - * @throws UnknownVariableException - */ - public function getVar($variable) - { - if (!isset($this->variables[$variable])) { - throw new UnknownVariableException("Variable ({$variable}) not set"); - } - - return $this->variables[$variable]; - } - - /** - * Add variable to executor - * - * @param string $variable - * @param integer|float $value - * @return MathExecutor - * @throws \Exception - */ - public function setVar($variable, $value) - { - if (!is_numeric($value)) { - throw new \Exception("Variable ({$variable}) value must be a number ({$value}) type ({gettype($value)})"); - } - - $this->variables[$variable] = $value; - - return $this; - } - - /** - * Add variables to executor - * - * @param array $variables - * @param bool $clear Clear previous variables - * @return MathExecutor - * @throws \Exception + * Set default operands and functions + * @throws ReflectionException */ - public function setVars(array $variables, $clear = true) + protected function addDefaults() { - if ($clear) { - $this->removeVars(); + foreach ($this->defaultOperators() as $name => $operator) { + list($callable, $priority, $isRightAssoc) = $operator; + $this->addOperator(new Operator($name, $isRightAssoc, $priority, $callable)); } - - foreach ($variables as $name => $value) { - $this->setVar($name, $value); + foreach ($this->defaultFunctions() as $name => $callable) { + $this->addFunction($name, $callable); } - - return $this; + $this->variables = $this->defaultVars(); } /** - * Remove variable from executor + * Get the default operators * - * @param string $variable - * @return MathExecutor - */ - public function removeVar($variable) - { - unset ($this->variables[$variable]); - - return $this; - } - - /** - * Remove all variables - * @return MathExecutor + * @return array of class names */ - public function removeVars() + protected function defaultOperators() { - $this->variables = []; - - return $this; + return [ + '+' => [ + function ($a, $b) { + return $a + $b; + }, + 170, + false + ], + '-' => [ + function ($a, $b) { + return $a - $b; + }, + 170, + false + ], + '*' => [ + function ($a, $b) { + return $a * $b; + }, + 180, + false + ], + '/' => [ + function ($a, $b) { + if ($b == 0) { + throw new DivisionByZeroException(); + } + return $a / $b; + }, + 180, + false + ], + '^' => [ + function ($a, $b) { + return pow($a, $b); + }, + 220, + true + ], + '&&' => [ + function ($a, $b) { + return $a && $b; + }, + 100, + false + ], + '||' => [ + function ($a, $b) { + return $a || $b; + }, + 90, + false + ], + '==' => [ + function ($a, $b) { + return $a == $b; + }, + 140, + false + ], + '!=' => [ + function ($a, $b) { + return $a != $b; + }, + 140, + false + ], + '>=' => [ + function ($a, $b) { + return $a >= $b; + }, + 150, + false + ], + '>' => [ + function ($a, $b) { + return $a > $b; + }, + 150, + false + ], + '<=' => [ + function ($a, $b) { + return $a <= $b; + }, + 150, + false + ], + '<' => [ + function ($a, $b) { + return $a < $b; + }, + 150, + false + ], + ]; } /** * Add operator to executor * - * @param string $operatorClass Class of operator token - * @return MathExecutor - * @throws Exception\UnknownOperatorException - */ - public function addOperator($operatorClass) - { - $this->tokenFactory->addOperator($operatorClass); - - return $this; - } - - /** - * Get all registered operators to executor - * - * @return array of operator class names - */ - public function getOperators() - { - return $this->tokenFactory->getOperators(); - } - - /** - * Add function to executor - * - * @param string $name Name of function - * @param callable $function Function - * @param int $places Count of arguments - * @return MathExecutor - * @throws \ReflectionException - */ - public function addFunction($name, $function = null, $places = null) - { - $this->tokenFactory->addFunction($name, $function, $places); - - return $this; - } - - /** - * Get all registered functions - * - * @return array containing callback and places indexed by - * function name - */ - public function getFunctions() - { - return $this->tokenFactory->getFunctions(); - } - - /** - * Set division by zero exception reporting - * - * @param bool $exception default true + * @param Operator $operator * @return MathExecutor */ - public function setDivisionByZeroException($exception = true) + public function addOperator(Operator $operator) { - $this->tokenFactory->setDivisionByZeroException($exception); + $this->operators[$operator->operator] = $operator; return $this; } - /** - * Get division by zero exception status - * - * @return bool - */ - public function getDivisionByZeroException() - { - return $this->tokenFactory->getDivisionByZeroException(); - } - - /** - * Execute expression - * - * @param $expression - * @return number - */ - public function execute($expression) - { - $cachekey = (string)$expression; - if (!array_key_exists($cachekey, $this->cache)) { - $lexer = new Lexer($this->tokenFactory); - $tokensStream = $lexer->stringToTokensStream($expression); - $tokens = $lexer->buildReversePolishNotation($tokensStream); - $this->cache[$cachekey] = $tokens; - } else { - $tokens = $this->cache[$cachekey]; - } - $calculator = new Calculator(); - $result = $calculator->calculate($tokens, $this->variables); - - return $result; - } - - /** - * Set default operands and functions - */ - protected function addDefaults() - { - $this->tokenFactory = new TokenFactory(); - - foreach ($this->defaultOperators() as $operatorClass) { - $this->tokenFactory->addOperator($operatorClass); - } - - foreach ($this->defaultFunctions() as $name => $callable) { - $this->tokenFactory->addFunction($name, $callable); - } - - $this->setVars($this->defaultVars()); - } - - /** - * Get the default operators - * - * @return array of class names - */ - protected function defaultOperators() - { - return [ - \NXP\Classes\Token\TokenPlus::class, - \NXP\Classes\Token\TokenMinus::class, - \NXP\Classes\Token\TokenMultiply::class, - \NXP\Classes\Token\TokenDivision::class, - \NXP\Classes\Token\TokenDegree::class, - \NXP\Classes\Token\TokenAnd::class, - \NXP\Classes\Token\TokenOr::class, - \NXP\Classes\Token\TokenEqual::class, - \NXP\Classes\Token\TokenNotEqual::class, - \NXP\Classes\Token\TokenGreaterThanOrEqual::class, - \NXP\Classes\Token\TokenGreaterThan::class, - \NXP\Classes\Token\TokenLessThanOrEqual::class, - \NXP\Classes\Token\TokenLessThan::class, - ]; - } - /** * Gets the default functions as an array. Key is function name * and value is the function as a closure. @@ -424,6 +333,44 @@ class MathExecutor ]; } + /** + * Execute expression + * + * @param $expression + * @return number + * @throws Exception\IncorrectExpressionException + * @throws Exception\IncorrectBracketsException + * @throws Exception\UnknownOperatorException + * @throws Exception\UnknownVariableException + */ + public function execute($expression) + { + $cachekey = (string)$expression; + if (!array_key_exists($cachekey, $this->cache)) { + $tokens = (new Tokenizer($expression, $this->operators))->tokenize()->buildReversePolishNotation(); + $this->cache[$cachekey] = $tokens; + } else { + $tokens = $this->cache[$cachekey]; + } + $calculator = new Calculator($this->functions, $this->operators); + return $calculator->calculate($tokens, $this->variables); + } + + /** + * Add function to executor + * + * @param string $name Name of function + * @param callable $function Function + * @param int $places Count of arguments + * @return MathExecutor + * @throws ReflectionException + */ + public function addFunction($name, $function = null, $places = null) + { + $this->functions[$name] = new CustomFunction($name, $function, $places); + return $this; + } + /** * Returns the default variables names as key/value pairs * @@ -433,7 +380,12 @@ class MathExecutor { return [ 'pi' => 3.14159265359, - 'e' => 2.71828182846 + 'e' => 2.71828182846 ]; } + + public function __clone() + { + $this->addDefaults(); + } } -- cgit v1.2.3 From b74742641f9c5dfb6077745c3c175bca6234d8e0 Mon Sep 17 00:00:00 2001 From: Alexander Kiryukhin Date: Fri, 15 May 2020 22:02:52 +0300 Subject: 7.1 downgrade --- src/NXP/Classes/Tokenizer.php | 15 ++------------- src/NXP/MathExecutor.php | 2 -- 2 files changed, 2 insertions(+), 15 deletions(-) (limited to 'src/NXP/MathExecutor.php') diff --git a/src/NXP/Classes/Tokenizer.php b/src/NXP/Classes/Tokenizer.php index 869c720..b72b869 100644 --- a/src/NXP/Classes/Tokenizer.php +++ b/src/NXP/Classes/Tokenizer.php @@ -10,18 +10,6 @@ namespace NXP\Classes; -use NXP\Classes\Token\AbstractOperator; -use NXP\Classes\Token\InterfaceOperator; -use NXP\Classes\Token\InterfaceToken; -use NXP\Classes\Token\TokenComma; -use NXP\Classes\Token\TokenFunction; -use NXP\Classes\Token\TokenLeftBracket; -use NXP\Classes\Token\TokenMinus; -use NXP\Classes\Token\TokenNumber; -use NXP\Classes\Token\TokenRightBracket; -use NXP\Classes\Token\TokenStringDoubleQuoted; -use NXP\Classes\Token\TokenStringSingleQuoted; -use NXP\Classes\Token\TokenVariable; use NXP\Exception\IncorrectBracketsException; use NXP\Exception\UnknownOperatorException; use RuntimeException; @@ -80,7 +68,7 @@ class Tokenizer public function tokenize() { - foreach (mb_str_split($this->input, 1) as $ch) { + foreach (str_split($this->input, 1) as $ch) { switch (true) { case $this->inSingleQuotedString: if ($ch === "'") { @@ -111,6 +99,7 @@ class Tokenizer $this->numberBuffer .= $ch; $this->allowNegative = false; break; + /** @noinspection PhpMissingBreakStatementInspection */ case strtolower($ch) === "e": if ($this->numberBuffer != "" && strpos($this->numberBuffer, ".") !== false) { $this->numberBuffer .= "e"; diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php index 8d3e890..a0a3f9b 100644 --- a/src/NXP/MathExecutor.php +++ b/src/NXP/MathExecutor.php @@ -14,8 +14,6 @@ namespace NXP; use NXP\Classes\Calculator; use NXP\Classes\CustomFunction; use NXP\Classes\Operator; -use NXP\Classes\Token\AbstractOperator; -use NXP\Classes\TokenFactory; use NXP\Classes\Tokenizer; use NXP\Exception\DivisionByZeroException; use ReflectionException; -- cgit v1.2.3 From 1bb9f61423c1eed320e95a1288a146ece410e1f9 Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Tue, 19 May 2020 21:52:26 -0400 Subject: typed parameters and return types --- src/NXP/Classes/Calculator.php | 2 +- src/NXP/Classes/CustomFunction.php | 4 ++-- src/NXP/Classes/Operator.php | 2 +- src/NXP/Classes/Tokenizer.php | 20 ++++++++++---------- src/NXP/MathExecutor.php | 18 +++++++++--------- 5 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src/NXP/MathExecutor.php') diff --git a/src/NXP/Classes/Calculator.php b/src/NXP/Classes/Calculator.php index 0db49e1..c6ccff1 100644 --- a/src/NXP/Classes/Calculator.php +++ b/src/NXP/Classes/Calculator.php @@ -49,7 +49,7 @@ class Calculator * @throws IncorrectExpressionException * @throws UnknownVariableException */ - public function calculate($tokens, $variables) + public function calculate(array $tokens, array $variables) { /** @var Token[] $stack */ $stack = []; diff --git a/src/NXP/Classes/CustomFunction.php b/src/NXP/Classes/CustomFunction.php index 944f7d9..636435c 100644 --- a/src/NXP/Classes/CustomFunction.php +++ b/src/NXP/Classes/CustomFunction.php @@ -32,7 +32,7 @@ class CustomFunction * @param int $places * @throws ReflectionException */ - public function __construct(string $name, callable $function, $places = null) + public function __construct(string $name, callable $function, int $places = null) { $this->name = $name; $this->function = $function; @@ -44,7 +44,7 @@ class CustomFunction } } - public function execute(&$stack) + public function execute(array &$stack) : Token { if (count($stack) < $this->places) { throw new IncorrectExpressionException(); diff --git a/src/NXP/Classes/Operator.php b/src/NXP/Classes/Operator.php index 53550a9..c3762ea 100644 --- a/src/NXP/Classes/Operator.php +++ b/src/NXP/Classes/Operator.php @@ -52,7 +52,7 @@ class Operator $this->places = $reflection->getNumberOfParameters(); } - public function execute(&$stack) + public function execute(array &$stack) : Token { if (count($stack) < $this->places) { throw new IncorrectExpressionException(); diff --git a/src/NXP/Classes/Tokenizer.php b/src/NXP/Classes/Tokenizer.php index b72b869..caf395f 100644 --- a/src/NXP/Classes/Tokenizer.php +++ b/src/NXP/Classes/Tokenizer.php @@ -66,7 +66,7 @@ class Tokenizer $this->operators = $operators; } - public function tokenize() + public function tokenize() : self { foreach (str_split($this->input, 1) as $ch) { switch (true) { @@ -173,17 +173,17 @@ class Tokenizer return $this; } - private function isNumber($ch) + private function isNumber(string $ch) : bool { return $ch >= '0' && $ch <= '9'; } - private function isAlpha($ch) + private function isAlpha(string $ch) : bool { return $ch >= 'a' && $ch <= 'z' || $ch >= 'A' && $ch <= 'Z' || $ch == '_'; } - private function emptyNumberBufferAsLiteral() + private function emptyNumberBufferAsLiteral() : void { if ($this->numberBuffer != "") { $this->tokens[] = new Token(Token::Literal, $this->numberBuffer); @@ -191,22 +191,22 @@ class Tokenizer } } - private function isDot($ch) + private function isDot(string $ch) : bool { return $ch == '.'; } - private function isLP($ch) + private function isLP(string $ch) : bool { return $ch == '('; } - private function isRP($ch) + private function isRP(string $ch) : bool { return $ch == ')'; } - private function emptyStrBufferAsVariable() + private function emptyStrBufferAsVariable() : void { if ($this->stringBuffer != "") { $this->tokens[] = new Token(Token::Variable, $this->stringBuffer); @@ -214,7 +214,7 @@ class Tokenizer } } - private function isComma($ch) + private function isComma(string $ch) : bool { return $ch == ','; } @@ -224,7 +224,7 @@ class Tokenizer * @throws IncorrectBracketsException * @throws UnknownOperatorException */ - public function buildReversePolishNotation() + public function buildReversePolishNotation() : array { $tokens = []; /** @var SplStack $stack */ diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php index a0a3f9b..53d8dfd 100644 --- a/src/NXP/MathExecutor.php +++ b/src/NXP/MathExecutor.php @@ -58,7 +58,7 @@ class MathExecutor * Set default operands and functions * @throws ReflectionException */ - protected function addDefaults() + protected function addDefaults() : void { foreach ($this->defaultOperators() as $name => $operator) { list($callable, $priority, $isRightAssoc) = $operator; @@ -75,7 +75,7 @@ class MathExecutor * * @return array of class names */ - protected function defaultOperators() + protected function defaultOperators() : array { return [ '+' => [ @@ -102,7 +102,7 @@ class MathExecutor '/' => [ function ($a, $b) { if ($b == 0) { - throw new DivisionByZeroException(); + throw new DivisionByZeroException(); } return $a / $b; }, @@ -181,7 +181,7 @@ class MathExecutor * @param Operator $operator * @return MathExecutor */ - public function addOperator(Operator $operator) + public function addOperator(Operator $operator) : self { $this->operators[$operator->operator] = $operator; return $this; @@ -193,7 +193,7 @@ class MathExecutor * * @return array */ - protected function defaultFunctions() + protected function defaultFunctions() : array { return [ 'abs' => function ($arg) { @@ -341,9 +341,9 @@ class MathExecutor * @throws Exception\UnknownOperatorException * @throws Exception\UnknownVariableException */ - public function execute($expression) + public function execute(string $expression) { - $cachekey = (string)$expression; + $cachekey = $expression; if (!array_key_exists($cachekey, $this->cache)) { $tokens = (new Tokenizer($expression, $this->operators))->tokenize()->buildReversePolishNotation(); $this->cache[$cachekey] = $tokens; @@ -363,7 +363,7 @@ class MathExecutor * @return MathExecutor * @throws ReflectionException */ - public function addFunction($name, $function = null, $places = null) + public function addFunction(string $name, callable $function = null, int $places = null) : self { $this->functions[$name] = new CustomFunction($name, $function, $places); return $this; @@ -374,7 +374,7 @@ class MathExecutor * * @return array */ - protected function defaultVars() + protected function defaultVars() : array { return [ 'pi' => 3.14159265359, -- cgit v1.2.3 From ab3a44b33031d86c74cc8f07c9d904d8d20c7da9 Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Tue, 19 May 2020 22:20:56 -0400 Subject: Private members --- src/NXP/MathExecutor.php | 94 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 90 insertions(+), 4 deletions(-) (limited to 'src/NXP/MathExecutor.php') diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php index 53d8dfd..0b7e9db 100644 --- a/src/NXP/MathExecutor.php +++ b/src/NXP/MathExecutor.php @@ -15,6 +15,7 @@ use NXP\Classes\Calculator; use NXP\Classes\CustomFunction; use NXP\Classes\Operator; use NXP\Classes\Tokenizer; +use NXP\MathExecutorException; use NXP\Exception\DivisionByZeroException; use ReflectionException; @@ -29,17 +30,17 @@ class MathExecutor * * @var array */ - public $variables = []; + private $variables = []; /** * @var Operator[] */ - public $operators = []; + private $operators = []; /** * @var CustomFunction[] */ - public $functions = []; + private $functions = []; /** * @var array @@ -61,7 +62,7 @@ class MathExecutor protected function addDefaults() : void { foreach ($this->defaultOperators() as $name => $operator) { - list($callable, $priority, $isRightAssoc) = $operator; + [$callable, $priority, $isRightAssoc] = $operator; $this->addOperator(new Operator($name, $isRightAssoc, $priority, $callable)); } foreach ($this->defaultFunctions() as $name => $callable) { @@ -382,6 +383,91 @@ class MathExecutor ]; } + /** + * Get all vars + * + * @return array + */ + public function getVars() : array + { + return $this->variables; + } + + /** + * Get a specific var + * + * @param string $variable + * @return integer|float + * @throws UnknownVariableException + */ + public function getVar(string $variable) + { + if (!isset($this->variables[$variable])) { + throw new UnknownVariableException("Variable ({$variable}) not set"); + } + return $this->variables[$variable]; + } + + /** + * Add variable to executor + * + * @param string $variable + * @param integer|float $value + * @return MathExecutor + * @throws MathExecutorException + */ + public function setVar(string $variable, $value) : self + { + if (!is_numeric($value)) { + throw new MathExecutorException("Variable ({$variable}) value must be a number ({$value}) type ({gettype($value)})"); + } + $this->variables[$variable] = $value; + return $this; + } + + /** + * Remove variable from executor + * + * @param string $variable + * @return MathExecutor + */ + public function removeVar(string $variable) : self + { + unset ($this->variables[$variable]); + return $this; + } + + /** + * Remove all variables + * @return MathExecutor + */ + public function removeVars() : self + { + $this->variables = []; + return $this; + } + + /** + * Get all registered operators to executor + * + * @return array of operator class names + */ + public function getOperators() + { + return $this->tokenFactory->getOperators(); + } + + /** + * Get all registered functions + * + * @return array containing callback and places indexed by + * function name + */ + public function getFunctions() : array + { + return $this->tokenFactory->getFunctions(); + } + public function __clone() { $this->addDefaults(); -- cgit v1.2.3 From b95ab24f367baf928332dc5040ab444c1c719623 Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Tue, 19 May 2020 22:36:55 -0400 Subject: setDivisionByZeroIsZero --- src/NXP/MathExecutor.php | 16 ++++++++++++++++ tests/MathTest.php | 9 ++------- 2 files changed, 18 insertions(+), 7 deletions(-) (limited to 'src/NXP/MathExecutor.php') diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php index 0b7e9db..e214209 100644 --- a/src/NXP/MathExecutor.php +++ b/src/NXP/MathExecutor.php @@ -468,6 +468,22 @@ class MathExecutor return $this->tokenFactory->getFunctions(); } + /** + * Set division by zero returns zero instead of throwing DivisionByZeroException + * + * @return MathExecutor + */ + public function setDivisionByZeroIsZero() : self + { + $this->addOperator(new Operator("/", false, 180, function ($a, $b) { + if ($b == 0) { + return 0; + } + return $a / $b; + })); + return $this; + } + public function __clone() { $this->addDefaults(); diff --git a/tests/MathTest.php b/tests/MathTest.php index 958f14c..39ac649 100644 --- a/tests/MathTest.php +++ b/tests/MathTest.php @@ -203,7 +203,7 @@ class MathTest extends TestCase ['(-3 * -1)'], ['1 + (-3 * -1)'], ['1 + ( -3 * 1)'], - ['1 + (3 * -1)'], + ['1 + (3 *-1)'], ['1 - 0'], ['1-0'], ]; @@ -226,12 +226,7 @@ class MathTest extends TestCase public function testZeroDivision() { $calculator = new MathExecutor(); - $calculator->addOperator(new Operator("/", false, 180, function ($a, $b) { - if ($b == 0) { - return 0; - } - return $a / $b; - })); + $calculator->setDivisionByZeroIsZero(); $this->assertEquals(0, $calculator->execute('10 / 0')); } -- cgit v1.2.3 From a621ea01c02109d2fd5808fe4e471b0dc86a5185 Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Tue, 19 May 2020 22:59:10 -0400 Subject: Adding setVars back in --- src/NXP/MathExecutor.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/NXP/MathExecutor.php') diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php index e214209..0c643a7 100644 --- a/src/NXP/MathExecutor.php +++ b/src/NXP/MathExecutor.php @@ -426,6 +426,25 @@ class MathExecutor } /** + * Add variables to executor + * + * @param array $variables + * @param bool $clear Clear previous variables + * @return MathExecutor + * @throws \Exception + */ + public function setVars(array $variables, bool $clear = true) : self + { + if ($clear) { + $this->removeVars(); + } + foreach ($variables as $name => $value) { + $this->setVar($name, $value); + } + return $this; + } + + /** * Remove variable from executor * * @param string $variable -- cgit v1.2.3 From d195b3e909ddcd2f983d303164a1855c3557c7ff Mon Sep 17 00:00:00 2001 From: Bruce Wells Date: Tue, 19 May 2020 23:00:10 -0400 Subject: Null parameters allowed --- src/NXP/MathExecutor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/NXP/MathExecutor.php') diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php index 0c643a7..5a20e17 100644 --- a/src/NXP/MathExecutor.php +++ b/src/NXP/MathExecutor.php @@ -364,7 +364,7 @@ class MathExecutor * @return MathExecutor * @throws ReflectionException */ - public function addFunction(string $name, callable $function = null, int $places = null) : self + public function addFunction(string $name, ?callable $function = null, ?int $places = null) : self { $this->functions[$name] = new CustomFunction($name, $function, $places); return $this; -- cgit v1.2.3