Skip to content

Commit 5b34eac

Browse files
committed
Introduce TFetchMode generic to enhance PHPDoc support for different PDO fetch modes in Query Builder
1 parent 4cd413b commit 5b34eac

21 files changed

+146
-71
lines changed

src/Illuminate/Auth/Passwords/DatabaseTokenRepository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function getConnection()
227227
/**
228228
* Begin a new database query against the table.
229229
*
230-
* @return \Illuminate\Database\Query\Builder
230+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
231231
*/
232232
protected function getTable()
233233
{

src/Illuminate/Cache/DatabaseStore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public function flush()
424424
/**
425425
* Get a query builder for the cache table.
426426
*
427-
* @return \Illuminate\Database\Query\Builder
427+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
428428
*/
429429
protected function table()
430430
{

src/Illuminate/Database/Capsule/Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function connection($connection = null)
8080
* @param \Closure|\Illuminate\Database\Query\Builder|string $table
8181
* @param string|null $as
8282
* @param string|null $connection
83-
* @return \Illuminate\Database\Query\Builder
83+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
8484
*/
8585
public static function table($table, $as = null, $connection = null)
8686
{

src/Illuminate/Database/Concerns/BuildsQueries.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
/**
2323
* @template TValue
24+
* @template TFetchMode of \PDO::FETCH_*|false
2425
*
2526
* @mixin \Illuminate\Database\Eloquent\Builder
2627
* @mixin \Illuminate\Database\Query\Builder
@@ -337,7 +338,7 @@ protected function orderedLazyById($chunkSize = 1000, $column = null, $alias = n
337338
* Execute the query and get the first result.
338339
*
339340
* @param array|string $columns
340-
* @return TValue|null
341+
* @return (TFetchMode is false ? TValue : (TFetchMode is 1|5|8|9 ? object : array))|null
341342
*/
342343
public function first($columns = ['*'])
343344
{
@@ -349,7 +350,7 @@ public function first($columns = ['*'])
349350
*
350351
* @param array|string $columns
351352
* @param string|null $message
352-
* @return TValue
353+
* @return (TFetchMode is false ? TValue : (TFetchMode is 1|5|8|9 ? object : array))
353354
*
354355
* @throws \Illuminate\Database\RecordNotFoundException
355356
*/
@@ -366,7 +367,7 @@ public function firstOrFail($columns = ['*'], $message = null)
366367
* Execute the query and get the first result if it's the sole matching record.
367368
*
368369
* @param array|string $columns
369-
* @return TValue
370+
* @return (TFetchMode is false ? TValue : (TFetchMode is 1|5|8|9 ? object : array))
370371
*
371372
* @throws \Illuminate\Database\RecordsNotFoundException
372373
* @throws \Illuminate\Database\MultipleRecordsFoundException

src/Illuminate/Database/Connection.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function getSchemaBuilder()
312312
*
313313
* @param \Closure|\Illuminate\Database\Query\Builder|\Illuminate\Contracts\Database\Query\Expression|string $table
314314
* @param string|null $as
315-
* @return \Illuminate\Database\Query\Builder
315+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
316316
*/
317317
public function table($table, $as = null)
318318
{
@@ -322,7 +322,7 @@ public function table($table, $as = null)
322322
/**
323323
* Get a new query builder instance.
324324
*
325-
* @return \Illuminate\Database\Query\Builder
325+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
326326
*/
327327
public function query()
328328
{
@@ -661,8 +661,10 @@ public function pretend(Closure $callback)
661661
/**
662662
* Execute the given callback without "pretending".
663663
*
664-
* @param \Closure $callback
665-
* @return mixed
664+
* @template TResult
665+
*
666+
* @param \Closure():TResult $callback
667+
* @return TResult
666668
*/
667669
public function withoutPretending(Closure $callback)
668670
{
@@ -682,8 +684,10 @@ public function withoutPretending(Closure $callback)
682684
/**
683685
* Execute the given callback in "dry run" mode.
684686
*
685-
* @param \Closure $callback
686-
* @return array
687+
* @template TResult of array
688+
*
689+
* @param \Closure():TResult $callback
690+
* @return TResult
687691
*/
688692
protected function withFreshQueryLog($callback)
689693
{

src/Illuminate/Database/ConnectionInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ interface ConnectionInterface
1111
*
1212
* @param \Closure|\Illuminate\Database\Query\Builder|string $table
1313
* @param string|null $as
14-
* @return \Illuminate\Database\Query\Builder
14+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
1515
*/
1616
public function table($table, $as = null);
1717

src/Illuminate/Database/Eloquent/Builder.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*/
3434
class Builder implements BuilderContract
3535
{
36-
/** @use \Illuminate\Database\Concerns\BuildsQueries<TModel> */
36+
/** @use \Illuminate\Database\Concerns\BuildsQueries<TModel,false> */
3737
use BuildsQueries, ForwardsCalls, QueriesRelationships {
3838
BuildsQueries::sole as baseSole;
3939
}
@@ -1797,7 +1797,7 @@ protected function getUnionBuilders()
17971797
/**
17981798
* Get the underlying query builder instance.
17991799
*
1800-
* @return \Illuminate\Database\Query\Builder
1800+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
18011801
*/
18021802
public function getQuery()
18031803
{
@@ -1820,7 +1820,7 @@ public function setQuery($query)
18201820
/**
18211821
* Get a base query builder instance.
18221822
*
1823-
* @return \Illuminate\Database\Query\Builder
1823+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
18241824
*/
18251825
public function toBase()
18261826
{

src/Illuminate/Database/Eloquent/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1607,7 +1607,7 @@ public function newEloquentBuilder($query)
16071607
/**
16081608
* Get a new query builder instance for the connection.
16091609
*
1610-
* @return \Illuminate\Database\Query\Builder
1610+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
16111611
*/
16121612
protected function newBaseQueryBuilder()
16131613
{

src/Illuminate/Database/Eloquent/Relations/Concerns/InteractsWithPivotTable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ public function newExistingPivot(array $attributes = [])
538538
/**
539539
* Get a new plain query builder for the pivot table.
540540
*
541-
* @return \Illuminate\Database\Query\Builder
541+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
542542
*/
543543
public function newPivotStatement()
544544
{
@@ -549,7 +549,7 @@ public function newPivotStatement()
549549
* Get a new pivot statement for a given "other" ID.
550550
*
551551
* @param mixed $id
552-
* @return \Illuminate\Database\Query\Builder
552+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
553553
*/
554554
public function newPivotStatementForId($id)
555555
{
@@ -559,7 +559,7 @@ public function newPivotStatementForId($id)
559559
/**
560560
* Create a new query builder for the pivot table.
561561
*
562-
* @return \Illuminate\Database\Query\Builder
562+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
563563
*/
564564
public function newPivotQuery()
565565
{

src/Illuminate/Database/Eloquent/Relations/MorphToMany.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected function getCurrentlyAttachedPivots()
127127
/**
128128
* Create a new query builder for the pivot table.
129129
*
130-
* @return \Illuminate\Database\Query\Builder
130+
* @return \Illuminate\Database\Query\Builder<\PDO::FETCH_OBJ>
131131
*/
132132
public function newPivotQuery()
133133
{

0 commit comments

Comments
 (0)