diff options
author | Bruce Wells <brucekwells@gmail.com> | 2020-04-10 05:06:58 +0300 |
---|---|---|
committer | Bruce Wells <brucekwells@gmail.com> | 2020-04-10 05:22:37 +0300 |
commit | e7add2d36dce3a25389e359bd53e4b5ebc6160f9 (patch) | |
tree | e61d76954437062412493fb6436bf092ed4e4b40 | |
parent | 4955c639e1069ba3d3415d01a3368f09b000c2a7 (diff) |
Update documentation for PHPFUI/InstaDoc
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | src/NXP/Classes/Calculator.php | 6 | ||||
-rw-r--r-- | src/NXP/Classes/Lexer.php | 1 | ||||
-rw-r--r-- | src/NXP/Classes/Token/AbstractOperator.php | 1 | ||||
-rw-r--r-- | src/NXP/Classes/TokenFactory.php | 8 | ||||
-rw-r--r-- | src/NXP/MathExecutor.php | 44 |
6 files changed, 48 insertions, 18 deletions
@@ -202,6 +202,10 @@ This will allow you to remove functions and operators if needed, or implement di Also note that you can replace an existing default operator by adding a new operator with the same regular expression string. For example if you just need to redefine TokenPlus, you can just add a new operator with the same regex string, in this case '\\+'. +## Documentation + +Full class documentation via [PHPFUI/InstaDoc](http://phpfui.com/?n=NXP&c=MathExecutor) + ## Future Enhancements -This package will continue to track currently supported versions of PHP. We recommend you keep PHP up-to-date. Currently the code will run under 5.6, but don't expect 5.6 support going forward. +This package will continue to track currently supported versions of PHP. PHP 7.1 and earlier support will be dropped when PHP 8 is released. diff --git a/src/NXP/Classes/Calculator.php b/src/NXP/Classes/Calculator.php index 980a52b..7d82ecd 100644 --- a/src/NXP/Classes/Calculator.php +++ b/src/NXP/Classes/Calculator.php @@ -26,9 +26,9 @@ class Calculator { /** * Calculate array of tokens in reverse polish notation - * @param array $tokens Array of tokens - * @param array $variables Array of variables - * @return number Result + * @param array $tokens + * @param array $variables + * @return number Result * @throws \NXP\Exception\IncorrectExpressionException * @throws \NXP\Exception\UnknownVariableException */ diff --git a/src/NXP/Classes/Lexer.php b/src/NXP/Classes/Lexer.php index cd12d21..a7fe697 100644 --- a/src/NXP/Classes/Lexer.php +++ b/src/NXP/Classes/Lexer.php @@ -155,6 +155,7 @@ class Lexer private function isNegativeZero($x) { $floatVal = floatval($x); + return $floatVal === 0.0 && $floatVal ** -1 === -INF; } } diff --git a/src/NXP/Classes/Token/AbstractOperator.php b/src/NXP/Classes/Token/AbstractOperator.php index 8b23ad8..67e8031 100644 --- a/src/NXP/Classes/Token/AbstractOperator.php +++ b/src/NXP/Classes/Token/AbstractOperator.php @@ -35,6 +35,7 @@ abstract class AbstractOperator implements InterfaceToken, InterfaceOperator public function setDivisionByZeroException($exception = true) { $this->divideByZeroReporting = $exception; + return $this; } diff --git a/src/NXP/Classes/TokenFactory.php b/src/NXP/Classes/TokenFactory.php index 5aa634a..70d1ba9 100644 --- a/src/NXP/Classes/TokenFactory.php +++ b/src/NXP/Classes/TokenFactory.php @@ -54,6 +54,7 @@ class TokenFactory * @param string $name * @param callable $function * @param int $places + * @return TokenFactory * @throws \ReflectionException */ public function addFunction($name, callable $function, $places = null) @@ -63,6 +64,8 @@ class TokenFactory $places = $reflector->getNumberOfParameters(); } $this->functions[$name] = [$places, $function]; + + return $this; } /** @@ -79,6 +82,7 @@ class TokenFactory /** * Add operator * @param string $operatorClass + * @return TokenFactory * @throws UnknownOperatorException * @throws \ReflectionException */ @@ -91,6 +95,8 @@ class TokenFactory } $this->operators[$operatorClass::getRegex()] = $operatorClass; + + return $this; } /** @@ -113,6 +119,7 @@ class TokenFactory public function setDivisionByZeroException($exception = true) { $this->divideByZeroReporting = $exception; + return $this; } @@ -147,6 +154,7 @@ class TokenFactory TokenComma::getRegex() ); $s .= $operatorsRegex . '/i'; + return $s; } diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php index 9d3f5e8..e9ce0ed 100644 --- a/src/NXP/MathExecutor.php +++ b/src/NXP/MathExecutor.php @@ -133,6 +133,7 @@ class MathExecutor /** * Remove all variables + * @return MathExecutor */ public function removeVars() { @@ -196,7 +197,6 @@ class MathExecutor * Set division by zero exception reporting * * @param bool $exception default true - * * @return MathExecutor */ public function setDivisionByZeroException($exception = true) @@ -256,25 +256,36 @@ class MathExecutor $this->setVars($this->defaultVars()); } + /** + * Get the default operators + * + * @return array of class names + */ protected function defaultOperators() { return [ - 'NXP\Classes\Token\TokenPlus', - 'NXP\Classes\Token\TokenMinus', - 'NXP\Classes\Token\TokenMultiply', - 'NXP\Classes\Token\TokenDivision', - 'NXP\Classes\Token\TokenDegree', - 'NXP\Classes\Token\TokenAnd', - 'NXP\Classes\Token\TokenOr', - 'NXP\Classes\Token\TokenEqual', - 'NXP\Classes\Token\TokenNotEqual', - 'NXP\Classes\Token\TokenGreaterThanOrEqual', - 'NXP\Classes\Token\TokenGreaterThan', - 'NXP\Classes\Token\TokenLessThanOrEqual', - 'NXP\Classes\Token\TokenLessThan', + \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. + * + * @return array + */ protected function defaultFunctions() { return [ @@ -413,6 +424,11 @@ class MathExecutor ]; } + /** + * Returns the default variables names as key/value pairs + * + * @return array + */ protected function defaultVars() { return [ |