36 lines
1 KiB
PHP
36 lines
1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
namespace Domain\Models\ValueObjects\Coupon;
|
||
|
|
|
||
|
|
use Shared\Enums\Country;
|
||
|
|
|
||
|
|
final readonly class CouponValidityInformationArray
|
||
|
|
{
|
||
|
|
public function __construct(
|
||
|
|
/** @var CouponValidityInformation[] */
|
||
|
|
public array $value,
|
||
|
|
) {
|
||
|
|
if ($this->value === []) {
|
||
|
|
throw new \DomainException('CouponValidityInformations requires at least one CouponValidityInformation.');
|
||
|
|
}
|
||
|
|
|
||
|
|
$hasFrance = false;
|
||
|
|
|
||
|
|
foreach ($this->value as $couponLegalInformation) {
|
||
|
|
if (! $couponLegalInformation instanceof CouponValidityInformation) {
|
||
|
|
throw new \DomainException('Value of CouponValidityInformationArray must be CouponValidityInformation instances.');
|
||
|
|
}
|
||
|
|
|
||
|
|
if ($couponLegalInformation->forLocale === Country::FRANCE) {
|
||
|
|
$hasFrance = true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
if (! $hasFrance) {
|
||
|
|
throw new \DomainException('CouponValidityInformations requires a CouponValidityInformation for France.');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|