php-ml/src/Phpml/Math/Comparison.php
Tomáš Votruba f4650c696c [coding standard] fix imports order and drop unused docs typehints (#145)
* fix imports order

* drop unused docs typehints, make use of return types where possible
2017-11-06 08:56:37 +01:00

40 lines
888 B
PHP

<?php
declare(strict_types=1);
namespace Phpml\Math;
use Phpml\Exception\InvalidArgumentException;
class Comparison
{
/**
* @throws InvalidArgumentException
*/
public static function compare($a, $b, string $operator): bool
{
switch ($operator) {
case '>':
return $a > $b;
case '>=':
return $a >= $b;
case '=':
case '==':
return $a == $b;
case '===':
return $a === $b;
case '<=':
return $a <= $b;
case '<':
return $a < $b;
case '!=':
case '<>':
return $a != $b;
case '!==':
return $a !== $b;
default:
throw InvalidArgumentException::invalidOperator($operator);
}
}
}