Skip to content

Issue/534 http client curl adapters#562

Merged
armanist merged 14 commits into
quantum-php:masterfrom
armanist:issue/534-http-client-curl-adapters
Jul 15, 2026
Merged

Issue/534 http client curl adapters#562
armanist merged 14 commits into
quantum-php:masterfrom
armanist:issue/534-http-client-curl-adapters

Conversation

@armanist

@armanist armanist commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Closes #534

This PR separates HttpClient execution behind Quantum-owned CurlAdapter and MultiCurlAdapter wrappers while preserving the existing HttpClient facade and keeping php-curl-class underneath for this phase.

It does not remove php-curl-class yet. That is intentionally deferred so native curl replacement can be implemented and reviewed separately against the adapter contracts introduced here.

Retiring php-curl-class/php-curl-class will be handled in follow-up ticket(s).

Summary by CodeRabbit

  • New Features
    • Introduced adapter-based HTTP handling for both single and multi requests.
    • Added public access to the currently active adapter.
    • Added adapter interfaces and a factory to create/reuse the HTTP client.
    • Added constants for supported HTTP client types.
  • Bug Fixes
    • Improved compatibility for info(0) calls (now verified by tests).
  • Tests
    • Added/expanded unit tests for adapters, factory, and client behavior.
  • Documentation
    • Updated the changelog for version 3.1.0.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

HttpClient adapter refactor

Layer / File(s) Summary
Adapter contracts and factory
src/HttpClient/Contracts/*, src/HttpClient/Enums/HttpClientType.php, src/HttpClient/Factories/HttpClientFactory.php
Adds shared adapter interfaces, client type constants, and lazy factory resolution for HttpClient.
Single-request CurlAdapter
src/HttpClient/Adapters/CurlAdapter.php, tests/Unit/HttpClient/Adapters/CurlAdapterTest.php
Wraps single-request configuration, execution, response inspection, and vendor-method forwarding.
Multi-request MultiCurlAdapter
src/HttpClient/Adapters/MultiCurlAdapter.php, tests/Unit/HttpClient/Adapters/MultiCurlAdapterTest.php
Wraps queued requests, callbacks, configuration, execution, and dynamic method forwarding.
HttpClient adapter integration
src/HttpClient/HttpClient.php, tests/Unit/HttpClient/HttpClientTest.php, CHANGELOG.md
Routes single and multi request flows through adapters, exposes the active adapter, updates response handling and dispatch, and records the refactor.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant HttpClient
  participant CurlAdapter
  participant MultiCurlAdapter
  participant php-curl-class
  HttpClient->>CurlAdapter: create and configure single request
  CurlAdapter->>php-curl-class: forward request operations
  php-curl-class-->>CurlAdapter: return execution and response data
  HttpClient->>MultiCurlAdapter: queue requests and register callbacks
  MultiCurlAdapter->>php-curl-class: start multi request
  php-curl-class-->>MultiCurlAdapter: invoke callback with Curl
  MultiCurlAdapter-->>HttpClient: provide CurlAdapter callback argument
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds adapter wrappers, but it defers the native curl migration and php-curl-class deprecation required by #534. Implement native single/multi curl adapters, deprecate/remove php-curl-class, and update consumers, tests, and docs to meet #534's acceptance criteria.
Docstring Coverage ⚠️ Warning Docstring coverage is 43.18% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly points to the HTTP client curl adapter refactor and matches the main theme of the PR.
Out of Scope Changes check ✅ Passed The added factory and test coverage support the HTTP client refactor and do not appear unrelated to the issue scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov-commenter

codecov-commenter commented Jul 14, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 98.46154% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/HttpClient/Factories/HttpClientFactory.php 90.00% 1 Missing ⚠️
src/HttpClient/HttpClient.php 97.22% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37fc64831f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/HttpClient/Factories/HttpClientFactory.php

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (1)
src/HttpClient/HttpClient.php (1)

326-336: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Remove redundant ensureRequestCreated() call.

ensureRequestCreated() is already invoked at the start of the __call method. Since interceptCall() operates on header arrays and does not unset or modify $this->client, calling ensureRequestCreated() a second time is unnecessary.

♻️ Proposed fix
         $this->interceptCall($method, $arguments);
 
-        $this->ensureRequestCreated();
-
         $this->client->callMethod($method, $arguments);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/HttpClient/HttpClient.php` around lines 326 - 336, Remove the second
redundant ensureRequestCreated() call in __call after interceptCall(),
preserving the initial request creation check and the existing supportsMethod,
interceptCall, and callMethod flow.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/HttpClient/Adapters/CurlAdapter.php`:
- Around line 143-146: Update the option dispatch in getInfo to use a strict
null check instead of truthiness, ensuring option value 0 is passed to
client->getInfo($option) while null continues calling client->getInfo() without
arguments.

In `@src/HttpClient/Adapters/MultiCurlAdapter.php`:
- Around line 39-51: Update MultiCurlAdapter::success and
MultiCurlAdapter::error to register closures that wrap each raw vendor Curl
instance in CurlAdapter before invoking the user callback, matching complete().
In tests/Unit/HttpClient/Adapters/MultiCurlAdapterTest.php lines 43-56, update
mock expectations for closure registration and assert callbacks receive
CurlAdapter instances.
- Around line 61-77: The addGet and addPost methods in
src/HttpClient/Adapters/MultiCurlAdapter.php#L61-L77 must prevent raw vendor
Curl instances from crossing the adapter boundary: capture each vendor result
and wrap it in CurlAdapter when it is a Curl object, otherwise preserve the
existing return behavior. Update
src/HttpClient/Adapters/MultiCurlAdapter.php#L61-L77 accordingly. In
src/HttpClient/Adapters/MultiCurlAdapterTest.php#L28-L39, return
Mockery::mock(Curl::class) from the mocks and assert both addGet and addPost
return CurlAdapter instances.

In `@src/HttpClient/HttpClient.php`:
- Around line 394-401: Update ensureSingleRequest() to call
ensureRequestCreated() before checking isMultiRequest(). Preserve the existing
MultiCurlAdapter rejection and exception behavior, while ensuring the method’s
CurlAdapterInterface assertion only applies after a client has been created.
- Around line 178-183: Update the `@phpstan-assert-if-false` annotation on
isMultiRequest() to declare that a false result leaves $this->client as
CurlAdapterInterface|null, while preserving the existing true assertion and
method behavior.
- Around line 274-293: Update getResponse() and getErrors() to return an empty
array when $this->client is null, before the fallback calls
$this->client->getId(). Preserve the existing multi-request and
initialized-client behavior.

---

Nitpick comments:
In `@src/HttpClient/HttpClient.php`:
- Around line 326-336: Remove the second redundant ensureRequestCreated() call
in __call after interceptCall(), preserving the initial request creation check
and the existing supportsMethod, interceptCall, and callMethod flow.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: dd453cd6-d26b-4200-bdaa-bf178403a7d6

📥 Commits

Reviewing files that changed from the base of the PR and between 98ae0a1 and 37fc648.

📒 Files selected for processing (12)
  • CHANGELOG.md
  • src/HttpClient/Adapters/CurlAdapter.php
  • src/HttpClient/Adapters/MultiCurlAdapter.php
  • src/HttpClient/Contracts/CurlAdapterInterface.php
  • src/HttpClient/Contracts/HttpClientAdapterInterface.php
  • src/HttpClient/Contracts/MultiCurlAdapterInterface.php
  • src/HttpClient/Enums/HttpClientType.php
  • src/HttpClient/Factories/HttpClientFactory.php
  • src/HttpClient/HttpClient.php
  • tests/Unit/HttpClient/Adapters/CurlAdapterTest.php
  • tests/Unit/HttpClient/Adapters/MultiCurlAdapterTest.php
  • tests/Unit/HttpClient/HttpClientTest.php

Comment thread src/HttpClient/Adapters/CurlAdapter.php
Comment thread src/HttpClient/Adapters/MultiCurlAdapter.php
Comment thread src/HttpClient/Adapters/MultiCurlAdapter.php
Comment thread src/HttpClient/HttpClient.php
Comment thread src/HttpClient/HttpClient.php
Comment thread src/HttpClient/HttpClient.php

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/Unit/HttpClient/Factories/HttpClientFactoryTest.php`:
- Around line 32-39: Update testHttpClientFactoryResolveReturnsSameInstance to
obtain one client through HttpClientFactory::get() and the other through
Di::get(HttpClientFactory::class)->resolve(), then assert they are the same
instance. Ensure the test covers identity across both factory entry points
rather than only repeated resolve() calls.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5e09ca8f-d418-481a-bde5-b52e091c1102

📥 Commits

Reviewing files that changed from the base of the PR and between 37fc648 and e99f21f.

📒 Files selected for processing (7)
  • src/HttpClient/Adapters/CurlAdapter.php
  • src/HttpClient/Adapters/MultiCurlAdapter.php
  • src/HttpClient/HttpClient.php
  • tests/Unit/HttpClient/Adapters/CurlAdapterTest.php
  • tests/Unit/HttpClient/Adapters/MultiCurlAdapterTest.php
  • tests/Unit/HttpClient/Factories/HttpClientFactoryTest.php
  • tests/Unit/HttpClient/HttpClientTest.php
🚧 Files skipped from review as they are similar to previous changes (4)
  • src/HttpClient/Adapters/CurlAdapter.php
  • tests/Unit/HttpClient/Adapters/CurlAdapterTest.php
  • tests/Unit/HttpClient/Adapters/MultiCurlAdapterTest.php
  • src/HttpClient/Adapters/MultiCurlAdapter.php

Comment thread tests/Unit/HttpClient/Factories/HttpClientFactoryTest.php
@armanist armanist added help wanted Extra attention is needed http HTTP transport, redirects, and request/response behavior labels Jul 14, 2026
@armanist armanist added this to the 3.1.0 milestone Jul 14, 2026
@armanist armanist merged commit af03b2e into quantum-php:master Jul 15, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

help wanted Extra attention is needed http HTTP transport, redirects, and request/response behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor HttpClient into native curl adapters for single and multi requests and deprecate php-curl-class

3 participants