aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Wells <brucekwells@gmail.com>2020-04-11 03:40:21 +0300
committerGitHub <noreply@github.com>2020-04-11 03:40:21 +0300
commit7198653aef6eab55e1644eea9f16bf0dd0dc2edd (patch)
treee61d76954437062412493fb6436bf092ed4e4b40 /src
parent4955c639e1069ba3d3415d01a3368f09b000c2a7 (diff)
Update documentation for PHPFUI/InstaDoc (#58)
Diffstat (limited to 'src')
-rw-r--r--src/NXP/Classes/Calculator.php6
-rw-r--r--src/NXP/Classes/Lexer.php1
-rw-r--r--src/NXP/Classes/Token/AbstractOperator.php1
-rw-r--r--src/NXP/Classes/TokenFactory.php8
-rw-r--r--src/NXP/MathExecutor.php44
5 files changed, 43 insertions, 17 deletions
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 [