2025-06-02 06:37:37 +02:00

26 lines
925 B
PHP

<?php
namespace App\Infrastructure\PostgreSQL\Repository\CarModelRepository;
use App\Domain\Model\CarModel;
use App\Domain\Model\Brand;
use App\Domain\Model\Value\BrandId;
use App\Domain\Model\Value\CarModelId;
class ModelMapper
{
/**
* @param array<string, mixed> $row - Single car model row from database
*/
public function map(array $row): CarModel
{
$carModelId = is_string($row['id'] ?? null) ? $row['id'] : throw new \InvalidArgumentException('CarModel ID is required');
$brandId = is_string($row['brand_id'] ?? null) ? $row['brand_id'] : throw new \InvalidArgumentException('Brand ID is required');
return new CarModel(
carModelId: new CarModelId($carModelId),
brandId: new BrandId($brandId),
name: is_string($row['name'] ?? null) ? $row['name'] : throw new \InvalidArgumentException('CarModel name is required'),
);
}
}