From f477260972f6ed289678c888bb28d6b20e173f35 Mon Sep 17 00:00:00 2001 From: ignace nyamagana butera Date: Sun, 19 Jan 2025 09:27:07 +0100 Subject: [PATCH] Improve codebase --- .../interoperability/tabular-data-importer.md | 10 +++++----- src/RdbmsResult.php | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/9.0/interoperability/tabular-data-importer.md b/docs/9.0/interoperability/tabular-data-importer.md index 21593e6e..ceb4d047 100644 --- a/docs/9.0/interoperability/tabular-data-importer.md +++ b/docs/9.0/interoperability/tabular-data-importer.md @@ -80,14 +80,14 @@ $names = RdbmsResult::columnNames($result); //will return ['firstname', 'lastname', ...] ``` -- convert the result into an `Iterator` using the `records` public static method. +- convert the result into an `Iterator` using the `rows` public static method. ```php mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $connection = new mysqli("localhost", "my_user", "my_password", "world"); $result = $connection->query("SELECT * FROM authors"); $result instanceOf mysqli_result || throw new RuntimeException('MySQL results not available'); -foreach (RdbmsResult::records($stmt) as $record) { +foreach (RdbmsResult::rows($stmt) as $record) { // returns each found record which match the processed query. } ``` @@ -116,13 +116,13 @@ JSON; $tabularData = new class ($payload) implements TabularData { private readonly array $header; - private readonly ArrayIterator $records; + private readonly ArrayIterator $rows; public function __construct(string $payload) { try { $data = json_decode($payload, true); $this->header = array_keys($data[0] ?? []); - $this->records = new ArrayIterator($data); + $this->rows = new ArrayIterator($data); } catch (Throwable $exception) { throw new ValueError('The provided JSON payload could not be converted into a Tabular Data instance.', previous: $exception); } @@ -135,7 +135,7 @@ $tabularData = new class ($payload) implements TabularData { public function getIterator() : Iterator { - return $this->records; + return $this->rows; } }; diff --git a/src/RdbmsResult.php b/src/RdbmsResult.php index 3b148c13..6f4c67c6 100644 --- a/src/RdbmsResult.php +++ b/src/RdbmsResult.php @@ -39,12 +39,12 @@ final class RdbmsResult implements TabularData { /** - * @param Iterator> $records - * @param array|array{} $headers + * @param Iterator> $rows + * @param array|array{} $header */ private function __construct( - private readonly Iterator $records, - private readonly array $headers + private readonly Iterator $rows, + private readonly array $header ) { } @@ -53,7 +53,7 @@ private function __construct( */ public function getHeader(): array { - return $this->headers; + return $this->header; } /** @@ -61,7 +61,7 @@ public function getHeader(): array */ public function getIterator(): Iterator { - return $this->records; + return $this->rows; } public static function tryFrom(object $result): ?self @@ -78,7 +78,7 @@ public static function tryFrom(object $result): ?self */ public static function from(object $result): self { - return new self(self::records($result), self::columnNames($result)); + return new self(self::rows($result), self::columnNames($result)); } /** @@ -108,7 +108,7 @@ function (int $index) use ($result): string { /** * @return Iterator> */ - public static function records(object $result): Iterator + public static function rows(object $result): Iterator { return match (true) { $result instanceof SQLite3Result => new class ($result) implements Iterator {