@@ -148,23 +148,28 @@ public function __construct(
148148 }
149149
150150 /**
151- * Immutable setter. Sets a http client and factories.
151+ * Creates an instance with http client and factories.
152152 *
153153 * It is recommended for the http client to have a timeout of e.g. 10
154154 * seconds, to avoid hanging requests. The timeout from ->setTimeout() will
155155 * have no effect on an instance created in this way.
156156 */
157- public function withHttpClient (
157+ public static function createWithHttpClient (
158158 ClientInterface $ httpClient ,
159159 RequestFactoryInterface $ requestFactory ,
160160 StreamFactoryInterface $ streamFactory ,
161+ ?string $ baseUrl = null ,
162+ ?string $ secret = null ,
161163 ): static {
162- $ clone = clone $ this ;
163- $ clone ->httpClient = $ httpClient ;
164- $ clone ->requestFactory = $ requestFactory ;
165- $ clone ->streamFactory = $ streamFactory ;
166-
167- return $ clone ;
164+ // Extending classes need to override this method, if they change the
165+ // constructor signature.
166+ // @phpstan-ignore new.static
167+ $ instance = new static ($ baseUrl , $ secret );
168+ $ instance ->httpClient = $ httpClient ;
169+ $ instance ->requestFactory = $ requestFactory ;
170+ $ instance ->streamFactory = $ streamFactory ;
171+
172+ return $ instance ;
168173 }
169174
170175 /**
0 commit comments