9999 || $sequence < 1) { throw new InvalidArgumentException('A job number needs a four-digit year and a positive sequence.'); } } public static function fromString(string $value): self { if (preg_match('/^(\d{4})-(\d{4,})$/', $value, $parts) !== 1) { throw new InvalidArgumentException("Not a job number: {$value}"); } return new self((int) $parts[1], (int) $parts[2]); } public function format(): string { return sprintf('%04d-%04d', $this->year, $this->sequence); } }