Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] feat: add generics to Eloquent Builder and Relations #51851

Merged
merged 4 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
"nyholm/psr7": "^1.2",
"orchestra/testbench-core": "^9.1.5",
"pda/pheanstalk": "^5.0",
"phpstan/phpstan": "^1.4.7",
"phpstan/phpstan": "^1.11.5",
"phpunit/phpunit": "^10.5|^11.0",
"predis/predis": "^2.0.2",
"resend/resend-php": "^0.10.0",
Expand Down
12 changes: 7 additions & 5 deletions src/Illuminate/Auth/EloquentUserProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class EloquentUserProvider implements UserProvider
/**
* The callback that may modify the user retrieval queries.
*
* @var (\Closure(\Illuminate\Database\Eloquent\Builder):mixed)|null
* @var (\Closure(\Illuminate\Database\Eloquent\Builder<*>):mixed)|null
*/
protected $queryCallback;

Expand Down Expand Up @@ -177,8 +177,10 @@ public function rehashPasswordIfRequired(UserContract $user, array $credentials,
/**
* Get a new query builder for the model instance.
*
* @param \Illuminate\Database\Eloquent\Model|null $model
* @return \Illuminate\Database\Eloquent\Builder
* @template TModel of \Illuminate\Database\Eloquent\Model
*
* @param TModel|null $model
* @return \Illuminate\Database\Eloquent\Builder<TModel>
*/
protected function newModelQuery($model = null)
{
Expand Down Expand Up @@ -252,7 +254,7 @@ public function setModel($model)
/**
* Get the callback that modifies the query before retrieving users.
*
* @return \Closure|null
* @return (\Closure(\Illuminate\Database\Eloquent\Builder<*>):mixed)|null
*/
public function getQueryCallback()
{
Expand All @@ -262,7 +264,7 @@ public function getQueryCallback()
/**
* Sets the callback to modify the query before retrieving users.
*
* @param (\Closure(\Illuminate\Database\Eloquent\Builder):mixed)|null $queryCallback
* @param (\Closure(\Illuminate\Database\Eloquent\Builder<*>):mixed)|null $queryCallback
* @return $this
*/
public function withQuery($queryCallback = null)
Expand Down
30 changes: 19 additions & 11 deletions src/Illuminate/Database/Concerns/BuildsQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
use InvalidArgumentException;
use RuntimeException;

/**
* @template TValue
*
* @mixin \Illuminate\Database\Eloquent\Builder
* @mixin \Illuminate\Database\Query\Builder
*/
trait BuildsQueries
{
use Conditionable;
Expand All @@ -26,7 +32,7 @@ trait BuildsQueries
* Chunk the results of the query.
*
* @param int $count
* @param callable $callback
* @param callable(\Illuminate\Support\Collection<int, TValue>, int): mixed $callback
* @return bool
*/
public function chunk($count, callable $callback)
Expand Down Expand Up @@ -65,9 +71,11 @@ public function chunk($count, callable $callback)
/**
* Run a map over each item while chunking.
*
* @param callable $callback
* @template TReturn
*
* @param callable(TValue): TReturn $callback
* @param int $count
* @return \Illuminate\Support\Collection
* @return \Illuminate\Support\Collection<int, TReturn>
*/
public function chunkMap(callable $callback, $count = 1000)
{
Expand All @@ -85,7 +93,7 @@ public function chunkMap(callable $callback, $count = 1000)
/**
* Execute a callback over each item while chunking.
*
* @param callable $callback
* @param callable(TValue, int): mixed $callback
* @param int $count
* @return bool
*
Expand All @@ -106,7 +114,7 @@ public function each(callable $callback, $count = 1000)
* Chunk the results of a query by comparing IDs.
*
* @param int $count
* @param callable $callback
* @param callable(\Illuminate\Support\Collection<int, TValue>, int): mixed $callback
* @param string|null $column
* @param string|null $alias
* @return bool
Expand All @@ -120,7 +128,7 @@ public function chunkById($count, callable $callback, $column = null, $alias = n
* Chunk the results of a query by comparing IDs in descending order.
*
* @param int $count
* @param callable $callback
* @param callable(\Illuminate\Support\Collection<int, TValue>, int): mixed $callback
* @param string|null $column
* @param string|null $alias
* @return bool
Expand All @@ -134,7 +142,7 @@ public function chunkByIdDesc($count, callable $callback, $column = null, $alias
* Chunk the results of a query by comparing IDs in a given order.
*
* @param int $count
* @param callable $callback
* @param callable(\Illuminate\Support\Collection<int, TValue>, int): mixed $callback
* @param string|null $column
* @param string|null $alias
* @param bool $descending
Expand Down Expand Up @@ -194,7 +202,7 @@ public function orderedChunkById($count, callable $callback, $column = null, $al
/**
* Execute a callback over each item while chunking by ID.
*
* @param callable $callback
* @param callable(TValue, int): mixed $callback
* @param int $count
* @param string|null $column
* @param string|null $alias
Expand Down Expand Up @@ -328,7 +336,7 @@ protected function orderedLazyById($chunkSize = 1000, $column = null, $alias = n
* Execute the query and get the first result.
*
* @param array|string $columns
* @return \Illuminate\Database\Eloquent\Model|object|static|null
* @return TValue|null
*/
public function first($columns = ['*'])
{
Expand All @@ -339,7 +347,7 @@ public function first($columns = ['*'])
* Execute the query and get the first result if it's the sole matching record.
*
* @param array|string $columns
* @return \Illuminate\Database\Eloquent\Model|object|static|null
* @return TValue
*
* @throws \Illuminate\Database\RecordsNotFoundException
* @throws \Illuminate\Database\MultipleRecordsFoundException
Expand Down Expand Up @@ -463,7 +471,7 @@ protected function paginateUsingCursor($perPage, $columns = ['*'], $cursorName =
/**
* Get the original column name of the given column, without any aliasing.
*
* @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder<*> $builder
* @param string $parameter
* @return string
*/
Expand Down
Loading