"{value} >= 5 || {value} < 6.7",
"{value} !== 'test' && {value} === true'
class Comparator
{
private $value;
private $compareValue;
public function __construct($value, $compareValue = null)
{
$this->value = $value;
$this->compareValue = $compareValue;
// for float comparison
if (is_numeric($this->value) && is_numeric($this->compareValue)) {
$this->value *= 100;
$this->compareValue *= 100;
}
}
public function equals(): bool
{
return $this->value === $this->compareValue;
}
public function notEquals(): bool
{
return $this->value !== $this->compareValue;
}
public function greaterThan(): bool
{
return $this->value > $this->compareValue;
}
public function greaterThanOrEqual(): bool
{
return $this->value >= $this->compareValue;
}
public function lessThan(): bool
{
return $this->value < $this->compareValue;
}
public function lessThanOrEqual(): bool
{
return $this->value <= $this->compareValue;
}
public function isNull(): bool
{
return $this->value === null;
}
public function isNotNull(): bool
{
return $this->value !== null;
}
public function isTrue(): bool
{
return $this->value === true;
}
public function isFalse(): bool
{
return !$this->isTrue();
}
public function and(): bool
{
return $this->value && $this->compareValue;
}
public function or(): bool
{
return $this->value || $this->compareValue;
}
}
/*
"{value} >= 5 || {value} < 6.7",
"{value} !== 'test' && {value} === true'
*/
$compare = new Comparator(10, 5);
$c1 = $compare->greaterThanOrEqual();
$compare = new Comparator(10.3, 6.7);
$c2 = $compare->lessThan();
var_dump($c1);
var_dump($c2);
$compare = new Comparator($c1, $c2);
$c3 = $compare->or();
var_dump($c3);