Skip to content

Commit 78020ff

Browse files
kelunikNyholm
authored andcommitted
Remove unused stream factory (#9)
* Remove unused stream factory * Restore useless parameter and emit deprecation notice if passed This ensures we don't add another parameter which might be a BC break compared to v0.1.0 then. * Make deprecation notice opt-in
1 parent a427c1d commit 78020ff

File tree

3 files changed

+34
-6
lines changed

3 files changed

+34
-6
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
## Unreleased
44

5+
- Ignore useless `StreamFactory` parameter in the constructor of `Http\Adapter\Artax\Client` and emit deprecation notice if it's not `null`.
6+
57
## v0.1.0
68

79
Initial release.

src/Client.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Http\Client\Exception\RequestException;
1010
use Http\Client\HttpClient;
1111
use Http\Discovery\MessageFactoryDiscovery;
12-
use Http\Discovery\StreamFactoryDiscovery;
1312
use Http\Message\ResponseFactory;
1413
use Http\Message\StreamFactory;
1514
use Psr\Http\Message\RequestInterface;
@@ -19,13 +18,23 @@ class Client implements HttpClient
1918
{
2019
private $client;
2120
private $responseFactory;
22-
private $streamFactory;
2321

24-
public function __construct(Artax\Client $client = null, ResponseFactory $responseFactory = null, StreamFactory $streamFactory = null)
25-
{
22+
/**
23+
* @param Artax\Client $client HTTP client implementation.
24+
* @param ResponseFactory $responseFactory Response factory to use or `null` to attempt auto-discovery.
25+
* @param StreamFactory $streamFactory This parameter will be ignored and removed in the next major version.
26+
*/
27+
public function __construct(
28+
Artax\Client $client = null,
29+
ResponseFactory $responseFactory = null,
30+
StreamFactory $streamFactory = null
31+
) {
2632
$this->client = $client ?? new Artax\DefaultClient();
2733
$this->responseFactory = $responseFactory ?? MessageFactoryDiscovery::find();
28-
$this->streamFactory = $streamFactory ?? StreamFactoryDiscovery::find();
34+
35+
if ($streamFactory !== null || \func_num_args() === 3) {
36+
@\trigger_error('The $streamFactory parameter is deprecated and ignored.', \E_USER_DEPRECATED);
37+
}
2938
}
3039

3140
/** {@inheritdoc} */

tests/ClientTest.php

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace Http\Adapter\Artax\Test;
44

55
use Amp\Artax;
6+
use Http\Adapter\Artax\Client;
67
use Http\Client\HttpClient;
78
use Http\Client\Tests\HttpClientTest;
8-
use Http\Adapter\Artax\Client;
99

1010
class ClientTest extends HttpClientTest
1111
{
@@ -17,4 +17,21 @@ protected function createHttpAdapter()
1717

1818
return new Client($client);
1919
}
20+
21+
public function testStreamFactoryDeprecation()
22+
{
23+
$invoked = false;
24+
25+
try {
26+
\set_error_handler(function () use (&$invoked) {
27+
$invoked = true;
28+
}, \E_USER_DEPRECATED);
29+
30+
new Client(null, null, null);
31+
} finally {
32+
\restore_error_handler();
33+
}
34+
35+
$this->assertTrue($invoked);
36+
}
2037
}

0 commit comments

Comments
 (0)