Skip to content

Commit

Permalink
Add toArray methods to new value objects
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamVyborny committed May 6, 2024
1 parent a099371 commit fb5692a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function toArray(): array
$result['columns'] = $this->columns;
}
if (isset($this->schema)) {
$result['schema'] = $this->schema;
$result['schema'] = $this->schema->toArray();
}
if (isset($this->incremental)) {
$result['incremental'] = $this->incremental;
Expand All @@ -75,16 +75,16 @@ public function toArray(): array
$result['column_metadata'] = $this->columnMetadata;
}
if (isset($this->manifestType)) {
$result['manifestType'] = $this->manifestType;
$result['manifest_type'] = $this->manifestType;
}
if (isset($this->hasHeader)) {
$result['hasHeader'] = $this->hasHeader;
$result['has_header'] = $this->hasHeader;
}
if (isset($this->description)) {
$result['description'] = $this->description;
}
if (isset($this->tableMetadata)) {
$result['tableMetadata'] = $this->tableMetadata;
$result['table_metadata'] = $this->tableMetadata;
}
return $result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,30 @@ public function __construct(
$this->setMetadata($metadata);
}

public function toArray(): array
{
$result = [
'name' => $this->name,
'data_type' => [],
'nullable' => $this->nullable,
'primary_key' => $this->primaryKey,
];

foreach ($this->dataType as $backendType => $dataType) {
$result['data_type'][$backendType] = $dataType->toArray();
}

if (isset($this->description)) {
$result['description'] = $this->description;
}

if (isset($this->metadata)) {
$result['metadata'] = $this->metadata;
}

return $result;
}

private function setDataType(array $dataTypes): void
{
foreach ($dataTypes as $backendType => $config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,21 @@ public function __construct(string $type, ?string $length = null, ?string $defau
$this->length = $length;
$this->default = $default;
}

public function toArray(): array
{
$result = [
'type' => $this->type,
];

if (isset($this->length)) {
$result['length'] = $this->length;
}

if (isset($this->default)) {
$result['default'] = $this->default;
}

return $result;
}
}

0 comments on commit fb5692a

Please sign in to comment.