$params */ public static function fromArray(array $params): self { $object = new self(); $object->forbidComplexExpressions = $params['forbidComplexExpressions'] ?? false; $object->forceDefault = $params['forceDefault'] ?? false; $object->orderBy = $params['orderBy'] ?? null; $object->order = $params['order'] ?? null; foreach ($params as $key => $value) { if (!property_exists($object, $key)) { throw new InvalidArgumentException("Unknown parameter '{$key}'."); } } if ($object->orderBy && !is_string($object->orderBy)) { throw new InvalidArgumentException("Bad orderBy."); } if ( $object->order && $object->order !== SearchParams::ORDER_ASC && $object->order !== SearchParams::ORDER_DESC ) { throw new InvalidArgumentException("Bad order."); } return $object; } public function forbidComplexExpressions(): bool { return $this->forbidComplexExpressions; } public function forceDefault(): bool { return $this->forceDefault; } public function getOrderBy(): ?string { /** @var ?string */ return $this->orderBy; } public function getOrder(): ?string { /** @var ?string */ return $this->order; } }