Merge pull request #27 from NeonXP/dev

Dev
This commit is contained in:
Alexander Kiryukhin 2018-09-06 20:41:20 +03:00 committed by GitHub
commit 2a629d37dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View file

@ -40,7 +40,7 @@ class Calculator
if ($token instanceof TokenVariable) {
$variable = $token->getValue();
if (!array_key_exists($variable, $variables)) {
throw new UnknownVariableException();
throw new UnknownVariableException($variable);
}
$value = $variables[$variable];
array_push($stack, new TokenNumber($value));

View file

@ -73,7 +73,7 @@ class TokenFactory
$class = new \ReflectionClass($operatorClass);
if (!in_array('NXP\Classes\Token\InterfaceToken', $class->getInterfaceNames())) {
throw new UnknownOperatorException;
throw new UnknownOperatorException($operatorClass);
}
$this->operators[] = $operatorClass;
@ -162,10 +162,10 @@ class TokenFactory
if (isset($this->functions[$token])) {
return new TokenFunction($this->functions[$token]);
} else {
throw new UnknownFunctionException();
throw new UnknownFunctionException($token);
}
}
throw new UnknownTokenException();
throw new UnknownTokenException($token);
}
}

View file

@ -91,6 +91,10 @@ class MathExecutor
*/
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;