ldc-boutique-cnc-sable/domain/Models/ValueObjects/OrderEmployee.php

42 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace Domain\Models\ValueObjects;
use Domain\Models\Entities\Shopper;
2026-06-14 21:32:07 +02:00
final readonly class OrderEmployee
{
public function __construct(
public readonly Matricule $matricule,
public readonly string $firstname,
public readonly string $lastname,
public readonly ShopperEstablishmentCode $facility,
public readonly ShopperSiteCode $site,
public readonly ShopperServiceCode $service,
2026-06-14 21:32:07 +02:00
) {
$this->assertNotEmpty('firstname', $firstname);
$this->assertNotEmpty('lastname', $lastname);
}
public static function fromShopper(Shopper $shopper): self
{
return new self(
matricule: clone $shopper->matricule,
firstname: $shopper->prenom,
lastname: $shopper->nom,
facility: $shopper->etablissement,
site: $shopper->site,
service: $shopper->service
);
}
2026-06-14 21:32:07 +02:00
private function assertNotEmpty(string $attribute, string $value): void
{
if (empty(trim($value))) {
throw new \DomainException("{$attribute} cannot be empty");
}
}
}