Skip to content

Commit d4ac176

Browse files
committed
Use a static factory instead of the immutable setter.
1 parent 85d5cde commit d4ac176

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/BigBlueButton.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,23 +144,28 @@ public function __construct(?string $baseUrl = null, ?string $secret = null, ?ar
144144
}
145145

146146
/**
147-
* Immutable setter. Sets a http client and factories.
147+
* Creates an instance with http client and factories.
148148
*
149149
* It is recommended for the http client to have a timeout of e.g. 10
150150
* seconds, to avoid hanging requests. The timeout from ->setTimeout() will
151151
* have no effect on an instance created in this way.
152152
*/
153-
public function withHttpClient(
153+
public static function createWithHttpClient(
154154
ClientInterface $httpClient,
155155
RequestFactoryInterface $requestFactory,
156156
StreamFactoryInterface $streamFactory,
157+
?string $baseUrl = null,
158+
?string $secret = null,
157159
): static {
158-
$clone = clone $this;
159-
$clone->httpClient = $httpClient;
160-
$clone->requestFactory = $requestFactory;
161-
$clone->streamFactory = $streamFactory;
162-
163-
return $clone;
160+
// Extending classes need to override this method, if they change the
161+
// constructor signature.
162+
// @phpstan-ignore new.static
163+
$instance = new static($baseUrl, $secret);
164+
$instance->httpClient = $httpClient;
165+
$instance->requestFactory = $requestFactory;
166+
$instance->streamFactory = $streamFactory;
167+
168+
return $instance;
164169
}
165170

166171
/**

0 commit comments

Comments
 (0)