From 03dc4342c5e0943e21c7307d01ca708258a2a105 Mon Sep 17 00:00:00 2001 From: Sergei Predvoditelev Date: Wed, 14 Feb 2024 10:39:53 +0300 Subject: [PATCH] Add more specific psalm type for `QueryFunctionsInterface::count()` result (#810) --- CHANGELOG.md | 1 + src/Query/Query.php | 1 + src/Query/QueryFunctionsInterface.php | 2 ++ 3 files changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a395afc9..d6f69c650 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Enh #801: Deprecate `SchemaInterface::isReadQuery()` and add `DbStringHelper::isReadQuery()` method (@Tigrov) - Enh #801: Remove unnecessary symbol `\\` from `rtrim()` function inside `DbStringHelper::baseName()` method (@Tigrov) - Bug #801: Fix bug with `Quoter::$tablePrefix` when change `AbstractConnection::$tablePrefix` property (@Tigrov) +- Enh #810: Add more specific psalm type for `QueryFunctionsInterface::count()` result (@vjik) ## 1.2.0 November 12, 2023 diff --git a/src/Query/Query.php b/src/Query/Query.php index 8aa9cc517..e262ac581 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -300,6 +300,7 @@ public function count(string $sql = '*'): int|string return 0; } + /** @psalm-var non-negative-int|string */ return $count <= PHP_INT_MAX ? (int) $count : $count; } diff --git a/src/Query/QueryFunctionsInterface.php b/src/Query/QueryFunctionsInterface.php index 0ad6222d5..0635c4162 100644 --- a/src/Query/QueryFunctionsInterface.php +++ b/src/Query/QueryFunctionsInterface.php @@ -39,6 +39,8 @@ public function average(string $sql): int|float|null|string; * @return int|string Number of records. The result may be a string depending on the underlying database engine and * to support integer values higher than a 32bit PHP integer can handle. * + * @psalm-return non-negative-int|string + * * Note: Make sure you quote column names in the expression. */ public function count(string $sql = '*'): int|string;