|null */ protected ?array $params; /** * @param string $method @since 2024-11-05 * @param array|null $params @since 2024-11-05 */ public function __construct( string $method, ?array $params = null ) { $this->method = $method; $this->params = $params; } /** * Creates an instance from an array. * * @param array{ * method: string, * params?: array|null * } $data * @phpstan-param array $data * @return self */ public static function fromArray(array $data): self { self::assertRequired($data, ['method']); return new self( self::asString($data['method']), self::asArrayOrNull($data['params'] ?? null) ); } /** * Converts the instance to an array. * * @return array */ public function toArray(): array { $result = []; $result['method'] = $this->method; if ($this->params !== null) { $result['params'] = $this->params; } return $result; } /** * @return string */ public function getMethod(): string { return $this->method; } /** * @return array|null */ public function getParams(): ?array { return $this->params; } }