userId; } public function getPortalId(): ?string { return $this->portalId; } public function getHash(): ?string { return $this->hash; } public function getIpAddress(): ?string { return $this->ipAddress; } public function toCreateSecret(): bool { return $this->createSecret; } public static function create(array $data): self { $object = new self(); $object->userId = $data['userId'] ?? null; $object->portalId = $data['portalId'] ?? null; $object->hash = $data['hash'] ?? null; $object->ipAddress = $data['ipAddress'] ?? null; $object->createSecret = $data['createSecret'] ?? false; $object->validate(); return $object; } protected function validate() { // @todo Use typed properties when php 7.4 is a min supported version. if ( isset($this->userId) && !is_string($this->userId) || isset($this->portalId) && !is_string($this->portalId) || isset($this->hash) && !is_string($this->hash) || isset($this->ipAddress) && !is_string($this->ipAddress) || !is_bool($this->createSecret) ) { throw new RuntimeException("Invalid data."); } if (!$this->userId) { throw new RuntimeException("No user ID."); } } }