58 lines
1.7 KiB
PHP
58 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Domain\Models\Entities;
|
|
|
|
use Carbon\CarbonImmutable;
|
|
use Carbon\CarbonInterface;
|
|
use Domain\Models\ValueObjects\Email;
|
|
use Domain\Models\ValueObjects\Entities\ShopperId;
|
|
use Domain\Models\ValueObjects\Matricule;
|
|
use Domain\Models\ValueObjects\ShopperEstablishmentCode;
|
|
use Domain\Models\ValueObjects\ShopperServiceCode;
|
|
use Domain\Models\ValueObjects\ShopperSiteCode;
|
|
use Shared\DDD\Entity;
|
|
|
|
/** @implements \Shared\DDD\Entity<\Domain\Models\ValueObjects\Entities\ShopperId> */
|
|
final class Shopper implements Entity
|
|
{
|
|
private const string BUSINESS_TIMEZONE = 'Europe/Paris';
|
|
|
|
public function __construct(
|
|
private readonly ShopperId $id,
|
|
public readonly Email $email,
|
|
public readonly Matricule $matricule,
|
|
public readonly string $nom,
|
|
public readonly string $prenom,
|
|
public readonly CarbonInterface $startDate,
|
|
public readonly ?CarbonInterface $endDate,
|
|
public readonly ShopperEstablishmentCode $etablissement,
|
|
public readonly ShopperSiteCode $site,
|
|
public readonly ShopperServiceCode $service
|
|
) {
|
|
if (trim($nom) === '') {
|
|
throw new \DomainException('nom cannot be empty');
|
|
}
|
|
if (trim($prenom) === '') {
|
|
throw new \DomainException('prenom cannot be empty');
|
|
}
|
|
}
|
|
|
|
#[\Override]
|
|
public function id(): ShopperId
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function isActive(): bool
|
|
{
|
|
$todayParis = CarbonImmutable::now(self::BUSINESS_TIMEZONE)->format('Y-m-d');
|
|
|
|
if ($this->startDate->format('Y-m-d') > $todayParis) {
|
|
return false;
|
|
}
|
|
|
|
return $this->endDate === null || $this->endDate->format('Y-m-d') > $todayParis;
|
|
}
|
|
}
|