| Total Complexity | 6 |
| Total Lines | 42 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | use function count; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Class SimpleCondition represents a simple condition like `"column" operator value`. |
||
| 18 | */ |
||
| 19 | class SimpleCondition implements SimpleConditionInterface |
||
| 20 | { |
||
| 21 | public function __construct( |
||
| 22 | private string|Expression|QueryInterface $column, |
||
| 23 | private string $operator, |
||
| 24 | private array|int|string|Iterator|ExpressionInterface|null $value |
||
| 25 | ) { |
||
| 26 | } |
||
| 27 | |||
| 28 | public function getColumn(): string|Expression|QueryInterface |
||
| 29 | { |
||
| 30 | return $this->column; |
||
| 31 | } |
||
| 32 | |||
| 33 | public function getOperator(): string |
||
| 34 | { |
||
| 35 | return $this->operator; |
||
| 36 | } |
||
| 37 | |||
| 38 | public function getValue(): array|int|string|Iterator|ExpressionInterface|null |
||
| 39 | { |
||
| 40 | return $this->value; |
||
| 41 | } |
||
| 42 | |||
| 43 | public static function fromArrayDefinition(string $operator, array $operands): self |
||
| 44 | { |
||
| 45 | if (count($operands) !== 2) { |
||
| 46 | throw new InvalidArgumentException("Operator '$operator' requires two operands."); |
||
| 47 | } |
||
| 48 | |||
| 49 | return new static($operands[0], $operator, $operands[1]); |
||
| 50 | } |
||
| 51 | } |
||
| 52 |