2026-09-01 18:54:47 +02:00
|
|
|
<?php
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Domain\Jobcard;
|
|
|
|
|
|
|
|
|
|
final class JobcardReference
|
|
|
|
|
{
|
|
|
|
|
public static function generate(int $sequence, ?int $year = null): string
|
|
|
|
|
{
|
2026-09-01 19:34:41 +02:00
|
|
|
if ($sequence < 1 || $sequence > 999999) {
|
|
|
|
|
throw new \InvalidArgumentException('Sequence must be between 1 and 999999.');
|
2026-09-01 18:54:47 +02:00
|
|
|
}
|
|
|
|
|
$year ??= (int) date('Y');
|
|
|
|
|
if ($year < 2000 || $year > 9999) {
|
|
|
|
|
throw new \InvalidArgumentException('Year must be four digits.');
|
|
|
|
|
}
|
|
|
|
|
return sprintf('JC-%04d-%06d', $year, $sequence);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static function isValid(string $reference): bool
|
|
|
|
|
{
|
|
|
|
|
return preg_match('/^JC-\d{4}-\d{6}$/', $reference) === 1;
|
|
|
|
|
}
|
|
|
|
|
}
|