for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Waredesk\Mappers;
use Waredesk\Collections\Products\Variants;
use Waredesk\Mappers\Product\VariantsMapper;
use Waredesk\Models\Product;
use DateTime;
class ProductMapper
{
public function map(Product $product, array $data): Product
$finalData = [];
foreach ($data as $key => $value) {
switch ($key) {
case 'id':
$finalData['id'] = (int)$value;
break;
case 'variants':
$finalData['variants'] = (new VariantsMapper())->map(new Variants(), $value);
case 'creation_datetime':
$finalData['creation_datetime'] = new DateTime($value);
case 'modification_datetime':
$finalData['modification_datetime'] = new DateTime($value);
default:
$finalData[$key] = $value;
}
$product->reset($finalData);
return $product;