diff options
author | Laria Carolin Chabowski <laria@laria.me> | 2020-09-13 21:44:30 +0200 |
---|---|---|
committer | Laria Carolin Chabowski <laria@laria.me> | 2020-09-13 21:44:30 +0200 |
commit | 11932a471b4ef10faf76b6fcfe30a35f946eb7ab (patch) | |
tree | cde92c5eceef8991033fe7773ab60da51e289af4 /src/ste/Calc.php | |
parent | d7d74d0a714f29515da85078cc826ba49d2913b9 (diff) | |
download | ste-11932a471b4ef10faf76b6fcfe30a35f946eb7ab.tar.gz ste-11932a471b4ef10faf76b6fcfe30a35f946eb7ab.tar.bz2 ste-11932a471b4ef10faf76b6fcfe30a35f946eb7ab.zip |
Use short array syntax
We can use it now that we switched to PHP 7.3
Diffstat (limited to 'src/ste/Calc.php')
-rw-r--r-- | src/ste/Calc.php | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/src/ste/Calc.php b/src/ste/Calc.php index 2f2d09d..9030c08 100644 --- a/src/ste/Calc.php +++ b/src/ste/Calc.php @@ -22,27 +22,27 @@ class Calc */ private static function shunting_yard($infix_math) { - $operators = array( - "+" => array("l", 2), - "-" => array("l", 2), - "*" => array("l", 3), - "/" => array("l", 3), - "^" => array("r", 4), - "_" => array("r", 5), - "(" => array("", 0), - ")" => array("", 0) - ); + $operators = [ + "+" => ["l", 2], + "-" => ["l", 2], + "*" => ["l", 3], + "/" => ["l", 3], + "^" => ["r", 4], + "_" => ["r", 5], + "(" => ["", 0], + ")" => ["", 0] + ]; preg_match_all("/\s*(?:(?:[+\\-\\*\\/\\^\\(\\)])|(\\d*[\\.]?\\d*))\\s*/s", $infix_math, $tokens, PREG_PATTERN_ORDER); $tokens_raw = array_filter(array_map('trim', $tokens[0]), function ($x) { return ($x === "0") || (!empty($x)); }); - $output_queue = array(); - $op_stack = array(); + $output_queue = []; + $op_stack = []; $lastpriority = null; /* Make - unary, if neccessary */ - $tokens = array(); + $tokens = []; foreach ($tokens_raw as $token) { $priority = isset($operators[$token]) ? $operators[$token][1] : -1; if (($token == "-") && (($lastpriority === null) || ($lastpriority >= 0))) { @@ -114,7 +114,7 @@ class Calc */ private static function pop2(&$array) { - $rv = array(array_pop($array), array_pop($array)); + $rv = [array_pop($array), array_pop($array)]; if (array_search(null, $rv, true) !== false) { throw new RuntimeError("Not enough numbers on stack. Invalid formula."); } @@ -128,7 +128,7 @@ class Calc */ private static function calc_rpn($rpn) { - $stack = array(); + $stack = []; foreach ($rpn as $token) { switch ($token) { case "+": |