From fd6f68b042acffd8fd52c30a6e56257d0d563e03 Mon Sep 17 00:00:00 2001 From: Rasmus Schultz Date: Sun, 27 Oct 2024 15:48:50 +0000 Subject: [PATCH] fix: the return type hint was incorrect here and would cause an error e.g. when mapping records to objects --- src/framework/Result.php | 4 ++-- test/test-unit.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/framework/Result.php b/src/framework/Result.php index ebd6fe8..a01b4a7 100644 --- a/src/framework/Result.php +++ b/src/framework/Result.php @@ -39,9 +39,9 @@ public function __construct(PreparedStatement $statement, int $batch_size, array } /** - * @return array|null first record of the record-set (or NULL, if the record-set is empty) + * @return mixed|null first record of the record-set (or NULL, if the record-set is empty) */ - public function firstRow(): array|null + public function firstRow(): mixed { foreach ($this->createIterator(1) as $record) { return $record; // break from loop immediately after fetching the first record diff --git a/test/test-unit.php b/test/test-unit.php index c3a2db6..015d1d5 100644 --- a/test/test-unit.php +++ b/test/test-unit.php @@ -696,14 +696,14 @@ function () { $mappers = [new RecordMapper(function (array $record) use (&$calls) { $calls[] = $record; - return $record; + return (object) $record; })]; $result = new Result($mock_statement, 20, $mappers); $record = $result->firstRow(); - eq($record, ['id' => 1], 'should return first row'); + eq($record->id, 1, 'should return first result'); eq($calls, [['id' => 1]], 'should process precisely one record (disregarding batch size)'); }