|
7 | 7 | use Purist\Specification\Doctrine\AbstractSpecification; |
8 | 8 | use Purist\Specification\Doctrine\Exception\InvalidArgumentException; |
9 | 9 |
|
10 | | -class Comparison extends AbstractSpecification |
| 10 | +readonly class Comparison extends AbstractSpecification |
11 | 11 | { |
12 | 12 | public const string EQ = '='; |
13 | | - |
14 | 13 | public const string NEQ = '<>'; |
15 | | - |
16 | 14 | public const string LT = '<'; |
17 | | - |
18 | 15 | public const string LTE = '<='; |
19 | | - |
20 | 16 | public const string GT = '>'; |
21 | | - |
22 | 17 | public const string GTE = '>='; |
23 | | - |
24 | 18 | public const string LIKE = 'LIKE'; |
25 | | - |
26 | 19 | /** |
27 | 20 | * @var string[] |
28 | 21 | */ |
29 | | - protected static array $operators = [self::EQ, self::NEQ, self::LT, self::LTE, self::GT, self::GTE, self::LIKE]; |
30 | | - protected string $operator; |
| 22 | + protected const array OPERATORS = [self::EQ, self::NEQ, self::LT, self::LTE, self::GT, self::GTE, self::LIKE]; |
31 | 23 |
|
32 | 24 | /** |
33 | 25 | * @throws InvalidArgumentException |
34 | 26 | */ |
35 | | - public function __construct(string $operator, string $field, protected string $value, ?string $dqlAlias = null) |
| 27 | + public function __construct(protected string $operator, string $field, protected string $value, ?string $dqlAlias = null) |
36 | 28 | { |
37 | | - if (!in_array($operator, self::$operators, true)) { |
38 | | - throw new InvalidArgumentException(sprintf('"%s" is not a valid operator. Valid operators: %s', $operator, implode(', ', self::$operators))); |
| 29 | + if (!in_array($operator, self::OPERATORS, true)) { |
| 30 | + throw new InvalidArgumentException(sprintf('"%s" is not a valid operator. Valid operators: %s', $operator, implode(', ', self::OPERATORS))); |
39 | 31 | } |
40 | 32 |
|
41 | | - $this->operator = $operator; |
42 | | - |
43 | 33 | parent::__construct($field, $dqlAlias); |
44 | 34 | } |
45 | 35 |
|
|
0 commit comments