summaryrefslogtreecommitdiff
path: root/src/ste/Calc.php
diff options
context:
space:
mode:
authorLaria Carolin Chabowski <laria@laria.me>2020-09-13 22:25:15 +0200
committerLaria Carolin Chabowski <laria@laria.me>2020-09-13 22:25:15 +0200
commit76a1e915e0eea54b9b9a01d921efa6f9edffb3a8 (patch)
tree2d3140702e971cbe492561fea0f2d4c512366c07 /src/ste/Calc.php
parent2bbb1646f56fe84f38ed2a0cba03a386acc6160e (diff)
downloadste-76a1e915e0eea54b9b9a01d921efa6f9edffb3a8.tar.gz
ste-76a1e915e0eea54b9b9a01d921efa6f9edffb3a8.tar.bz2
ste-76a1e915e0eea54b9b9a01d921efa6f9edffb3a8.zip
Code cleanup
- Add parameter and return types - Add missing @throws tags - Add visibilities to consts
Diffstat (limited to 'src/ste/Calc.php')
-rw-r--r--src/ste/Calc.php8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/ste/Calc.php b/src/ste/Calc.php
index 9030c08..660943d 100644
--- a/src/ste/Calc.php
+++ b/src/ste/Calc.php
@@ -20,7 +20,7 @@ class Calc
* @return array
* @throws RuntimeError
*/
- private static function shunting_yard($infix_math)
+ private static function shunting_yard(string $infix_math): array
{
$operators = [
"+" => ["l", 2],
@@ -112,7 +112,7 @@ class Calc
* @return array
* @throws RuntimeError
*/
- private static function pop2(&$array)
+ private static function pop2(array &$array): array
{
$rv = [array_pop($array), array_pop($array)];
if (array_search(null, $rv, true) !== false) {
@@ -126,7 +126,7 @@ class Calc
* @return int|float
* @throws RuntimeError
*/
- private static function calc_rpn($rpn)
+ private static function calc_rpn(array $rpn)
{
$stack = [];
foreach ($rpn as $token) {
@@ -174,7 +174,7 @@ class Calc
* @return float|int
* @throws RuntimeError
*/
- public static function calc($expr)
+ public static function calc(string $expr)
{
return self::calc_rpn(self::shunting_yard($expr));
}