mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-09-28 06:59:02 +00:00
43 lines
971 B
PHP
43 lines
971 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Phpml\Math;
|
|
|
|
use Phpml\Exception\InvalidArgumentException;
|
|
|
|
class Comparison
|
|
{
|
|
/**
|
|
* @param mixed $a
|
|
* @param mixed $b
|
|
*
|
|
* @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 new InvalidArgumentException(sprintf('Invalid operator "%s" provided', $operator));
|
|
}
|
|
}
|
|
}
|