Evaluate an operator

@param mixed $value
@param string $operator
@param mixed $operand
@return boolean
332289
protected function evaluateOperator($value, $operator, $operand)
    {
        switch ($operator) {
            case '=':
                return $value === $operand;
            case '!=':
                return $value !== $operand;
            case '<':
                return $value < $operand;
            case '<=':
                return $value <= $operand;
            case '>':
                return $value > $operand;
            case '>=':
                return $value >= $operand;
            case '$=':
                if (is_array($value)) {
                    if ($this->evaluateOperator(end($value), '=', $operand)) {
                        return true;
                    }
                    return false;
                } else {
                    return strrpos($value, (string)$operand) === strlen($value) - strlen($operand);
                }
            case '^=':
                if (is_array($value)) {
                    if ($this->evaluateOperator(reset($value), '=', $operand)) {
                        return true;
                    }
                    return false;
                } else {
                    return strpos($value, (string)$operand) === 0;
                }
            case '*=':
                if (is_array($value)) {
                    foreach ($value as $item) {
                        if ($this->evaluateOperator($item, '=', $operand)) {
                            return true;
                        }
                    }
                    return false;
                } else {
                    return strpos($value, (string)$operand) !== false;
                }
            case 'instanceof':
                if ($this->operandIsSimpleType($operand)) {
                    return $this->handleSimpleTypeOperand($operand, $value);
                } else {
                    return ($value instanceof $operand);
                }
            case '!instanceof':
                if ($this->operandIsSimpleType($operand)) {
                    return !$this->handleSimpleTypeOperand($operand, $value);
                } else {
                    return !($value instanceof $operand);
                }
            default:
                return ($value !== null);
        }
    }
884235
public function operator($operator, $value)
    {
        $this->wrapEqualityCriteria();

        if ($this->currentField) {
            $this->query[$this->currentField][$operator] = $value;
        } else {
            $this->query[$operator] = $value;
        }
        return $this;
    }
1121675
protected function equality($comparison, $operand)
    {
        return $this->expr->addCondition(new Operator\Equality(
            $this,
            $comparison,
            $this->expr->value($operand)
        ));
    }
186710
private function validateComparisonOperators($value) 
    {
        $operator = strtoupper(trim($value));
        $isValid = in_array($operator, $this->comparisonOperators);
        
        if($isValid === true) {
            return $operator;
        } 
        
        throw new \Exception("Comparison operator $value is not supported.");
    }
1333700
protected static function parseComparisonOperator($value, $is_negation)
    {
        if (preg_match('/^\((gt|ge|lt|le)\)(.+)$/', $value, $match)) {
            $operator = null;
            switch ($match[1]) {
                case 'gt':
                    $operator = $is_negation ? static::OPERATOR_LESS_EQUAL : static::OPERATOR_GREATER;
                    break;
                case 'ge':
                    $operator = $is_negation ? static::OPERATOR_LESS : static::OPERATOR_GREATER_EQUAL;
                    break;
                case 'lt':
                    $operator = $is_negation ? static::OPERATOR_GREATER_EQUAL : static::OPERATOR_LESS;
                    break;
                case 'le':
                    $operator = $is_negation ? static::OPERATOR_GREATER : static::OPERATOR_LESS_EQUAL;
                    break;
            }

            $value = $match[2];

            return [$operator, $value];
        }

        return false;
    }
1131065
public function where($operand, $operatorOrValue=null, $value=null)
    {
        return $this->addWhere($operand, $operatorOrValue, $value, 'and', func_num_args());
    }
585773
public static function doUnaryOperation($operator, &$value)
    {
        if (self::$unaryOperations === null) {
            self::$unaryOperations = [
                    self::BITWISE_NOT   => function (&$i) { return ~$i; },
                    self::NOT           => function (&$i) { return !$i; },
                    self::INCREMENT     => function (&$i) { return $i++; },
                    self::DECREMENT     => function (&$i) { return $i--; },
                    self::PRE_INCREMENT => function (&$i) { return ++$i; },
                    self::PRE_DECREMENT => function (&$i) { return --$i; },
                    self::NEGATION      => function (&$i) { return -$i; },
                    self::PLUS          => function (&$i) { return +$i; },
            ];
        }

        if (!isset(self::$unaryOperations[$operator])) {
            throw new PinqException('Unary operator \'%s\' is not supported', $operator);
        }

        $operation = self::$unaryOperations[$operator];

        return $operation($value);
    }
494323
protected static function parseOperatorAndValue($value, $is_negation)
    {
        if ($result = static::parseComparisonOperator($value, $is_negation)) {
            return $result;
        }

        if ($result = static::parseLikeOperator($value, $is_negation)) {
            return $result;
        }

        if ($result = static::parseNullOperator($value, $is_negation)) {
            return $result;
        }

        if ($result = static::parseEqualsInOperator($value, $is_negation)) {
            return $result;
        }

        throw new InvalidArgumentException(sprintf('Unable to parse operator or value from "%s"', $value));
    }
749964
public function where($field, $operator, $value = null)
    {
        if (is_null($value)) {
            $value    = $operator;
            $operator = '=';
        }

        return $this->filter(function ($data) use ($field, $operator, $value) {
            if (strpos($field, '.')) {
                list($field, $relation) = explode('.', $field);

                $result = isset($data[$field][$relation]) ? $data[$field][$relation] : null;
            } else {
                $result = isset($data[$field]) ? $data[$field] : null;
            }

            switch ($operator) {
                case '===':
                    return $result === $value;
                case '!==':
                    return $result !== $value;
                case '!=':
                case '<>':
                    return $result != $value;
                case '>':
                    return $result > $value;
                case '>=':
                    return $result >= $value;
                case '<':
                    return $result < $value;
                case '<=':
                    return $result <= $value;
                case 'like':
                    return is_string($result) && false !== strpos($result, $value);
                case 'not like':
                    return is_string($result) && false === strpos($result, $value);
                case 'in':
                    return is_scalar($result) && in_array($result, $value, true);
                case 'not in':
                    return is_scalar($result) && !in_array($result, $value, true);
                case 'between':
                    list($min, $max) = is_string($value) ? explode(',', $value) : $value;
                    return is_scalar($result) && $result >= $min && $result <= $max;
                case 'not between':
                    list($min, $max) = is_string($value) ? explode(',', $value) : $value;
                    return is_scalar($result) && $result > $max || $result < $min;
                case '==':
                case '=':
                default:
                    return $result == $value;
            }
        });
    }
796803
public function jsonOperator($key, $operator, $value = null)
    {
        if (func_num_args() === 2) {
            $value = $operator;
            $operator = '=';
        }

        return function ($item) use ($key, $operator, $value) {
            $column = $key;
            if(Str::contains($key, '->')) {
                $explodeKey = explode('->', $key);
                $column = $explodeKey[0];
                $key = $explodeKey[1];
            }

            $retrieved = data_get($item, $column.'.'.$key, null, true);

            $strings = array_filter(
                [$retrieved, $value], function ($value) {
                    return is_string($value) || (is_object($value) && method_exists($value, '__toString'));
                }
            );

            if (count($strings) < 2 && count(array_filter([$retrieved, $value], 'is_object')) == 1) {
                return in_array($operator, ['!=', '<>', '!==']);
            }

            switch ($operator) {
            default:
            case '=':
            case '==':  
                return $retrieved == $value;
            case '!=':
            case '<>':  
                return $retrieved != $value;
            case '<':   
                return $retrieved < $value;
            case '>':   
                return $retrieved > $value;
            case '<=':  
                return $retrieved <= $value;
            case '>=':  
                return $retrieved >= $value;
            case '===': 
                return $retrieved === $value;
            case '!==': 
                return $retrieved !== $value;
            }
        };
    }
535531
protected function checkOperand($operand)
    {
        if (!is_scalar($operand) && !$operand instanceof ExpressionContract) {
            throw new InvalidArgumentException('Condition only acceps scalars and Expression, not ' . Type::of($operand));
        }
        return $operand;
    }
249973
static public BooleanExpression OR(Collection<? extends BooleanExpression> operands){
		BooleanExpression result = new BooleanExpression(OPERATOR_OR);
		result.addOperand(operands);
		return result;
	}
1174960
public function where($field, $operator = null, $value = null, $boolean = 'AND')
    {
        // If the developer is adding multiple where statements together,
        // we will enforce that by adding the approriate boolean.

        if ($this->condition && count($this->condition) > 0) {
            $this->condition[] = $boolean;
        }

        // Here we will make some assumptions about the operator. If only two values
        // are passed in, we will assume the operator is an equals sign. Furthermore,
        // we will identify if the value is null and apply the respective operator.

        list($value, $operator) = $this->prepareValueAndOperator(
            $value, $operator, func_num_args() == 2
        );

        $this->condition[] = [
            'field' => compact('field'),
            'op' => $operator,
            'value' => $value
        ];

        return $this;
    }
1174562
private function normalizeValue(string $value, string $operator)
    {
        if (!is_numeric($value)) {
            $this->getLogger()->notice('Invalid filter ignored', [
                'exception' => new InvalidArgumentException(sprintf('Invalid value for "[%s]", expected number', $operator)),
            ]);

            return null;
        }

        return $value + 0; // coerce $value to the right type.
    }
465092
private function addOperator($operator, $field, $value) {
		$this->is($field, array('$' . $operator => $value));
		
		return $this;
	}
294260
protected function match($operator, $pattern, $value)
    {
        $value   = strtolower($value);
        $pattern = strtolower($pattern);
        switch ($operator) {
            case '=':
                return $value === $pattern;
            case '!=':
                return $value !== $pattern;
            case '^=':
                return preg_match('/^'.preg_quote($pattern, '/').'/', $value);
            case '$=':
                return preg_match('/'.preg_quote($pattern, '/').'$/', $value);
            case '*=':
                if ($pattern[0] == '/') {
                    return preg_match($pattern, $value);
                }

                return preg_match("/".$pattern."/i", $value);
        }

        return false;
    }
619660
public function process()
    {
        $operands = $this->getOperands();

        if (count($operands) === 0) {
            return null;
        }

        if ($operands->exclusivelySingleOrMultiple() === false) {
            $msg = "The Multiple operator only accepts operands with single or omultiple cardinality.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        }

        $refType = null;
        $returnValue = null;

        foreach ($operands as $operand) {

            if (is_null($operand) || ($operand instanceof MultipleContainer && $operand->isNull())) {
                // As per specs, ignore.
                continue;
            } else {
                if ($refType !== null) {
                    // A reference type as already been identified.
                    if (CommonUtils::inferBaseType($operand) === $refType) {
                        // $operand can be added to $returnValue.
                        static::appendValue($returnValue, $operand);
                    } else {
                        // baseType mismatch.
                        $msg = "The Multiple operator only accepts values with a similar baseType.";
                        throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
                    }
                } elseif (($discoveryType = CommonUtils::inferBaseType($operand)) !== false) {
                    // First value being identified as non-null.
                    $refType = $discoveryType;
                    $returnValue = new MultipleContainer($refType);
                    static::appendValue($returnValue, $operand);
                }
            }
        }

        return $returnValue;
    }