JBZoo\SimpleTypes\Type\Type::compare PHP Method

compare() public method

public compare ( mixed $value, string $mode = '==', integer $round = Formatter::ROUND_DEFAULT ) : boolean
$value mixed
$mode string
$round integer
return boolean
    public function compare($value, $mode = '==', $round = Formatter::ROUND_DEFAULT)
    {
        // prepare value
        $value = $this->getValidValue($value);
        $mode = trim($mode);
        $mode = in_array($mode, array('=', '==', '==='), true) ? '==' : $mode;
        $round = null === $round ? Formatter::ROUND_DEFAULT : (int) $round;
        $val1 = round((double) $this->val($this->_rule), $round);
        $val2 = round((double) $value->val($this->_rule), $round);
        $this->log("Compared \"{$this->dump(false)}\" {$mode} " . "\"{$value->dump(false)}\" // {$val1} {$mode} {$val2}, r={$round}, ");
        if ($mode === '==') {
            return $val1 === $val2;
        } elseif ($mode === '!=' || $mode === '!==') {
            return $val1 !== $val2;
        } elseif ($mode === '<') {
            return $val1 < $val2;
        } elseif ($mode === '>') {
            return $val1 > $val2;
        } elseif ($mode === '<=') {
            return $val1 <= $val2;
        } elseif ($mode === '>=') {
            return $val1 >= $val2;
        }
        throw new Exception($this->_type . ': Undefined compare mode: ' . $mode);
    }