ldc-boutique-cnc-sable/domain/Models/ValueObjects/OrderEmployee.php
Jérémy Munsch 71e0d65f31
refactor(OrderService): simplify order creation from basket
Updated the OrderService to utilize the new fromBasket method for creating orders, enhancing code clarity and maintainability. Removed the ProductAvailabilityService as its functionality is now integrated into the ProductRepository.
2026-10-29 20:21:32 +01:00

41 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Domain\Models\ValueObjects;
use Domain\Models\Entities\Shopper;
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,
) {
$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
);
}
private function assertNotEmpty(string $attribute, string $value): void
{
if (empty(trim($value))) {
throw new \DomainException("{$attribute} cannot be empty");
}
}
}