Skip to content

Commit

Permalink
Hide data in ArrayMemory by default (#952)
Browse files Browse the repository at this point in the history
  • Loading branch information
stloyd authored Feb 2, 2024
1 parent 824f2da commit e22b300
Show file tree
Hide file tree
Showing 43 changed files with 89 additions and 96 deletions.
23 changes: 8 additions & 15 deletions src/core/etl/src/Flow/ETL/Memory/ArrayMemory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,13 @@
final class ArrayMemory implements \Countable, Memory
{
/**
* @var array<array<string, mixed>>
*/
public array $data;

/**
* @param array<mixed> $memory
* @param array<array-key, array<string, mixed>> $memory
*
* @throws InvalidArgumentException
*/
public function __construct(array $memory = [])
public function __construct(private array $memory = [])
{
$this->assertMemoryStructure($memory);
/** @var array<array-key, array<string, mixed>> $memory */
$this->data = $memory;
}

/**
Expand All @@ -36,7 +29,7 @@ public function chunks(int $size) : array

$chunks = [];

foreach (\array_chunk($this->data, $size) as $chunk) {
foreach (\array_chunk($this->memory, $size) as $chunk) {
$chunks[] = new self($chunk);
}

Expand All @@ -45,7 +38,7 @@ public function chunks(int $size) : array

public function count() : int
{
return \count($this->data);
return \count($this->memory);
}

/**
Expand All @@ -55,7 +48,7 @@ public function count() : int
*/
public function dump() : array
{
return $this->data;
return $this->memory;
}

/**
Expand All @@ -70,7 +63,7 @@ public function flatValues() : array
{
$data = [];

foreach ($this->data as $entry) {
foreach ($this->memory as $entry) {
$data[] = \array_values($entry);
}

Expand All @@ -86,7 +79,7 @@ public function map(callable $callback) : array
{
$data = [];

foreach ($this->data as $entry) {
foreach ($this->memory as $entry) {
$data[] = $callback($entry);
}

Expand All @@ -100,7 +93,7 @@ public function save(array $data) : void
{
$this->assertMemoryStructure($data);

$this->data = \array_merge($this->data, $data);
$this->memory = \array_merge($this->memory, $data);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function test_adding_new_entries() : void
['id' => 1, 'updated_at' => new \DateTimeImmutable('2020-01-01T00:00:00+00:00')],
['id' => 2, 'updated_at' => new \DateTimeImmutable('2020-01-01T00:00:00+00:00')],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function test_add_json_into_existing_reference() : void
[
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4]],
],
$memory->data
$memory->dump()
);
}

Expand All @@ -52,7 +52,7 @@ public function test_add_json_string_into_existing_reference() : void
[
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4]],
],
$memory->data
$memory->dump()
);
}

Expand All @@ -74,7 +74,7 @@ public function test_adding_json_as_object_from_string_entry() : void
'json' => '{"id":1,"name":"test"}',
],
],
$memory->data
$memory->dump()
);
}

Expand All @@ -95,7 +95,7 @@ public function test_adding_json_from_string_entry() : void
'json' => '[{"id":1},{"id":2}]',
],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function test_all_cases_found() : void
['id' => 3, 'result' => 'not found'],
['id' => 4, 'result' => 'found'],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function test_any_case_found() : void
['id' => 3, 'result' => 'not found'],
['id' => 4, 'result' => 'found'],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function test_array_exists() : void
['id' => 1, 'has_array' => true],
['id' => 2, 'has_array' => false],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function test_expand_both() : void
['id' => 1, 'expanded' => ['b' => 2]],
['id' => 1, 'expanded' => ['c' => 3]],
],
$memory->data
$memory->dump()
);
}

Expand All @@ -61,7 +61,7 @@ public function test_expand_keys() : void
['id' => 1, 'expanded' => 'b'],
['id' => 1, 'expanded' => 'c'],
],
$memory->data
$memory->dump()
);
}

Expand All @@ -86,7 +86,7 @@ public function test_expand_values() : void
['id' => 1, 'expanded' => 2],
['id' => 1, 'expanded' => 3],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function test_array_get_collection() : void
['id' => 1, 'result' => [['a' => 1, 'c' => 3], ['a' => 1, 'c' => 3], ['a' => 1, 'c' => 3]]],
['id' => 2, 'result' => null],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function test_array_get() : void
['id' => 1, 'result' => 2],
['id' => 2, 'result' => null],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function test_array_key_rename() : void
['id' => 1, 'array' => ['b' => 2, 'c' => 3, 'd' => 1]],
['id' => 2, 'array' => null],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function test_array_keys_style_convert() : void
[
['id' => 1, 'array' => ['camel-cased' => 1, 'snake-cased' => 2, 'space-word' => 3]],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function test_array_merge_collection() : void
['id' => 1, 'result' => ['a' => 1, 'b' => 2, 'c' => 3]],
['id' => 2, 'result' => null],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function test_array_merge() : void
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]],
['id' => 2, 'array' => null],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function test_array_reverse() : void
['id' => 1, 'array' => ['c' => 3, 'b' => 2, 'a' => 1]],
['id' => 2, 'array' => null],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function test_array_sort() : void
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]],
['id' => 2, 'array' => null],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function test_array_unpack() : void
['id' => 1, 'a' => 1, 'b' => 2, 'c' => 3],
['id' => 2],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function test_between_comparisons() : void
'not_between' => false,
],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function test_all_comparisons() : void
'type' => false,
],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function test_to_lower() : void
[
['key' => 'this is title', 'capitalized' => 'This Is Title'],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function test_cast() : void
[
['date' => '2023-01-01T00:00:00+00:00'],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function test_combine() : void
['id' => 1, 'array' => ['a' => 1, 'b' => 2, 'c' => 3]],
['id' => 2, 'array' => null],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function test_concat_on_non_string_value() : void
['id' => 1, 'concat' => null],
['id' => 2, 'concat' => null],
],
$memory->data
$memory->dump()
);
}

Expand All @@ -61,7 +61,7 @@ public function test_concat_on_stringable_value() : void
['id' => 1, 'concat' => '1-value'],
['id' => 2, 'concat' => null],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function test_contains() : void
[
['key' => 'value', 'contains' => true],
],
$memory->data
$memory->dump()
);
}

Expand All @@ -54,7 +54,7 @@ public function test_contains_on_non_string_key() : void
[
['id' => 1, 'contains' => false],
],
$memory->data
$memory->dump()
);
}

Expand All @@ -76,7 +76,7 @@ public function test_contains_on_non_string_value() : void
[
['id' => '1', 'contains' => false],
],
$memory->data
$memory->dump()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function test_count_on_array() : void
[
['array' => [1, 2, 3], 'count' => 3],
],
$memory->data
$memory->dump()
);
}

Expand All @@ -53,7 +53,7 @@ public function test_count_on_non_countable() : void
[
['key' => 1, 'count' => null],
],
$memory->data
$memory->dump()
);
}

Expand All @@ -77,7 +77,7 @@ public function test_count_on_object() : void
[
['key' => $iterator, 'count' => 3],
],
$memory->data
$memory->dump()
);
}
}
Loading

0 comments on commit e22b300

Please sign in to comment.