gabrielbull/php-waredesk-api

View on GitHub
src/Mappers/Product/Variant/AttributeMapper.php

Summary

Maintainability
A
2 hrs
Test Coverage
<?php

namespace Waredesk\Mappers\Product\Variant;

use DateTime;
use Waredesk\Mapper;
use Waredesk\Models\Product\Variant\Attribute;

class AttributeMapper extends Mapper
{
    public function map(Attribute $attribute, $data): Attribute
    {
        $finalData = [];
        foreach ($data as $key => $value) {
            switch ($key) {
                case 'creation':
                    $finalData['creation'] = new DateTime($value);
                    break;
                case 'modification':
                    $finalData['modification'] = new DateTime($value);
                    break;
                default:
                    $finalData[$key] = $value;
                    break;
            }
        }
        $attribute->reset($finalData);
        return $attribute;
    }
}