- Removed fully qualified names for better readability. - Streamlined code by using direct class references.
40 lines
1 KiB
PHP
40 lines
1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Domain\Events\Dto;
|
|
|
|
use Domain\Models\ValueObjects\DeliveryAddress;
|
|
|
|
final readonly class OrderPlacedShop
|
|
{
|
|
public function __construct(
|
|
public string $name,
|
|
public string $address,
|
|
public string $postcode,
|
|
public string $city,
|
|
) {
|
|
if (empty(trim($name))) {
|
|
throw new \DomainException('Shop name is required');
|
|
}
|
|
if (empty(trim($address))) {
|
|
throw new \DomainException('Shop address is required');
|
|
}
|
|
if (empty(trim($postcode))) {
|
|
throw new \DomainException('Shop postcode is required');
|
|
}
|
|
if (empty(trim($city))) {
|
|
throw new \DomainException('Shop city is required');
|
|
}
|
|
}
|
|
|
|
public static function fromDeliveryAddress(DeliveryAddress $address): self
|
|
{
|
|
return new self(
|
|
name: $address->name,
|
|
address: $address->address,
|
|
postcode: $address->postcode,
|
|
city: $address->city,
|
|
);
|
|
}
|
|
}
|