Skip to content

Commit ac6efaa

Browse files
authored
[12.x] add generics to QueryBuilder’s column related methods (#55663)
* [12.x] add generics to QueryBuilder’s column related methods * fix styling * more detailed types * narrow types * more narrowing * not at this time * fix test * use type alias * more use of alias * not now * fix styling * use covariant * fixed * fix styling * dont include string in SubQueryBuilderTypes * reorder * add generics to callback * fix styling * remove type alias * fix singlular name * replace all aliases * revert
1 parent 0900dc5 commit ac6efaa

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/Illuminate/Database/Query/Builder.php

+20-17
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class Builder implements BuilderContract
100100
/**
101101
* The columns that should be returned.
102102
*
103-
* @var array|null
103+
* @var array<string|\Illuminate\Contracts\Database\Query\Expression>|null
104104
*/
105105
public $columns;
106106

@@ -278,7 +278,7 @@ public function __construct(
278278
/**
279279
* Set the columns to be selected.
280280
*
281-
* @param array|mixed $columns
281+
* @param mixed $columns
282282
* @return $this
283283
*/
284284
public function select($columns = ['*'])
@@ -432,7 +432,7 @@ protected function prependDatabaseNameIfCrossDatabaseQuery($query)
432432
/**
433433
* Add a new select column to the query.
434434
*
435-
* @param array|mixed $column
435+
* @param mixed $column
436436
* @return $this
437437
*/
438438
public function addSelect($column)
@@ -3019,7 +3019,7 @@ public function toRawSql()
30193019
* Execute a query for a single record by ID.
30203020
*
30213021
* @param int|string $id
3022-
* @param array|string $columns
3022+
* @param string|\Illuminate\Contracts\Database\Query\Expression|array<string|\Illuminate\Contracts\Database\Query\Expression> $columns
30233023
* @return object|null
30243024
*/
30253025
public function find($id, $columns = ['*'])
@@ -3033,7 +3033,7 @@ public function find($id, $columns = ['*'])
30333033
* @template TValue
30343034
*
30353035
* @param mixed $id
3036-
* @param (\Closure(): TValue)|list<string>|string $columns
3036+
* @param (\Closure(): TValue)|string|\Illuminate\Contracts\Database\Query\Expression|array<string|\Illuminate\Contracts\Database\Query\Expression> $columns
30373037
* @param (\Closure(): TValue)|null $callback
30383038
* @return object|TValue
30393039
*/
@@ -3096,7 +3096,7 @@ public function soleValue($column)
30963096
/**
30973097
* Execute the query as a "select" statement.
30983098
*
3099-
* @param array|string $columns
3099+
* @param string|\Illuminate\Contracts\Database\Query\Expression|array<string|\Illuminate\Contracts\Database\Query\Expression> $columns
31003100
* @return \Illuminate\Support\Collection<int, \stdClass>
31013101
*/
31023102
public function get($columns = ['*'])
@@ -3152,7 +3152,7 @@ protected function withoutGroupLimitKeys($items)
31523152
* Paginate the given query into a simple paginator.
31533153
*
31543154
* @param int|\Closure $perPage
3155-
* @param array|string $columns
3155+
* @param string|\Illuminate\Contracts\Database\Query\Expression|array<string|\Illuminate\Contracts\Database\Query\Expression> $columns
31563156
* @param string $pageName
31573157
* @param int|null $page
31583158
* @param \Closure|int|null $total
@@ -3180,7 +3180,7 @@ public function paginate($perPage = 15, $columns = ['*'], $pageName = 'page', $p
31803180
* This is more efficient on larger data-sets, etc.
31813181
*
31823182
* @param int $perPage
3183-
* @param array|string $columns
3183+
* @param string|\Illuminate\Contracts\Database\Query\Expression|array<string|\Illuminate\Contracts\Database\Query\Expression> $columns
31843184
* @param string $pageName
31853185
* @param int|null $page
31863186
* @return \Illuminate\Contracts\Pagination\Paginator
@@ -3203,7 +3203,7 @@ public function simplePaginate($perPage = 15, $columns = ['*'], $pageName = 'pag
32033203
* This is more efficient on larger data-sets, etc.
32043204
*
32053205
* @param int|null $perPage
3206-
* @param array|string $columns
3206+
* @param string|\Illuminate\Contracts\Database\Query\Expression|array<string|\Illuminate\Contracts\Database\Query\Expression> $columns
32073207
* @param string $cursorName
32083208
* @param \Illuminate\Pagination\Cursor|string|null $cursor
32093209
* @return \Illuminate\Contracts\Pagination\CursorPaginator
@@ -3250,7 +3250,7 @@ protected function ensureOrderForCursorPagination($shouldReverse = false)
32503250
/**
32513251
* Get the count of the total records for the paginator.
32523252
*
3253-
* @param array $columns
3253+
* @param array<string|\Illuminate\Contracts\Database\Query\Expression> $columns
32543254
* @return int
32553255
*/
32563256
public function getCountForPagination($columns = ['*'])
@@ -3272,8 +3272,8 @@ public function getCountForPagination($columns = ['*'])
32723272
/**
32733273
* Run a pagination count query.
32743274
*
3275-
* @param array $columns
3276-
* @return array
3275+
* @param array<string|\Illuminate\Contracts\Database\Query\Expression> $columns
3276+
* @return array<mixed>
32773277
*/
32783278
protected function runPaginationCountQuery($columns = ['*'])
32793279
{
@@ -3313,7 +3313,8 @@ protected function cloneForPaginationCount()
33133313
/**
33143314
* Remove the column aliases since they will break count queries.
33153315
*
3316-
* @return array
3316+
* @param array<string|\Illuminate\Contracts\Database\Query\Expression> $columns
3317+
* @return array<string|\Illuminate\Contracts\Database\Query\Expression>
33173318
*/
33183319
protected function withoutSelectAliases(array $columns)
33193320
{
@@ -3677,9 +3678,11 @@ protected function setAggregate($function, $columns)
36773678
*
36783679
* After running the callback, the columns are reset to the original value.
36793680
*
3680-
* @param array $columns
3681-
* @param callable $callback
3682-
* @return mixed
3681+
* @template TResult
3682+
*
3683+
* @param array<string|\Illuminate\Contracts\Database\Query\Expression> $columns
3684+
* @param callable(): TResult $callback
3685+
* @return TResult
36833686
*/
36843687
protected function onceWithColumns($columns, $callback)
36853688
{
@@ -4081,7 +4084,7 @@ protected function forSubQuery()
40814084
/**
40824085
* Get all of the query builder's columns in a text-only array with all expressions evaluated.
40834086
*
4084-
* @return array
4087+
* @return list<string>
40854088
*/
40864089
public function getColumns()
40874090
{

0 commit comments

Comments
 (0)