type = self::TYPE; $this->title = $title; $this->description = $description; $this->default = $default; } /** * Creates an instance from an array. * * @param array{ * type: 'boolean', * title?: string|null, * description?: string|null, * default?: bool|null * } $data * @phpstan-param array $data * @return self */ public static function fromArray(array $data): self { return new self( self::asStringOrNull($data['title'] ?? null), self::asStringOrNull($data['description'] ?? null), self::asBoolOrNull($data['default'] ?? null) ); } /** * Converts the instance to an array. * * @return array */ public function toArray(): array { $result = []; $result['type'] = $this->type; if ($this->title !== null) { $result['title'] = $this->title; } if ($this->description !== null) { $result['description'] = $this->description; } if ($this->default !== null) { $result['default'] = $this->default; } return $result; } /** * @return 'boolean' */ public function getType(): string { return $this->type; } /** * @return string|null */ public function getTitle(): ?string { return $this->title; } /** * @return string|null */ public function getDescription(): ?string { return $this->description; } /** * @return bool|null */ public function getDefault(): ?bool { return $this->default; } }