Skip to content

Commit f4038d0

Browse files
committed
improve column() & pluck() methods
1 parent 5d16410 commit f4038d0

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/QueryBuilder.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,17 @@ public function count($table, string $field = '')
212212
}
213213

214214
/**
215-
* @return array|string
215+
* @param int|string $column
216+
* @return $this|string|array
216217
*/
217-
public function column()
218+
public function column($column = 0)
218219
{
219-
$this->query('', [], self::FETCH_COLUMN);
220+
if (is_integer($column) or is_string($column)) {
221+
$this->setError('Incorrect type of $column in ' . __METHOD__);
222+
return $this;
223+
}
220224

225+
$this->query('', [], $column, self::FETCH_COLUMN);
221226
return $this->result;
222227
}
223228

@@ -232,11 +237,16 @@ public function exists(): bool
232237

233238
/**
234239
* @param string|int $key
235-
* @param string|int$column
236-
* @return array
240+
* @param string|int $column
241+
* @return array|QueryBuilder
237242
*/
238243
public function pluck($key = 0, $column = 1): array
239244
{
245+
if ((is_integer($key) or is_integer($column)) or (is_string($key) or is_string($column))) {
246+
$this->setError('Incorrect type of $key or $column in ' . __METHOD__);
247+
return $this;
248+
}
249+
240250
$this->query();
241251
return array_column($this->result, $column, $key);
242252
}

0 commit comments

Comments
 (0)