Skip to content

Commit

Permalink
Improve type annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
vjik committed Nov 21, 2023
1 parent 6845a40 commit 003d4e8
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

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

## 1.2.0 November 12, 2023

Expand Down
2 changes: 1 addition & 1 deletion src/Command/CommandInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ public function query(): DataReaderInterface;
* @throws Exception
* @throws Throwable If execution failed.
*
* @return array All rows of the query result. Each array element is an array representing a row of data.
* @return array[] All rows of the query result. Each array element is an array representing a row of data.
* Empty array if the query results in nothing.
*/
public function queryAll(): array;
Expand Down
5 changes: 2 additions & 3 deletions src/Helper/DbArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,9 @@ public static function multisort(
* This method is internally used to convert the data fetched from a database into the format as required by this
* query.
*
* @param array $rows The raw query result from a database.
* @param array[] $rows The raw query result from a database.
*
* @psalm-suppress MixedArrayOffset
* @return array[]
*/
public static function populate(array $rows, Closure|string|null $indexBy = null): array
{
Expand All @@ -345,7 +345,6 @@ public static function populate(array $rows, Closure|string|null $indexBy = null

$result = [];

/** @psalm-var array[][] $row */
foreach ($rows as $row) {
/** @psalm-suppress MixedArrayOffset */
$result[self::getValueByPath($row, $indexBy)] = $row;
Expand Down
5 changes: 5 additions & 0 deletions src/Query/BatchQueryResultInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
* ```
*
* @extends Iterator<int|string, mixed>
*
* @psalm-type PopulateClosure=Closure(array[],Closure|string|null): mixed
*/
interface BatchQueryResultInterface extends Iterator
{
Expand Down Expand Up @@ -106,5 +108,8 @@ public function getBatchSize(): int;
*/
public function batchSize(int $value): self;

/**
* @psalm-param PopulateClosure|null $populateMethod
*/
public function setPopulatedMethod(Closure|null $populateMethod = null): self;
}
2 changes: 1 addition & 1 deletion src/Query/QueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function addParams(array $params): static;
* @throws InvalidConfigException
* @throws Throwable
*
* @return array The query results. If the query results in nothing, it returns an empty array.
* @return array[] The query results. If the query results in nothing, it returns an empty array.
*/
public function all(): array;

Expand Down

0 comments on commit 003d4e8

Please sign in to comment.