Skip to content

Commit 56dac9c

Browse files
committed
Merge branch 'feat-operators' of github.com:utopia-php/database into feat-operators
2 parents eef05bc + 664b451 commit 56dac9c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/Database/Validator/Operator.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Operator extends Validator
1414
/**
1515
* @var array<string, Document|array<string, mixed>>
1616
*/
17-
protected array $attributes;
17+
protected array $attributes = [];
1818

1919
protected string $message = 'Invalid operator';
2020

@@ -238,10 +238,14 @@ private function validateOperatorForAttribute(
238238
case DatabaseOperator::TYPE_ARRAY_INTERSECT:
239239
case DatabaseOperator::TYPE_ARRAY_DIFF:
240240
if (!$isArray) {
241-
$this->message = "Cannot apply {$method} operator to non-array field '{$operator->getAttribute()}'";
241+
$this->message = "Cannot use {$method} operator on non-array attribute '{$operator->getAttribute()}'";
242242
return false;
243243
}
244244

245+
if (empty($values) || !\is_array($values[0])) {
246+
$this->message = "{$method} operator requires a non-empty array value";
247+
return false;
248+
}
245249

246250
break;
247251
case DatabaseOperator::TYPE_ARRAY_FILTER:

0 commit comments

Comments
 (0)