From c619fab4149ca0d76bcc854024cb4ec77e34fd9d Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz <1921950+norberttech@users.noreply.github.com> Date: Mon, 22 Jul 2024 23:31:30 +0200 Subject: [PATCH] Deprecate Schema::entries in favor to Schema::references (#1137) * Deprecate Schema::entries in favor to Schema::references * Added References::names() helper method --- src/core/etl/src/Flow/ETL/Row/References.php | 14 +++++++++++++ src/core/etl/src/Flow/ETL/Row/Schema.php | 21 ++++++++++++------- .../ETL/Row/Schema/SelectiveValidator.php | 2 +- .../ETL/Tests/Unit/Row/ReferencesTest.php | 10 +++++++++ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/src/core/etl/src/Flow/ETL/Row/References.php b/src/core/etl/src/Flow/ETL/Row/References.php index cd8b6f4d9..0c0ad89ad 100644 --- a/src/core/etl/src/Flow/ETL/Row/References.php +++ b/src/core/etl/src/Flow/ETL/Row/References.php @@ -92,6 +92,20 @@ public function has(string|Reference $reference) : bool return false; } + /** + * @return array + */ + public function names() : array + { + $names = []; + + foreach ($this->refs as $ref) { + $names[] = $ref->name(); + } + + return $names; + } + /** * @param string $offset * diff --git a/src/core/etl/src/Flow/ETL/Row/Schema.php b/src/core/etl/src/Flow/ETL/Row/Schema.php index 3f095b5ab..de20a72ea 100644 --- a/src/core/etl/src/Flow/ETL/Row/Schema.php +++ b/src/core/etl/src/Flow/ETL/Row/Schema.php @@ -55,17 +55,13 @@ public function definitions() : array } /** + * @deprecated use references() : References instead + * * @return array */ public function entries() : array { - $refs = []; - - foreach ($this->definitions as $definition) { - $refs[] = $definition->entry(); - } - - return $refs; + return $this->references()->all(); } public function findDefinition(string|Reference $ref) : ?Definition @@ -211,6 +207,17 @@ public function nullable() : self return $this->makeNullable(); } + public function references() : References + { + $refs = []; + + foreach ($this->definitions as $definition) { + $refs[] = $definition->entry(); + } + + return References::init(...$refs); + } + public function remove(string|Reference ...$entries) : self { $refs = References::init(...$entries); diff --git a/src/core/etl/src/Flow/ETL/Row/Schema/SelectiveValidator.php b/src/core/etl/src/Flow/ETL/Row/Schema/SelectiveValidator.php index d97f5cb98..9a6a4a4ba 100644 --- a/src/core/etl/src/Flow/ETL/Row/Schema/SelectiveValidator.php +++ b/src/core/etl/src/Flow/ETL/Row/Schema/SelectiveValidator.php @@ -15,7 +15,7 @@ final class SelectiveValidator implements SchemaValidator { public function isValid(Rows $rows, Schema $schema) : bool { - foreach ($schema->entries() as $ref) { + foreach ($schema->references() as $ref) { $definition = $schema->getDefinition($ref); foreach ($rows as $row) { diff --git a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/ReferencesTest.php b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/ReferencesTest.php index ff04f6197..a63c9d4c1 100644 --- a/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/ReferencesTest.php +++ b/src/core/etl/tests/Flow/ETL/Tests/Unit/Row/ReferencesTest.php @@ -20,6 +20,16 @@ public function test_lazy_without() : void ); } + public function test_references_names() : void + { + $refs = refs('id', 'name'); + + self::assertEquals( + ['id', 'name'], + $refs->names() + ); + } + public function test_that_reference_with_alias_exists() : void { $refs = new References(ref('id')->as('test'), ref('name'));