Skip to content

Commit

Permalink
simplify adapter picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Naoray committed Jan 6, 2025
1 parent 4b7906d commit 30d245f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 25 deletions.
4 changes: 2 additions & 2 deletions src/Http/Adapter/GuzzleMollieHttpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function factories(): Factories
}

/**
* Instantiate a default adapter with sane configuration for Guzzle 6 or 7.
* Instantiate a default adapter with sane configuration for Guzzle.
*/
public static function createDefault(): self
{
Expand Down Expand Up @@ -132,6 +132,6 @@ protected function createResponse(
*/
public function version(): string
{
return 'Guzzle/'.ClientInterface::MAJOR_VERSION;
return 'Guzzle/' . ClientInterface::MAJOR_VERSION;
}
}
32 changes: 9 additions & 23 deletions src/Http/Adapter/MollieHttpAdapterPicker.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@ class MollieHttpAdapterPicker implements MollieHttpAdapterPickerContract
public function pickHttpAdapter($httpClient): HttpAdapterContract
{
if (! $httpClient) {
if ($this->guzzleIsDetected()) {
$guzzleVersion = $this->guzzleMajorVersionNumber();

if ($guzzleVersion && in_array($guzzleVersion, [6, 7])) {
return GuzzleMollieHttpAdapter::createDefault();
}
}

return new CurlMollieHttpAdapter;
return $this->createDefaultAdapter();
}

if ($httpClient instanceof HttpAdapterContract) {
Expand All @@ -38,23 +30,17 @@ public function pickHttpAdapter($httpClient): HttpAdapterContract
throw new UnrecognizedClientException('The provided http client or adapter was not recognized.');
}

private function guzzleIsDetected(): bool
{
return interface_exists('\\'.\GuzzleHttp\ClientInterface::class);
}

private function guzzleMajorVersionNumber(): ?int
private function createDefaultAdapter(): HttpAdapterContract
{
// Guzzle 7
if (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
return (int) \GuzzleHttp\ClientInterface::MAJOR_VERSION;
if ($this->guzzleIsDetected()) {
return GuzzleMollieHttpAdapter::createDefault();
}

// Before Guzzle 7
if (defined('\GuzzleHttp\ClientInterface::VERSION')) {
return (int) \GuzzleHttp\ClientInterface::VERSION[0];
}
return new CurlMollieHttpAdapter;
}

return null;
private function guzzleIsDetected(): bool
{
return interface_exists('\\' . \GuzzleHttp\ClientInterface::class);
}
}

0 comments on commit 30d245f

Please sign in to comment.