Skip to content

Commit 17dd2e3

Browse files
authored
update _whereIn to throw on invalid types
Currently if a string is passed into _whereIn it is the object is returned without any issue. This can be misleading. We should throw an exception when the wrong type has been provided.
1 parent 09b17fc commit 17dd2e3

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

system/Database/BaseBuilder.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,14 +979,20 @@ public function orHavingNotIn(string $key = null, $values = null, bool $escape =
979979
* @param string $type
980980
* @param boolean $escape
981981
* @param string $clause (Internal use only)
982+
* @throws InvalidArgumentException
982983
*
983984
* @return BaseBuilder
984985
*/
985986
protected function _whereIn(string $key = null, $values = null, bool $not = false, string $type = 'AND ', bool $escape = null, string $clause = 'QBWhere')
986987
{
987-
if ($key === null || $values === null)
988+
if (empty($key) || ! is_string($key))
988989
{
989-
return $this;
990+
throw new InvalidArgumentException(sprintf('%s() expects $key to be a non-empty string', debug_backtrace(0, 2)[1]['function']));
991+
}
992+
993+
if ($values === null || (! is_array($values) && ! ($values instanceof Closure)))
994+
{
995+
throw new InvalidArgumentException(sprintf('%s() expects $values to be of type array or closure', debug_backtrace(0, 2)[1]['function']));
990996
}
991997

992998
is_bool($escape) || $escape = $this->db->protectIdentifiers;

0 commit comments

Comments
 (0)