Skip to content

Commit a6bce7a

Browse files
authored
Refactor to remove "guzzle specific" logic (#177)
1 parent fef8475 commit a6bce7a

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

src/Strategy/CommonClassesStrategy.php

+7-13
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ final class CommonClassesStrategy implements DiscoveryStrategy
9898
],
9999
[
100100
'class' => GuzzleHttp::class,
101-
'condition' => GuzzleHttp::class,
101+
'condition' => [self::class, 'isGuzzleImplementingPsr18'],
102102
],
103103
[
104104
'class' => [self::class, 'buzzInstantiate'],
@@ -125,18 +125,7 @@ public static function getCandidates($type)
125125
*/
126126
private static function getPsr18Candidates()
127127
{
128-
$candidates = [];
129-
130-
// Guzzle 6 does not implement the PSR-18 client interface, but Guzzle 7 does.
131-
foreach (self::$classes[Psr18Client::class] ?? [] as $c) {
132-
if (GuzzleHttp::class === $c['class']) {
133-
if (defined('GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
134-
$candidates[] = $c;
135-
}
136-
} else {
137-
$candidates[] = $c;
138-
}
139-
}
128+
$candidates = self::$classes[Psr18Client::class];
140129

141130
// HTTPlug 2.0 clients implements PSR18Client too.
142131
foreach (self::$classes[HttpClient::class] as $c) {
@@ -162,6 +151,11 @@ public static function symfonyPsr18Instantiate()
162151
return new SymfonyPsr18(null, Psr17FactoryDiscovery::findResponseFactory(), Psr17FactoryDiscovery::findStreamFactory());
163152
}
164153

154+
public static function isGuzzleImplementingPsr18()
155+
{
156+
return defined('GuzzleHttp\ClientInterface::MAJOR_VERSION');
157+
}
158+
165159
/**
166160
* Can be used as a condition.
167161
*

0 commit comments

Comments
 (0)