From 0e194646b376e52335ed7b1c42b5b96b6e3ef0c5 Mon Sep 17 00:00:00 2001 From: darkdef Date: Sun, 21 Jan 2024 18:51:44 +0300 Subject: [PATCH 01/11] Restore Query::one interface --- src/Query/QueryInterface.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Query/QueryInterface.php b/src/Query/QueryInterface.php index 0bbe54957..d6b6d607c 100644 --- a/src/Query/QueryInterface.php +++ b/src/Query/QueryInterface.php @@ -249,10 +249,10 @@ public function getWithQueries(): array; * @throws InvalidConfigException * @throws Throwable * - * @return array|null The first row (in terms of an array) of the query result. It returns `null` if the query - * results in nothing. + * @return array|object|null The first row (as array or object) of the query result. + * It returns `null` if the query results in nothing. */ - public function one(): array|null; + public function one(): array|object|null; /** * Sets the parameters to bind to the query. From 9801083e68ab6abcd9c2adc526d9b4bf733990b1 Mon Sep 17 00:00:00 2001 From: darkdef Date: Mon, 29 Jan 2024 22:29:59 +0300 Subject: [PATCH 02/11] fix --- src/Command/AbstractCommand.php | 2 +- src/Command/CommandInterface.php | 4 ++-- src/Debug/CommandInterfaceProxy.php | 2 +- src/Query/Query.php | 2 +- src/Query/QueryInterface.php | 3 ++- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index 10ba47fb6..6348a800d 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -442,7 +442,7 @@ public function queryColumn(): array return is_array($results) ? $results : []; } - public function queryOne(): array|null + public function queryOne(): array|object|null { /** @psalm-var mixed $results */ $results = $this->queryInternal(self::QUERY_MODE_ROW); diff --git a/src/Command/CommandInterface.php b/src/Command/CommandInterface.php index 3caad60d2..9042a1d20 100644 --- a/src/Command/CommandInterface.php +++ b/src/Command/CommandInterface.php @@ -626,10 +626,10 @@ public function queryColumn(): array; * @throws Exception * @throws Throwable If execution failed. * - * @return array|null The first row (in terms of an array) of the query result. Null if the query + * @return array|object|null The first row (in terms of an array) of the query result. Null if the query * results in nothing. */ - public function queryOne(): array|null; + public function queryOne(): array|object|null; /** * Execute the SQL statement and returns the value of the first column in the first row of data. diff --git a/src/Debug/CommandInterfaceProxy.php b/src/Debug/CommandInterfaceProxy.php index 2ca7773c7..aa51eefd8 100644 --- a/src/Debug/CommandInterfaceProxy.php +++ b/src/Debug/CommandInterfaceProxy.php @@ -389,7 +389,7 @@ public function queryColumn(): array /** * @psalm-suppress PossiblyUndefinedArrayOffset */ - public function queryOne(): array|null + public function queryOne(): array|object|null { [$callStack] = debug_backtrace(); diff --git a/src/Query/Query.php b/src/Query/Query.php index 8aa9cc517..81e34c5c4 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -528,7 +528,7 @@ public function offset(ExpressionInterface|int|null $offset): static return $this; } - public function one(): array|null + public function one(): array|object|null { return match ($this->emulateExecution) { true => null, diff --git a/src/Query/QueryInterface.php b/src/Query/QueryInterface.php index d6b6d607c..1fe95a8e0 100644 --- a/src/Query/QueryInterface.php +++ b/src/Query/QueryInterface.php @@ -45,7 +45,8 @@ 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. + * @psalm-return array[]|object[] */ public function all(): array; From 8003e644175d62a77e6ee30e75eced8b7c12e577 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 6 Apr 2024 09:59:24 +0000 Subject: [PATCH 03/11] Apply Rector changes (CI) --- src/Query/Query.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Query/Query.php b/src/Query/Query.php index 70d3a5aea..3418f1522 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -680,7 +680,6 @@ public function withQueries(array $withQueries): static * * Restores the value of select to make this query reusable. * - * @param ExpressionInterface|string $selectExpression * * @throws Exception * @throws InvalidArgumentException From 6e904c615d73d81e2af057a0ef09ebeca9e3a236 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sat, 6 Apr 2024 09:59:32 +0000 Subject: [PATCH 04/11] Apply fixes from StyleCI --- src/Query/Query.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Query/Query.php b/src/Query/Query.php index 3418f1522..7a5d89f25 100644 --- a/src/Query/Query.php +++ b/src/Query/Query.php @@ -680,7 +680,6 @@ public function withQueries(array $withQueries): static * * Restores the value of select to make this query reusable. * - * * @throws Exception * @throws InvalidArgumentException * @throws InvalidConfigException From 29248032298d5278ba11e72f2922308b90aacb70 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 20 Aug 2024 17:41:31 +0700 Subject: [PATCH 05/11] Update comments and psalm --- src/Command/CommandInterface.php | 8 +++++--- src/Query/QueryInterface.php | 10 ++++++---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Command/CommandInterface.php b/src/Command/CommandInterface.php index 19598ad3e..235c3ec2a 100644 --- a/src/Command/CommandInterface.php +++ b/src/Command/CommandInterface.php @@ -623,8 +623,10 @@ 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. - * Empty array if the query results in nothing. + * @return array All rows of the query result. Each array element is an `array` or `object` representing a row of + * data. Empty array if the query results in nothing. + * + * @psalm-return array */ public function queryAll(): array; @@ -649,7 +651,7 @@ public function queryColumn(): array; * @throws Exception * @throws Throwable If execution failed. * - * @return array|object|null The first row (in terms of an array) of the query result. Null if the query + * @return array|object|null The first row as an `array` or as an `object` of the query result. `null` if the query * results in nothing. */ public function queryOne(): array|object|null; diff --git a/src/Query/QueryInterface.php b/src/Query/QueryInterface.php index 32afc69a3..52ac73f94 100644 --- a/src/Query/QueryInterface.php +++ b/src/Query/QueryInterface.php @@ -51,8 +51,10 @@ 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. - * @psalm-return array[]|object[] + * @return array All rows of the query result. Each array element is an `array` or `object` representing a row of + * data. Empty array if the query results in nothing. + * + * @psalm-return array */ public function all(): array; @@ -259,8 +261,8 @@ public function getWithQueries(): array; * @throws InvalidConfigException * @throws Throwable * - * @return array|object|null The first row (as array or object) of the query result. - * It returns `null` if the query results in nothing. + * @return array|object|null The first row as an `array` or as an `object` of the query result. `null` if the query + * results in nothing. */ public function one(): array|object|null; From 652f8a93c753cd89a8269580dc6c85039028c810 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 20 Aug 2024 17:43:17 +0700 Subject: [PATCH 06/11] Add lines to CHANGELOG.md and UPGRADE.md --- CHANGELOG.md | 1 + UPGRADE.md | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d391a4164..a32212baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ - Enh #855: Add array and JSON overlaps conditions (@Tigrov) - Enh #860: Add `bit` abstract type (@Tigrov) - Enh #862: Refactor PHP type of `ColumnSchemaInterface` instances (@Tigrov) +- Enh #798: Allow `QueryInterface::all()` and `QueryInterface::one()` to return objects (@darkdef, @Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index d8767e8ae..5a6443b80 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -126,4 +126,6 @@ Each table column has its own class in the `Yiisoft\Db\Schema\Column` namespace ### Other changes -- Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method +- Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method; +- Allow to `QueryInterface::one()` and `CommandInterface::queryOne()` return an object; +- Allow to `QueryInterface::all()` and `CommandInterface::queryAll()` return array of objects; From 9c746855f923f07c9d4b5fa01e7c7dfc0d5437de Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 20 Aug 2024 17:54:31 +0700 Subject: [PATCH 07/11] Update PHPDoc return type --- src/Command/CommandInterface.php | 6 ++---- src/Query/QueryInterface.php | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Command/CommandInterface.php b/src/Command/CommandInterface.php index 235c3ec2a..e3dc5ab8e 100644 --- a/src/Command/CommandInterface.php +++ b/src/Command/CommandInterface.php @@ -623,10 +623,8 @@ 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` or `object` representing a row of - * data. Empty array if the query results in nothing. - * - * @psalm-return array + * @return array[]|object[] All rows of the query result. Each array element is an `array` or `object` representing + * a row of data. Empty array if the query results in nothing. */ public function queryAll(): array; diff --git a/src/Query/QueryInterface.php b/src/Query/QueryInterface.php index 52ac73f94..75ed79905 100644 --- a/src/Query/QueryInterface.php +++ b/src/Query/QueryInterface.php @@ -51,10 +51,8 @@ public function addParams(array $params): static; * @throws InvalidConfigException * @throws Throwable * - * @return array All rows of the query result. Each array element is an `array` or `object` representing a row of - * data. Empty array if the query results in nothing. - * - * @psalm-return array + * @return array[]|object[] All rows of the query result. Each array element is an `array` or `object` representing + * a row of data. Empty array if the query results in nothing. */ public function all(): array; From 9f1273036e38fb5df7fd80cf8a73f037e35be2a7 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 20 Aug 2024 17:59:28 +0700 Subject: [PATCH 08/11] Update CHANGELOG.md [skip ci] --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a32212baf..23305c4db 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,7 @@ - Enh #855: Add array and JSON overlaps conditions (@Tigrov) - Enh #860: Add `bit` abstract type (@Tigrov) - Enh #862: Refactor PHP type of `ColumnSchemaInterface` instances (@Tigrov) -- Enh #798: Allow `QueryInterface::all()` and `QueryInterface::one()` to return objects (@darkdef, @Tigrov) +- Enh #798: Allow to `CommandInterface::queryOne()` and `CommandInterface::queryAll()` return objects (@darkdef, @Tigrov) ## 1.3.0 March 21, 2024 From 8399664a9bb8e190d203c25358a4f38263266b26 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 20 Aug 2024 18:12:51 +0700 Subject: [PATCH 09/11] Revert "return object" for `CommandInterface` --- CHANGELOG.md | 2 +- UPGRADE.md | 4 ++-- src/Command/AbstractCommand.php | 2 +- src/Command/CommandInterface.php | 7 +++---- src/Debug/CommandInterfaceProxy.php | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23305c4db..93b6cb7d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,7 @@ - Enh #855: Add array and JSON overlaps conditions (@Tigrov) - Enh #860: Add `bit` abstract type (@Tigrov) - Enh #862: Refactor PHP type of `ColumnSchemaInterface` instances (@Tigrov) -- Enh #798: Allow to `CommandInterface::queryOne()` and `CommandInterface::queryAll()` return objects (@darkdef, @Tigrov) +- Enh #798: Allow to `QueryInterface::one()` and `QueryInterface::all()` return objects (@darkdef, @Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 5a6443b80..839f1ad1b 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -127,5 +127,5 @@ Each table column has its own class in the `Yiisoft\Db\Schema\Column` namespace ### Other changes - Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method; -- Allow to `QueryInterface::one()` and `CommandInterface::queryOne()` return an object; -- Allow to `QueryInterface::all()` and `CommandInterface::queryAll()` return array of objects; +- Allow to `QueryInterface::one()` return an object; +- Allow to `QueryInterface::all()` return array of objects; diff --git a/src/Command/AbstractCommand.php b/src/Command/AbstractCommand.php index 5c9edff8e..6f97718a8 100644 --- a/src/Command/AbstractCommand.php +++ b/src/Command/AbstractCommand.php @@ -454,7 +454,7 @@ public function queryColumn(): array return is_array($results) ? $results : []; } - public function queryOne(): array|object|null + public function queryOne(): array|null { /** @psalm-var mixed $results */ $results = $this->queryInternal(self::QUERY_MODE_ROW); diff --git a/src/Command/CommandInterface.php b/src/Command/CommandInterface.php index e3dc5ab8e..269855e24 100644 --- a/src/Command/CommandInterface.php +++ b/src/Command/CommandInterface.php @@ -623,8 +623,8 @@ public function query(): DataReaderInterface; * @throws Exception * @throws Throwable If execution failed. * - * @return array[]|object[] All rows of the query result. Each array element is an `array` or `object` representing - * a row of data. Empty array if the query results in nothing. + * @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; @@ -649,8 +649,7 @@ public function queryColumn(): array; * @throws Exception * @throws Throwable If execution failed. * - * @return array|object|null The first row as an `array` or as an `object` of the query result. `null` if the query - * results in nothing. + * @return array|null The first row as an `array` of the query result. `null` if the query results in nothing. */ public function queryOne(): array|object|null; diff --git a/src/Debug/CommandInterfaceProxy.php b/src/Debug/CommandInterfaceProxy.php index cc1b4ebbc..ed513f8ee 100644 --- a/src/Debug/CommandInterfaceProxy.php +++ b/src/Debug/CommandInterfaceProxy.php @@ -389,7 +389,7 @@ public function queryColumn(): array /** * @psalm-suppress PossiblyUndefinedArrayOffset */ - public function queryOne(): array|object|null + public function queryOne(): array|null { [$callStack] = debug_backtrace(); From b6db8388c1402c374566021860db2f381415ae7a Mon Sep 17 00:00:00 2001 From: Tigrov Date: Tue, 20 Aug 2024 18:18:54 +0700 Subject: [PATCH 10/11] Revert "return object" for `CommandInterface` --- src/Command/CommandInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Command/CommandInterface.php b/src/Command/CommandInterface.php index 269855e24..a10748f90 100644 --- a/src/Command/CommandInterface.php +++ b/src/Command/CommandInterface.php @@ -651,7 +651,7 @@ public function queryColumn(): array; * * @return array|null The first row as an `array` of the query result. `null` if the query results in nothing. */ - public function queryOne(): array|object|null; + public function queryOne(): array|null; /** * Execute the SQL statement and returns the value of the first column in the first row of data. From df9e0ab8a803d9a37bc1026f67afd58e7bec982b Mon Sep 17 00:00:00 2001 From: Tigrov Date: Wed, 21 Aug 2024 13:56:56 +0700 Subject: [PATCH 11/11] Update CHANGELOG.md and UPGRADE.md [skip ci] --- CHANGELOG.md | 2 +- UPGRADE.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 93b6cb7d7..614264c5e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +32,7 @@ - Enh #855: Add array and JSON overlaps conditions (@Tigrov) - Enh #860: Add `bit` abstract type (@Tigrov) - Enh #862: Refactor PHP type of `ColumnSchemaInterface` instances (@Tigrov) -- Enh #798: Allow to `QueryInterface::one()` and `QueryInterface::all()` return objects (@darkdef, @Tigrov) +- Enh #798: Allow `QueryInterface::one()` and `QueryInterface::all()` to return objects (@darkdef, @Tigrov) ## 1.3.0 March 21, 2024 diff --git a/UPGRADE.md b/UPGRADE.md index 839f1ad1b..bbce1e55a 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -127,5 +127,5 @@ Each table column has its own class in the `Yiisoft\Db\Schema\Column` namespace ### Other changes - Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method; -- Allow to `QueryInterface::one()` return an object; -- Allow to `QueryInterface::all()` return array of objects; +- Allow `QueryInterface::one()` to return an object; +- Allow `QueryInterface::all()` to return array of objects;