diff options
author | Alexander Kiryukhin <a.kiryukhin@mail.ru> | 2020-05-20 22:26:59 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-20 22:26:59 +0300 |
commit | 913cf0a1e8920dbcc18649fa173a0c7e6ba5d5ef (patch) | |
tree | bb1049748d4b6f12209d0a868fb17592b85789ea /src/NXP/Classes | |
parent | 949334d6c37d384800c639ba9941e94f5157f5ac (diff) | |
parent | 2c18fbb2452baa1839f9102b309de1967b30307d (diff) |
Merge pull request #63 from phpfui/neonxp-ngv2.0.0
Update parameters and add back functions
Diffstat (limited to 'src/NXP/Classes')
-rw-r--r-- | src/NXP/Classes/Calculator.php | 2 | ||||
-rw-r--r-- | src/NXP/Classes/CustomFunction.php | 4 | ||||
-rw-r--r-- | src/NXP/Classes/Operator.php | 2 | ||||
-rw-r--r-- | src/NXP/Classes/Tokenizer.php | 20 |
4 files changed, 14 insertions, 14 deletions
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..bf36405 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<Token> $stack */ |