Passed
Branch psalm-3 (d5d890)
by Wilmer
02:56
created

LikeCondition   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 40
rs 10
c 0
b 0
f 0
wmc 5
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Query\Conditions;
6
7
use Iterator;
8
use Yiisoft\Db\Exception\InvalidArgumentException;
9
use Yiisoft\Db\Expression\Expression;
10
use Yiisoft\Db\Expression\ExpressionInterface;
11
use Yiisoft\Db\Query\Conditions\Interface\LikeConditionInterface;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_INTERFACE, expecting T_STRING or '{' on line 11 at column 32
Loading history...
12
13
/**
14
 * Class LikeCondition represents a `LIKE` condition.
15
 */
16
class LikeCondition implements LikeConditionInterface
17
{
18
    protected ?array $escapingReplacements = [];
19
20
    public function __construct(
21
        private string|Expression $column,
22
        private string $operator,
23
        private array|int|string|Iterator|ExpressionInterface|null $value
24
    ) {
25
    }
26
27
    public function getColumn(): string|Expression
28
    {
29
        return $this->column;
30
    }
31
32
    public function getEscapingReplacements(): ?array
33
    {
34
        return $this->escapingReplacements;
35
    }
36
37
    public function getOperator(): string
38
    {
39
        return $this->operator;
40
    }
41
42
    public function getValue(): array|int|string|Iterator|ExpressionInterface|null
43
    {
44
        return $this->value;
45
    }
46
47
    public function setEscapingReplacements(array|null $escapingReplacements): void
48
    {
49
        $this->escapingReplacements = $escapingReplacements;
50
    }
51
52
    public static function fromArrayDefinition(string $operator, array $operands): self
53
    {
54
        if (!isset($operands[0], $operands[1])) {
55
            throw new InvalidArgumentException("Operator '$operator' requires two operands.");
56
        }
57
58
        $condition = new static($operands[0], $operator, $operands[1]);
59
60
        if (array_key_exists(2, $operands)) {
61
            $condition->setEscapingReplacements($operands[2]);
62
        }
63
64
        return $condition;
65
    }
66
}
67