From 1079caa2ea257dde74a5541b32084e3925b281ee Mon Sep 17 00:00:00 2001 From: Jean Galea <1651502+jgalea@users.noreply.github.com> Date: Thu, 28 May 2026 21:51:34 +0200 Subject: [PATCH] fix: make handler parameter nullable in WpClient constructor Allows php-http/discovery's ClassDiscovery to instantiate WpClient without arguments. When null is passed, the constructor falls back to HandlerStack::createDefault(). Closes #1 --- src/WpClient.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/WpClient.php b/src/WpClient.php index a6253f6..bc3961d 100644 --- a/src/WpClient.php +++ b/src/WpClient.php @@ -27,14 +27,15 @@ class WpClient implements ClientInterface /** * Constructor. * - * @param HandlerInterface $handler The handler to use for dispatching requests and receiving responses. - * @param UriInterface|null $baseUri Optional base URI for all relative requests sent using this client. + * @param HandlerInterface|null $handler The handler to use for dispatching requests and receiving responses. + * Defaults to {@link HandlerStack::createDefault()} when null. + * @param UriInterface|null $baseUri Optional base URI for all relative requests sent using this client. * * @throws InvalidArgumentException If the "base_uri" option is present and is not a valid URI. */ - public function __construct(HandlerInterface $handler, ?UriInterface $baseUri = null) + public function __construct(?HandlerInterface $handler = null, ?UriInterface $baseUri = null) { - $this->handler = $handler; + $this->handler = $handler ?? HandlerStack::createDefault(); $this->baseUri = $baseUri; }