Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00%
0 / 1
40.00%
2 / 5
CRAP
72.73%
8 / 11
Comparison
0.00%
0 / 1
40.00%
2 / 5
6.73
72.73%
8 / 11
 __construct($field, $operator, $value)
100.00%
1 / 1
2
100.00%
7 / 7
 getField()
0.00%
0 / 1
2
0.00%
0 / 1
 getValue()
0.00%
0 / 1
2
0.00%
0 / 1
 getOperator()
100.00%
1 / 1
1
100.00%
1 / 1
 visit(ExpressionVisitor $visitor)
0.00%
0 / 1
2
0.00%
0 / 1
<?php
// Copyright (c) Lellys Informática. All rights reserved. See License.txt in the project root for license information.
namespace Easy\Collections\Linq\Expr;
/**
 * Comparison of a field with a value by the given operator.
 *
 * @author Benjamin Eberlei <kontakt@beberlei.de>
 * @since  2.3
 */
class Comparison implements Expression
{
    const EQ = '=';
    const NEQ = '<>';
    const LT = '<';
    const LTE = '<=';
    const GT = '>';
    const GTE = '>=';
    const IS = '='; // no difference with EQ
    const IN = 'IN';
    const NIN = 'NIN';
    const CONTAINS = 'CONTAINS';
    const STARTS_WITH = 'STARTS_WITH';
    const ENDS_WITH = 'ENDS_WITH';
    /**
     * @var string
     */
    private $field;
    /**
     * @var string
     */
    private $op;
    /**
     * @var Value
     */
    private $value;
    /**
     * @param string $field
     * @param string $operator
     * @param mixed  $value
     */
    public function __construct($field, $operator, $value)
    {
        if (!($value instanceof Value)) {
            $value = new Value($value);
        }
        $this->field = $field;
        $this->op = $operator;
        $this->value = $value;
    }
    /**
     * @return string
     */
    public function getField()
    {
        return $this->field;
    }
    /**
     * @return Value
     */
    public function getValue()
    {
        return $this->value;
    }
    /**
     * @return string
     */
    public function getOperator()
    {
        return $this->op;
    }
    /**
     * {@inheritDoc}
     */
    public function visit(ExpressionVisitor $visitor)
    {
        return $visitor->walkComparison($this);
    }
}