Skip to content

Commit 8396504

Browse files
authored
Optimized the PHPDoc for hyperf/database. (#7511)
1 parent abaa219 commit 8396504

30 files changed

Lines changed: 1357 additions & 218 deletions

src/Concerns/BuildsQueries.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
use Hyperf\Database\Exception\RecordsNotFoundException;
2424
use Hyperf\Database\Model\Builder;
2525
use Hyperf\Database\Model\Collection;
26-
use Hyperf\Database\Model\Model;
2726
use Hyperf\Database\Query\Expression;
2827
use Hyperf\Paginator\Contract\CursorPaginator as CursorPaginatorContract;
2928
use Hyperf\Paginator\Cursor;
@@ -36,7 +35,7 @@
3635
use function Hyperf\Collection\data_get;
3736

3837
/**
39-
* @template TValue
38+
* @template TValue of object
4039
* @mixin Builder
4140
* @mixin \Hyperf\Database\Query\Builder
4241
*/
@@ -48,6 +47,7 @@ trait BuildsQueries
4847
* Chunk the results of the query.
4948
*
5049
* @param int $count
50+
* @param callable(BaseCollection<int, TValue>, int): mixed $callback
5151
* @return bool
5252
*/
5353
public function chunk($count, callable $callback)
@@ -85,6 +85,8 @@ public function chunk($count, callable $callback)
8585

8686
/**
8787
* Run a map over each item while chunking.
88+
*
89+
* @param callable(TValue): mixed $callback
8890
*/
8991
public function chunkMap(callable $callback, int $count = 1000): BaseCollection
9092
{
@@ -102,6 +104,7 @@ public function chunkMap(callable $callback, int $count = 1000): BaseCollection
102104
/**
103105
* Execute a callback over each item while chunking.
104106
*
107+
* @param callable(TValue, int): mixed $callback
105108
* @param int $count
106109
* @return bool
107110
*/
@@ -118,6 +121,8 @@ public function each(callable $callback, $count = 1000)
118121

119122
/**
120123
* Query lazily, by chunks of the given size.
124+
*
125+
* @return LazyCollection<int, TValue>
121126
*/
122127
public function lazy(int $chunkSize = 1000): LazyCollection
123128
{
@@ -146,6 +151,8 @@ public function lazy(int $chunkSize = 1000): LazyCollection
146151

147152
/**
148153
* Query lazily, by chunking the results of a query by comparing IDs.
154+
*
155+
* @return LazyCollection<int, TValue>
149156
*/
150157
public function lazyById(int $chunkSize = 1000, ?string $column = null, ?string $alias = null): LazyCollection
151158
{
@@ -154,6 +161,8 @@ public function lazyById(int $chunkSize = 1000, ?string $column = null, ?string
154161

155162
/**
156163
* Query lazily, by chunking the results of a query by comparing IDs in descending order.
164+
*
165+
* @return LazyCollection<int, TValue>
157166
*/
158167
public function lazyByIdDesc(int $chunkSize = 1000, ?string $column = null, ?string $alias = null): LazyCollection
159168
{
@@ -164,7 +173,7 @@ public function lazyByIdDesc(int $chunkSize = 1000, ?string $column = null, ?str
164173
* Execute the query and get the first result.
165174
*
166175
* @param array $columns
167-
* @return null|Model|object|static
176+
* @return null|TValue
168177
*/
169178
public function first($columns = ['*'])
170179
{
@@ -173,6 +182,8 @@ public function first($columns = ['*'])
173182

174183
/**
175184
* Execute a callback over each item while chunking by ID.
185+
*
186+
* @param callable(TValue, int): mixed $callback
176187
*/
177188
public function eachById(callable $callback, int $count = 1000, ?string $column = null, ?string $alias = null): bool
178189
{
@@ -188,6 +199,8 @@ public function eachById(callable $callback, int $count = 1000, ?string $column
188199

189200
/**
190201
* Chunk the results of a query by comparing IDs in a given order.
202+
*
203+
* @param callable(BaseCollection<int, TValue>, int): mixed $callback
191204
*/
192205
public function orderedChunkById(int $count, callable $callback, ?string $column = null, ?string $alias = null, bool $descending = false): bool
193206
{
@@ -240,6 +253,8 @@ public function orderedChunkById(int $count, callable $callback, ?string $column
240253

241254
/**
242255
* Chunk the results of a query by comparing IDs in descending order.
256+
*
257+
* @param callable(BaseCollection<int, TValue>, int): mixed $callback
243258
*/
244259
public function chunkByIdDesc(int $count, callable $callback, ?string $column = null, ?string $alias = null): bool
245260
{

0 commit comments

Comments
 (0)