mirror of
https://github.com/Llewellynvdm/php-ml.git
synced 2024-09-26 14:09:04 +00:00
f4650c696c
* fix imports order * drop unused docs typehints, make use of return types where possible
40 lines
888 B
PHP
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);
|
|
}
|
|
}
|
|
}
|