personalIdentityCode; } self::ensureIdentifiersFitType($type, $businessId, $personalIdentityCode); self::ensureInternalIsCompany($this->internal, $type); $this->name = $name; $this->type = $type; $this->businessId = $businessId; $this->personalIdentityCode = $personalIdentityCode; } public function removePersonalIdentityCode(): void { $this->personalIdentityCode = null; } public function id(): ?int { return $this->id; } public function name(): CustomerName { return $this->name; } public function type(): CustomerType { return $this->type; } public function businessId(): ?BusinessId { return $this->businessId; } public function personalIdentityCode(): ?PersonalIdentityCode { return $this->personalIdentityCode; } /** * The company itself, whose jobs hold internal work (administration, * sales, training). Created by a migration, never through the UI. */ public function isInternal(): bool { return $this->internal; } private static function ensureInternalIsCompany(bool $internal, CustomerType $type): void { if ($internal && $type !== CustomerType::Company) { throw new InternalCustomerMustBeCompany; } } private static function ensureIdentifiersFitType( CustomerType $type, ?BusinessId $businessId, ?PersonalIdentityCode $personalIdentityCode, ): void { if ($type === CustomerType::Consumer && $businessId !== null) { throw new ConsumerCannotHaveBusinessId; } if ($type === CustomerType::Company && $personalIdentityCode !== null) { throw new CompanyCannotHavePersonalIdentityCode; } } }