Skip to content

Commit b621fbd

Browse files
authored
Merge pull request #473 from php-http/strict-typing
Declare parameter and return types
2 parents ffeb988 + a996b9b commit b621fbd

26 files changed

+137
-278
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ The change log describes what is "Added", "Removed", "Changed" or "Fixed" betwee
2020
- Removed the `DummyClient` interface
2121
- Removed the `Http\Client\HttpClient` alias use the `Psr\Http\Client\ClientInterface` typehint in your services for autowiring.
2222
- Changed classes marked as `@final` to be actually `final`. If you extended any of those, instead implement interfaces or decorate the class rather than extending it. Open an issue if you think a class needs to be made non-final to discuss what we should do.
23+
- Added return type declaration to `Http\HttplugBundle\ClientFactory\ClientFactory::createClient`
2324

2425
# Version 1
2526

src/ClientFactory/AutoDiscoveryFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Http\HttplugBundle\ClientFactory;
66

77
use Http\Discovery\Psr18ClientDiscovery;
8+
use Psr\Http\Client\ClientInterface;
89

910
/**
1011
* Use auto discovery to find a HTTP client.
@@ -13,7 +14,7 @@
1314
*/
1415
final class AutoDiscoveryFactory implements ClientFactory
1516
{
16-
public function createClient(array $config = [])
17+
public function createClient(array $config = []): ClientInterface
1718
{
1819
return Psr18ClientDiscovery::find();
1920
}

src/ClientFactory/BuzzFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Http\HttplugBundle\ClientFactory;
66

77
use Buzz\Client\FileGetContents;
8+
use Psr\Http\Client\ClientInterface;
89
use Psr\Http\Message\ResponseFactoryInterface;
910
use Symfony\Component\OptionsResolver\OptionsResolver;
1011

@@ -17,7 +18,7 @@ public function __construct(private readonly ResponseFactoryInterface $responseF
1718
{
1819
}
1920

20-
public function createClient(array $config = [])
21+
public function createClient(array $config = []): ClientInterface
2122
{
2223
if (!class_exists('Buzz\Client\FileGetContents')) {
2324
throw new \LogicException('To use the Buzz you need to install the "kriswallsmith/buzz" package.');
@@ -29,7 +30,7 @@ public function createClient(array $config = [])
2930
/**
3031
* Get options to configure the Buzz client.
3132
*/
32-
private function getOptions(array $config = [])
33+
private function getOptions(array $config = []): array
3334
{
3435
$resolver = new OptionsResolver();
3536

src/ClientFactory/ClientFactory.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ interface ClientFactory
1313
{
1414
/**
1515
* Input an array of configuration to be able to create a ClientInterface.
16-
*
17-
* @return ClientInterface
1816
*/
19-
public function createClient(array $config = []);
17+
public function createClient(array $config = []): ClientInterface;
2018
}

src/ClientFactory/CurlFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Http\HttplugBundle\ClientFactory;
66

77
use Http\Client\Curl\Client;
8+
use Psr\Http\Client\ClientInterface;
89
use Psr\Http\Message\ResponseFactoryInterface;
910
use Psr\Http\Message\StreamFactoryInterface;
1011

@@ -19,7 +20,7 @@ public function __construct(
1920
) {
2021
}
2122

22-
public function createClient(array $config = [])
23+
public function createClient(array $config = []): ClientInterface
2324
{
2425
if (!class_exists('Http\Client\Curl\Client')) {
2526
throw new \LogicException('To use the Curl client you need to install the "php-http/curl-client" package.');

src/ClientFactory/Guzzle6Factory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
namespace Http\HttplugBundle\ClientFactory;
66

77
use Http\Adapter\Guzzle6\Client;
8+
use Psr\Http\Client\ClientInterface;
89

910
/**
1011
* @author Tobias Nyholm <[email protected]>
1112
*/
1213
final class Guzzle6Factory implements ClientFactory
1314
{
14-
public function createClient(array $config = [])
15+
public function createClient(array $config = []): ClientInterface
1516
{
1617
if (!class_exists('Http\Adapter\Guzzle6\Client')) {
1718
throw new \LogicException('To use the Guzzle6 adapter you need to install the "php-http/guzzle6-adapter" package.');

src/ClientFactory/Guzzle7Factory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
namespace Http\HttplugBundle\ClientFactory;
66

77
use Http\Adapter\Guzzle7\Client;
8+
use Psr\Http\Client\ClientInterface;
89

910
/**
1011
* @author Tobias Nyholm <[email protected]>
1112
*/
1213
final class Guzzle7Factory implements ClientFactory
1314
{
14-
public function createClient(array $config = [])
15+
public function createClient(array $config = []): ClientInterface
1516
{
1617
if (!class_exists('Http\Adapter\Guzzle7\Client')) {
1718
throw new \LogicException('To use the Guzzle7 adapter you need to install the "php-http/guzzle7-adapter" package.');

src/ClientFactory/MockFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class MockFactory implements ClientFactory
1919
*
2020
* Note that this can be any client, not only a mock client.
2121
*/
22-
public function setClient(ClientInterface $client)
22+
public function setClient(ClientInterface $client): void
2323
{
2424
$this->client = $client;
2525
}
2626

27-
public function createClient(array $config = [])
27+
public function createClient(array $config = []): ClientInterface
2828
{
2929
if (!class_exists(Client::class)) {
3030
throw new \LogicException('To use the mock adapter you need to install the "php-http/mock-client" package.');

src/ClientFactory/ReactFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
namespace Http\HttplugBundle\ClientFactory;
66

77
use Http\Adapter\React\Client;
8+
use Psr\Http\Client\ClientInterface;
89

910
/**
1011
* @author Tobias Nyholm <[email protected]>
1112
*/
1213
final class ReactFactory implements ClientFactory
1314
{
14-
public function createClient(array $config = [])
15+
public function createClient(array $config = []): ClientInterface
1516
{
1617
if (!class_exists('Http\Adapter\React\Client')) {
1718
throw new \LogicException('To use the React adapter you need to install the "php-http/react-adapter" package.');

src/ClientFactory/SocketFactory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
namespace Http\HttplugBundle\ClientFactory;
66

77
use Http\Client\Socket\Client;
8+
use Psr\Http\Client\ClientInterface;
89

910
/**
1011
* @author Tobias Nyholm <[email protected]>
1112
*/
1213
final class SocketFactory implements ClientFactory
1314
{
14-
public function createClient(array $config = [])
15+
public function createClient(array $config = []): ClientInterface
1516
{
1617
if (!class_exists('Http\Client\Socket\Client')) {
1718
throw new \LogicException('To use the Socket client you need to install the "php-http/socket-client" package.');

0 commit comments

Comments
 (0)