diff options
Diffstat (limited to 'src/NXP/Classes/Operator.php')
-rw-r--r-- | src/NXP/Classes/Operator.php | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/src/NXP/Classes/Operator.php b/src/NXP/Classes/Operator.php index 1b1acc4..7dee06d 100644 --- a/src/NXP/Classes/Operator.php +++ b/src/NXP/Classes/Operator.php @@ -7,37 +7,21 @@ use ReflectionFunction; class Operator { - /** - * @var string - */ - public $operator; + public string $operator = ''; - /** - * @var bool - */ - public $isRightAssoc; + public bool $isRightAssoc = false; - /** - * @var int - */ - public $priority; + public int $priority = 0; /** * @var callable(\SplStack) */ public $function; - /** - * @var int - */ - public $places; + public int $places = 0; /** * Operator constructor. - * @param string $operator - * @param bool $isRightAssoc - * @param int $priority - * @param callable $function */ public function __construct(string $operator, bool $isRightAssoc, int $priority, callable $function) { @@ -54,17 +38,18 @@ class Operator * * @throws IncorrectExpressionException */ - public function execute(array &$stack): Token + public function execute(array &$stack) : Token { - if (count($stack) < $this->places) { + if (\count($stack) < $this->places) { throw new IncorrectExpressionException(); } $args = []; + for ($i = 0; $i < $this->places; $i++) { - array_unshift($args, array_pop($stack)->value); + \array_unshift($args, \array_pop($stack)->value); } - $result = call_user_func_array($this->function, $args); + $result = \call_user_func_array($this->function, $args); return new Token(Token::Literal, $result); } |