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

Improve type annotations #779

Merged
merged 2 commits into from
Nov 21, 2023
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## 1.2.1 under development

- Bug #777: Fix `Query::count()` when it returns an incorrect value if the result is greater than `PHP_INT_MAX` (@Tigrov)
- 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)
- Enh #778: Deprecate unnecessary argument `$rawSql` of `AbstractCommand::internalExecute()` (@Tigrov)

## 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
Loading