for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php namespace Arcanedev\Units\Traits;
/**
* Trait Calculatable
*
* @package Arcanedev\Units\Traits
* @author ARCANEDEV <[email protected]>
*/
trait Calculatable
{
* Calculate the value.
* @param float|int $a
* @param string $operator
* @param float|int $b
* @return float|int
protected static function calculate($a, $operator, $b)
switch ($operator) {
case '+':
return $a + $b;
case '-':
return $a - $b;
case 'x':
case '*':
return $a * $b;
case '/':
return $a / $b;
case '^':
return pow($a, $b);
}
return $a;