Skip to content

Commit 003d4e8

Browse files
committed
Improve type annotations
1 parent 6845a40 commit 003d4e8

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
- Bug #777: Fix `Query::count()` when it returns an incorrect value if the result is greater
66
than `PHP_INT_MAX` (@Tigrov)
7+
- Enh #779: Specify result type of `QueryInterface::all()`, `CommandInterface::queryAll()` and
8+
`DbArrayHelper::populate()` methods to `array[]` (@vjik)
9+
- Enh #779: Specify populate closure type in `BatchQueryResultInterface` (@vjik)
710

811
## 1.2.0 November 12, 2023
912

src/Command/CommandInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ public function query(): DataReaderInterface;
600600
* @throws Exception
601601
* @throws Throwable If execution failed.
602602
*
603-
* @return array All rows of the query result. Each array element is an array representing a row of data.
603+
* @return array[] All rows of the query result. Each array element is an array representing a row of data.
604604
* Empty array if the query results in nothing.
605605
*/
606606
public function queryAll(): array;

src/Helper/DbArrayHelper.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ public static function multisort(
333333
* This method is internally used to convert the data fetched from a database into the format as required by this
334334
* query.
335335
*
336-
* @param array $rows The raw query result from a database.
336+
* @param array[] $rows The raw query result from a database.
337337
*
338-
* @psalm-suppress MixedArrayOffset
338+
* @return array[]
339339
*/
340340
public static function populate(array $rows, Closure|string|null $indexBy = null): array
341341
{
@@ -345,7 +345,6 @@ public static function populate(array $rows, Closure|string|null $indexBy = null
345345

346346
$result = [];
347347

348-
/** @psalm-var array[][] $row */
349348
foreach ($rows as $row) {
350349
/** @psalm-suppress MixedArrayOffset */
351350
$result[self::getValueByPath($row, $indexBy)] = $row;

src/Query/BatchQueryResultInterface.php

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
* ```
3636
*
3737
* @extends Iterator<int|string, mixed>
38+
*
39+
* @psalm-type PopulateClosure=Closure(array[],Closure|string|null): mixed
3840
*/
3941
interface BatchQueryResultInterface extends Iterator
4042
{
@@ -106,5 +108,8 @@ public function getBatchSize(): int;
106108
*/
107109
public function batchSize(int $value): self;
108110

111+
/**
112+
* @psalm-param PopulateClosure|null $populateMethod
113+
*/
109114
public function setPopulatedMethod(Closure|null $populateMethod = null): self;
110115
}

src/Query/QueryInterface.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public function addParams(array $params): static;
4545
* @throws InvalidConfigException
4646
* @throws Throwable
4747
*
48-
* @return array The query results. If the query results in nothing, it returns an empty array.
48+
* @return array[] The query results. If the query results in nothing, it returns an empty array.
4949
*/
5050
public function all(): array;
5151

0 commit comments

Comments
 (0)