Skip to content

Commit 2d50deb

Browse files
committed
Connection, ResultSet: $rowNormalizer is normalized to Closure
1 parent a785e33 commit 2d50deb

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

src/Database/Connection.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class Connection
2828
private SqlPreprocessor $preprocessor;
2929
private ?PDO $pdo = null;
3030

31-
/** @var callable(array, ResultSet): array */
32-
private $rowNormalizer = [Helpers::class, 'normalizeRow'];
31+
/** @var ?\Closure(array<string, mixed>, ResultSet): array<string, mixed> */
32+
private ?\Closure $rowNormalizer;
3333
private ?string $sql = null;
3434
private int $transactionDepth = 0;
3535

@@ -42,9 +42,9 @@ public function __construct(
4242
private readonly ?string $password = null,
4343
private readonly array $options = [],
4444
) {
45-
if (!empty($options['newDateTime'])) {
46-
$this->rowNormalizer = fn($row, $resultSet) => Helpers::normalizeRow($row, $resultSet, DateTime::class);
47-
}
45+
$this->rowNormalizer = !empty($options['newDateTime'])
46+
? fn(array $row, ResultSet $resultSet): array => Helpers::normalizeRow($row, $resultSet, DateTime::class)
47+
: Helpers::normalizeRow(...);
4848
if (empty($options['lazy'])) {
4949
$this->connect();
5050
}
@@ -134,7 +134,7 @@ public function getReflection(): Reflection
134134
*/
135135
public function setRowNormalizer(?callable $normalizer): static
136136
{
137-
$this->rowNormalizer = $normalizer;
137+
$this->rowNormalizer = $normalizer ? $normalizer(...) : null;
138138
return $this;
139139
}
140140

src/Database/ResultSet.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919
class ResultSet implements \Iterator, IRowContainer
2020
{
2121
private ?\PDOStatement $pdoStatement = null;
22-
23-
/** @var callable(array, ResultSet): array */
24-
private readonly mixed $normalizer;
2522
private Row|false|null $lastRow = null;
2623
private int $lastRowKey = -1;
2724

@@ -35,10 +32,10 @@ public function __construct(
3532
private readonly Connection $connection,
3633
private readonly string $queryString,
3734
private readonly array $params,
38-
?callable $normalizer = null,
35+
/** @var ?\Closure(array<string, mixed>, self): array<string, mixed> */
36+
private readonly ?\Closure $normalizer = null,
3937
) {
4038
$time = microtime(true);
41-
$this->normalizer = $normalizer;
4239
$types = ['boolean' => PDO::PARAM_BOOL, 'integer' => PDO::PARAM_INT, 'resource' => PDO::PARAM_LOB, 'NULL' => PDO::PARAM_NULL];
4340

4441
try {

0 commit comments

Comments
 (0)