add transformer for underline raw data

This commit is contained in:
karneaud 2024-07-29 16:17:09 -04:00
parent 4c3829b8c1
commit 85220bf58f

View File

@ -0,0 +1,42 @@
<?php
namespace App\Repositories\Import\Quickbooks\Transformers;
use Illuminate\Support\Collection;
class Transformer
{
public function transform(array $items, string $type): Collection
{
if(!method_exists($this, ($method = "transform{$type}s"))) throw new \InvalidArgumentException("Unknown type: $type");
return call_user_func([$this, $method], $items);
}
protected function transformInvoices(array $items): Collection
{
return $this->transformation($items, []);
}
protected function transformCustomers(array $items): Collection
{
return $this->transformation($items, [
'CompanyName',
'PrimaryPhone',
'BillAddr',
'ShipAddr',
'Notes',
'GivenName',
'FamilyName',
'PrimaryEmailAddr',
'CurrencyRef',
'MetaData'
]);
}
protected function transformation(array $items, array $keys) : Collection
{
return collect($items)->select($keys);
}
}