Skip to content

Commit

Permalink
Deprecate Schema::entries in favor to Schema::references (#1137)
Browse files Browse the repository at this point in the history
* Deprecate Schema::entries in favor to Schema::references

* Added References::names() helper method
  • Loading branch information
norberttech authored Jul 22, 2024
1 parent 21aac68 commit c619fab
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
14 changes: 14 additions & 0 deletions src/core/etl/src/Flow/ETL/Row/References.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ public function has(string|Reference $reference) : bool
return false;
}

/**
* @return array<string>
*/
public function names() : array
{
$names = [];

foreach ($this->refs as $ref) {
$names[] = $ref->name();
}

return $names;
}

/**
* @param string $offset
*
Expand Down
21 changes: 14 additions & 7 deletions src/core/etl/src/Flow/ETL/Row/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,13 @@ public function definitions() : array
}

/**
* @deprecated use references() : References instead
*
* @return array<Reference>
*/
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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions src/core/etl/tests/Flow/ETL/Tests/Unit/Row/ReferencesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit c619fab

Please sign in to comment.