Skip to content

Commit

Permalink
check for non associative arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
fjafari committed Sep 30, 2022
1 parent 6d51cdb commit 2009cd2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Query/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,13 @@ protected function _getBaseName()

return Util::toSnakeCase($shortName);
}

public function isNotAssociativeArray(array $arr)
{
if ([] === $arr) {
return true;
}

return \array_keys($arr) === \range(0, \count($arr) - 1);
}
}
4 changes: 4 additions & 0 deletions src/Query/BoolQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ protected function _addQuery(string $type, $args): self
throw new InvalidException('Invalid parameter. Has to be array or instance of Elastica\Query\AbstractQuery');
}

if (\is_array($args) && $this->isNotAssociativeArray($args)) {
throw new InvalidException('Invalid parameter. The array must be an associative array.');
}

return $this->addParam($type, $args);
}
}

0 comments on commit 2009cd2

Please sign in to comment.